Changing is_value_transfer to enum
This commit is contained in:
parent
8084e1b6d7
commit
cd9a0e4e58
@ -3,8 +3,16 @@ use util::hash::*;
|
|||||||
use util::uint::*;
|
use util::uint::*;
|
||||||
use util::bytes::*;
|
use util::bytes::*;
|
||||||
|
|
||||||
// TODO: should be a trait, possible to avoid cloning everything from a Transaction(/View).
|
/// Transaction value
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub enum ActionValue {
|
||||||
|
/// Value that should be transfered
|
||||||
|
Transfer(U256),
|
||||||
|
/// Apparent value for transaction (not transfered)
|
||||||
|
Apparent(U256)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: should be a trait, possible to avoid cloning everything from a Transaction(/View).
|
||||||
/// Action (call/create) input params. Everything else should be specified in Externalities.
|
/// Action (call/create) input params. Everything else should be specified in Externalities.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct ActionParams {
|
pub struct ActionParams {
|
||||||
@ -22,9 +30,7 @@ pub struct ActionParams {
|
|||||||
/// Gas price.
|
/// Gas price.
|
||||||
pub gas_price: U256,
|
pub gas_price: U256,
|
||||||
/// Transaction value.
|
/// Transaction value.
|
||||||
pub value: U256,
|
pub value: ActionValue,
|
||||||
/// Should transfer value from sender to origin
|
|
||||||
pub is_value_transfer: bool,
|
|
||||||
/// Code being executed.
|
/// Code being executed.
|
||||||
pub code: Option<Bytes>,
|
pub code: Option<Bytes>,
|
||||||
/// Input data.
|
/// Input data.
|
||||||
@ -41,10 +47,9 @@ impl Default for ActionParams {
|
|||||||
origin: Address::new(),
|
origin: Address::new(),
|
||||||
gas: U256::zero(),
|
gas: U256::zero(),
|
||||||
gas_price: U256::zero(),
|
gas_price: U256::zero(),
|
||||||
value: U256::zero(),
|
value: ActionValue::Transfer(U256::zero()),
|
||||||
code: None,
|
code: None,
|
||||||
data: None,
|
data: None
|
||||||
is_value_transfer: true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -741,7 +741,10 @@ impl Interpreter {
|
|||||||
stack.push(address_to_u256(params.sender.clone()));
|
stack.push(address_to_u256(params.sender.clone()));
|
||||||
},
|
},
|
||||||
instructions::CALLVALUE => {
|
instructions::CALLVALUE => {
|
||||||
stack.push(params.value.clone());
|
stack.push(match params.value {
|
||||||
|
ActionValue::Transfer(val) => val,
|
||||||
|
ActionValue::Apparent(val) => val,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
instructions::CALLDATALOAD => {
|
instructions::CALLDATALOAD => {
|
||||||
let big_id = stack.pop_back();
|
let big_id = stack.pop_back();
|
||||||
|
@ -133,8 +133,7 @@ impl<'a> Executive<'a> {
|
|||||||
origin: sender.clone(),
|
origin: sender.clone(),
|
||||||
gas: init_gas,
|
gas: init_gas,
|
||||||
gas_price: t.gas_price,
|
gas_price: t.gas_price,
|
||||||
value: t.value,
|
value: ActionValue::Transfer(t.value),
|
||||||
is_value_transfer: true,
|
|
||||||
code: Some(t.data.clone()),
|
code: Some(t.data.clone()),
|
||||||
data: None,
|
data: None,
|
||||||
};
|
};
|
||||||
@ -148,8 +147,7 @@ impl<'a> Executive<'a> {
|
|||||||
origin: sender.clone(),
|
origin: sender.clone(),
|
||||||
gas: init_gas,
|
gas: init_gas,
|
||||||
gas_price: t.gas_price,
|
gas_price: t.gas_price,
|
||||||
value: t.value,
|
value: ActionValue::Transfer(t.value),
|
||||||
is_value_transfer: true,
|
|
||||||
code: self.state.code(address),
|
code: self.state.code(address),
|
||||||
data: Some(t.data.clone()),
|
data: Some(t.data.clone()),
|
||||||
};
|
};
|
||||||
@ -173,8 +171,8 @@ impl<'a> Executive<'a> {
|
|||||||
let backup = self.state.clone();
|
let backup = self.state.clone();
|
||||||
|
|
||||||
// at first, transfer value to destination
|
// at first, transfer value to destination
|
||||||
if params.is_value_transfer {
|
if let ActionValue::Transfer(val) = params.value {
|
||||||
self.state.transfer_balance(¶ms.sender, ¶ms.address, ¶ms.value);
|
self.state.transfer_balance(¶ms.sender, ¶ms.address, &val);
|
||||||
}
|
}
|
||||||
trace!("Executive::call(params={:?}) self.env_info={:?}", params, self.info);
|
trace!("Executive::call(params={:?}) self.env_info={:?}", params, self.info);
|
||||||
|
|
||||||
@ -232,8 +230,8 @@ impl<'a> Executive<'a> {
|
|||||||
self.state.new_contract(¶ms.address);
|
self.state.new_contract(¶ms.address);
|
||||||
|
|
||||||
// then transfer value to it
|
// then transfer value to it
|
||||||
if params.is_value_transfer {
|
if let ActionValue::Transfer(val) = params.value {
|
||||||
self.state.transfer_balance(¶ms.sender, ¶ms.address, ¶ms.value);
|
self.state.transfer_balance(¶ms.sender, ¶ms.address, &val);
|
||||||
}
|
}
|
||||||
|
|
||||||
let res = {
|
let res = {
|
||||||
|
@ -29,10 +29,13 @@ impl OriginInfo {
|
|||||||
pub fn from(params: &ActionParams) -> Self {
|
pub fn from(params: &ActionParams) -> Self {
|
||||||
OriginInfo {
|
OriginInfo {
|
||||||
sender: params.sender.clone(),
|
sender: params.sender.clone(),
|
||||||
value: params.value.clone(),
|
|
||||||
address: params.address.clone(),
|
address: params.address.clone(),
|
||||||
origin: params.origin.clone(),
|
origin: params.origin.clone(),
|
||||||
gas_price: params.gas_price.clone()
|
gas_price: params.gas_price.clone(),
|
||||||
|
value: match params.value {
|
||||||
|
ActionValue::Transfer(val) => val,
|
||||||
|
ActionValue::Apparent(val) => val,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -115,8 +118,7 @@ impl<'a> Ext for Externalities<'a> {
|
|||||||
origin: self.origin_info.origin.clone(),
|
origin: self.origin_info.origin.clone(),
|
||||||
gas: *gas,
|
gas: *gas,
|
||||||
gas_price: self.origin_info.gas_price.clone(),
|
gas_price: self.origin_info.gas_price.clone(),
|
||||||
value: value.clone(),
|
value: ActionValue::Transfer(value.clone()),
|
||||||
is_value_transfer: true,
|
|
||||||
code: Some(code.to_vec()),
|
code: Some(code.to_vec()),
|
||||||
data: None,
|
data: None,
|
||||||
};
|
};
|
||||||
@ -147,8 +149,7 @@ impl<'a> Ext for Externalities<'a> {
|
|||||||
origin: self.origin_info.origin.clone(),
|
origin: self.origin_info.origin.clone(),
|
||||||
gas: *gas,
|
gas: *gas,
|
||||||
gas_price: self.origin_info.gas_price.clone(),
|
gas_price: self.origin_info.gas_price.clone(),
|
||||||
value: self.origin_info.value.clone(),
|
value: ActionValue::Apparent(self.origin_info.value.clone()),
|
||||||
is_value_transfer: false,
|
|
||||||
code: self.state.code(code_address),
|
code: self.state.code(code_address),
|
||||||
data: Some(data.to_vec()),
|
data: Some(data.to_vec()),
|
||||||
};
|
};
|
||||||
@ -176,8 +177,7 @@ impl<'a> Ext for Externalities<'a> {
|
|||||||
origin: self.origin_info.origin.clone(),
|
origin: self.origin_info.origin.clone(),
|
||||||
gas: *gas,
|
gas: *gas,
|
||||||
gas_price: self.origin_info.gas_price.clone(),
|
gas_price: self.origin_info.gas_price.clone(),
|
||||||
value: value.clone(),
|
value: ActionValue::Transfer(value.clone()),
|
||||||
is_value_transfer: true,
|
|
||||||
code: self.state.code(code_address),
|
code: self.state.code(code_address),
|
||||||
data: Some(data.to_vec()),
|
data: Some(data.to_vec()),
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user