Skip to content

Commit 0376ff4

Browse files
authored
Merge pull request #2 from axic/fmt
Reformat using rustfmt
2 parents edb2a00 + 95984b4 commit 0376ff4

File tree

2 files changed

+72
-34
lines changed

2 files changed

+72
-34
lines changed

circle.yml

+7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@ jobs:
1717
name: Update rustc
1818
command: |
1919
rustup target add wasm32-unknown-unknown
20+
rustup component add rustfmt-preview
2021
rustup update
22+
- run:
23+
name: Check formatting
24+
command: |
25+
rustfmt --version
26+
cargo fmt
27+
git diff --exit-code
2128
- run:
2229
name: Install dependencies
2330
command: |

src/lib.rs

+65-34
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1-
extern crate ewasm_api;
2-
extern crate vm;
3-
extern crate evm;
41
extern crate ethereum_types;
2+
extern crate evm;
3+
extern crate ewasm_api;
54
extern crate parity_bytes as bytes;
5+
extern crate vm;
66

7-
use std::sync::Arc;
8-
use std::ops::Deref;
97
use std::cmp;
8+
use std::ops::Deref;
9+
use std::sync::Arc;
1010

11-
use self::ethereum_types::{U128, U256, H256, H160, Address};
11+
use self::ethereum_types::{Address, H160, H256, U128, U256};
1212

1313
use self::bytes::Bytes;
1414

1515
use self::evm::Factory;
1616

1717
use self::vm::{
18-
EnvInfo, CreateContractAddress, ReturnData, CleanDustMode, ActionParams,
19-
ActionValue, Schedule, ContractCreateResult, MessageCallResult, CallType,
20-
Result, GasLeft
18+
ActionParams, ActionValue, CallType, CleanDustMode, ContractCreateResult,
19+
CreateContractAddress, EnvInfo, GasLeft, MessageCallResult, Result, ReturnData, Schedule,
2120
};
2221

2322
// For some explanation see ethcore/vm/src/tests.rs::FakeExt
@@ -26,7 +25,7 @@ use self::vm::{
2625
struct EwasmExt {
2726
pub info: EnvInfo,
2827
pub schedule: Schedule,
29-
pub selfdestruct_address: Option<Address>
28+
pub selfdestruct_address: Option<Address>,
3029
}
3130

3231
impl vm::Ext for EwasmExt {
@@ -70,8 +69,10 @@ impl vm::Ext for EwasmExt {
7069
/// Returns address balance.
7170
fn balance(&self, address: &Address) -> Result<U256> {
7271
// FIXME: this type should just implement the From trait for the underlying type
73-
let address: [u8;20] = address.0;
74-
Ok(U256::from(U128::from(ewasm_api::external_balance(&address))))
72+
let address: [u8; 20] = address.0;
73+
Ok(U256::from(U128::from(ewasm_api::external_balance(
74+
&address,
75+
))))
7576
}
7677

7778
/// Returns the hash of one of the 256 most recent complete blocks.
@@ -83,7 +84,13 @@ impl vm::Ext for EwasmExt {
8384
/// Creates new contract.
8485
///
8586
/// Returns gas_left and contract address if contract creation was succesfull.
86-
fn create(&mut self, gas: &U256, value: &U256, code: &[u8], address: CreateContractAddress) -> ContractCreateResult {
87+
fn create(
88+
&mut self,
89+
gas: &U256,
90+
value: &U256,
91+
code: &[u8],
92+
address: CreateContractAddress,
93+
) -> ContractCreateResult {
8794
// FIXME: implement
8895
unimplemented!()
8996
// ContractCreateResult::Failed
@@ -94,15 +101,16 @@ impl vm::Ext for EwasmExt {
94101
/// Returns Err, if we run out of gas.
95102
/// Otherwise returns call_result which contains gas left
96103
/// and true if subcall was successfull.
97-
fn call(&mut self,
98-
gas: &U256,
99-
sender_address: &Address,
100-
receive_address: &Address,
101-
value: Option<U256>,
102-
data: &[u8],
103-
code_address: &Address,
104-
output: &mut [u8],
105-
call_type: CallType
104+
fn call(
105+
&mut self,
106+
gas: &U256,
107+
sender_address: &Address,
108+
receive_address: &Address,
109+
value: Option<U256>,
110+
data: &[u8],
111+
code_address: &Address,
112+
output: &mut [u8],
113+
call_type: CallType,
106114
) -> MessageCallResult {
107115
// FIXME: set this properly
108116
//let gas_limit = u64::from(gas);
@@ -112,14 +120,24 @@ impl vm::Ext for EwasmExt {
112120
let gas_start = ewasm_api::gas_left();
113121

114122
// FIXME: this type should just implement the From trait for the underlying type
115-
let receive_address: [u8;20] = receive_address.0;
123+
let receive_address: [u8; 20] = receive_address.0;
116124

117125
let call_result = match call_type {
118-
CallType::Call => ewasm_api::call_mutable(gas_limit, &receive_address, &U128::from(value.unwrap_or_default()).into(), &data),
119-
CallType::CallCode => ewasm_api::call_code(gas_limit, &receive_address, &U128::from(value.unwrap_or_default()).into(), &data),
126+
CallType::Call => ewasm_api::call_mutable(
127+
gas_limit,
128+
&receive_address,
129+
&U128::from(value.unwrap_or_default()).into(),
130+
&data,
131+
),
132+
CallType::CallCode => ewasm_api::call_code(
133+
gas_limit,
134+
&receive_address,
135+
&U128::from(value.unwrap_or_default()).into(),
136+
&data,
137+
),
120138
CallType::DelegateCall => ewasm_api::call_delegate(gas_limit, &receive_address, &data),
121139
CallType::StaticCall => ewasm_api::call_static(gas_limit, &receive_address, &data),
122-
_ => panic!()
140+
_ => panic!(),
123141
};
124142

125143
// FIXME: might not be good enough
@@ -137,7 +155,7 @@ impl vm::Ext for EwasmExt {
137155

138156
let ret_len = ret.len();
139157
MessageCallResult::Success(gas_used, ReturnData::new(ret, 0, ret_len))
140-
},
158+
}
141159
ewasm_api::CallResult::Failure => MessageCallResult::Failed,
142160
ewasm_api::CallResult::Revert => {
143161
// Retrieve the entire returndata as it needs to be returned
@@ -223,13 +241,22 @@ impl vm::Ext for EwasmExt {
223241
}
224242

225243
/// Decide if any more operations should be traced. Passthrough for the VM trace.
226-
fn trace_next_instruction(&mut self, _pc: usize, _instruction: u8, _current_gas: U256) -> bool { false }
244+
fn trace_next_instruction(&mut self, _pc: usize, _instruction: u8, _current_gas: U256) -> bool {
245+
false
246+
}
227247

228248
/// Prepare to trace an operation. Passthrough for the VM trace.
229249
fn trace_prepare_execute(&mut self, _pc: usize, _instruction: u8, _gas_cost: U256) {}
230250

231251
/// Trace the finalised execution of a single instruction.
232-
fn trace_executed(&mut self, _gas_used: U256, _stack_push: &[U256], _mem_diff: Option<(usize, &[u8])>, _store_diff: Option<(U256, U256)>) {}
252+
fn trace_executed(
253+
&mut self,
254+
_gas_used: U256,
255+
_stack_push: &[U256],
256+
_mem_diff: Option<(usize, &[u8])>,
257+
_store_diff: Option<(U256, U256)>,
258+
) {
259+
}
233260

234261
/// Check if running in static context.
235262
fn is_static(&self) -> bool {
@@ -239,7 +266,7 @@ impl vm::Ext for EwasmExt {
239266
}
240267

241268
#[no_mangle]
242-
pub extern fn main() {
269+
pub extern "C" fn main() {
243270
// It is fine using U256::zero() here because the main point of the
244271
// factory is to determine if gas is 64bit or not. In ewasm it is always 64bit.
245272
let mut instance = Factory::default().create(&U256::zero());
@@ -263,14 +290,18 @@ pub extern fn main() {
263290
match result {
264291
Ok(GasLeft::Known(gas_left)) => {
265292
if ext.selfdestruct_address.is_some() {
266-
let beneficiary: [u8;20] = ext.selfdestruct_address.unwrap().into();
293+
let beneficiary: [u8; 20] = ext.selfdestruct_address.unwrap().into();
267294
ewasm_api::selfdestruct(&beneficiary)
268295
} else {
269296
ewasm_api::finish()
270297
}
271-
},
272-
Ok(GasLeft::NeedsReturn {gas_left, data, apply_state}) => ewasm_api::finish_data(&data.deref()),
298+
}
299+
Ok(GasLeft::NeedsReturn {
300+
gas_left,
301+
data,
302+
apply_state,
303+
}) => ewasm_api::finish_data(&data.deref()),
273304
// FIXME: add support for pushing the error message as revert data
274-
Err(err) => ewasm_api::revert()
305+
Err(err) => ewasm_api::revert(),
275306
}
276307
}

0 commit comments

Comments
 (0)