Skip to content

Commit 30475dc

Browse files
committed
Reformat using rustfmt
1 parent 76832b8 commit 30475dc

File tree

1 file changed

+42
-48
lines changed

1 file changed

+42
-48
lines changed

src/main.rs

Lines changed: 42 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ extern crate ethereum_bn128;
22
extern crate parity_bytes as bytes;
33
extern crate rustc_hex;
44

5-
use std::os::raw::c_char;
65
use std::ffi::CStr;
6+
use std::os::raw::c_char;
77

88
use rustc_hex::FromHex;
99
use rustc_hex::ToHex;
@@ -12,67 +12,61 @@ use bytes::BytesRef;
1212

1313
#[no_mangle]
1414
pub fn ec_mul(input_hex_ptr: *const c_char) -> *const c_char {
15-
let input_hex = unsafe { CStr::from_ptr(input_hex_ptr) };
16-
let input_str: &str = input_hex.to_str().unwrap();
17-
let input_parsed = FromHex::from_hex(input_str).unwrap();
15+
let input_hex = unsafe { CStr::from_ptr(input_hex_ptr) };
16+
let input_str: &str = input_hex.to_str().unwrap();
17+
let input_parsed = FromHex::from_hex(input_str).unwrap();
1818

19-
let mut output = vec![0u8; 64];
20-
match ethereum_bn128::bn128_mul(&input_parsed[..], &mut BytesRef::Fixed(&mut output[..])) {
21-
Ok(_) => {
22-
let mut output_hex = output.to_hex();
23-
output_hex.push_str("\0");
24-
return output_hex.as_ptr() as *const c_char
25-
}
26-
Err(_) => {
27-
return "\0".as_ptr() as *const c_char
28-
}
29-
}
19+
let mut output = vec![0u8; 64];
20+
match ethereum_bn128::bn128_mul(&input_parsed[..], &mut BytesRef::Fixed(&mut output[..])) {
21+
Ok(_) => {
22+
let mut output_hex = output.to_hex();
23+
output_hex.push_str("\0");
24+
return output_hex.as_ptr() as *const c_char;
25+
}
26+
Err(_) => return "\0".as_ptr() as *const c_char,
27+
}
3028
}
3129

3230
#[no_mangle]
3331
pub fn ec_add(input_hex_ptr: *const c_char) -> *const c_char {
34-
let input_hex = unsafe { CStr::from_ptr(input_hex_ptr) };
35-
let input_str: &str = input_hex.to_str().unwrap();
36-
let input_parsed = FromHex::from_hex(input_str).unwrap();
32+
let input_hex = unsafe { CStr::from_ptr(input_hex_ptr) };
33+
let input_str: &str = input_hex.to_str().unwrap();
34+
let input_parsed = FromHex::from_hex(input_str).unwrap();
3735

38-
let mut output = vec![0u8; 64];
39-
match ethereum_bn128::bn128_add(&input_parsed[..], &mut BytesRef::Fixed(&mut output[..])) {
40-
Ok(_) => {
41-
let mut output_hex = output.to_hex();
42-
output_hex.push_str("\0");
43-
return output_hex.as_ptr() as *const c_char
44-
}
45-
Err(_) => {
46-
return "\0".as_ptr() as *const c_char
47-
}
48-
}
36+
let mut output = vec![0u8; 64];
37+
match ethereum_bn128::bn128_add(&input_parsed[..], &mut BytesRef::Fixed(&mut output[..])) {
38+
Ok(_) => {
39+
let mut output_hex = output.to_hex();
40+
output_hex.push_str("\0");
41+
return output_hex.as_ptr() as *const c_char;
42+
}
43+
Err(_) => return "\0".as_ptr() as *const c_char,
44+
}
4945
}
5046

5147
#[no_mangle]
5248
pub fn ec_pairing(input_hex_ptr: *const c_char) -> *const c_char {
53-
let input_hex = unsafe { CStr::from_ptr(input_hex_ptr) };
54-
let input_str: &str = input_hex.to_str().unwrap();
55-
let input_parsed = FromHex::from_hex(input_str).unwrap();
49+
let input_hex = unsafe { CStr::from_ptr(input_hex_ptr) };
50+
let input_str: &str = input_hex.to_str().unwrap();
51+
let input_parsed = FromHex::from_hex(input_str).unwrap();
5652

57-
let mut output = vec![0u8; 32];
58-
match ethereum_bn128::bn128_pairing(&input_parsed[..], &mut BytesRef::Fixed(&mut output[..])) {
59-
Ok(_) => {
60-
let mut output_hex = output.to_hex();
61-
output_hex.push_str("\0");
62-
return output_hex.as_ptr() as *const c_char
63-
}
64-
Err(_) => {
65-
return "\0".as_ptr() as *const c_char
66-
}
67-
}
53+
let mut output = vec![0u8; 32];
54+
match ethereum_bn128::bn128_pairing(&input_parsed[..], &mut BytesRef::Fixed(&mut output[..])) {
55+
Ok(_) => {
56+
let mut output_hex = output.to_hex();
57+
output_hex.push_str("\0");
58+
return output_hex.as_ptr() as *const c_char;
59+
}
60+
Err(_) => return "\0".as_ptr() as *const c_char,
61+
}
6862
}
6963

70-
extern {
71-
fn emscripten_exit_with_live_runtime();
64+
extern "C" {
65+
fn emscripten_exit_with_live_runtime();
7266
}
7367

7468
fn main() {
75-
unsafe {
76-
emscripten_exit_with_live_runtime();
77-
}
69+
unsafe {
70+
emscripten_exit_with_live_runtime();
71+
}
7872
}

0 commit comments

Comments
 (0)