parent
36b92210e1
commit
c19339e799
@ -251,12 +251,13 @@ impl<'a> Executive<'a> {
|
|||||||
// part of substate that may be reverted
|
// part of substate that may be reverted
|
||||||
let mut unconfirmed_substate = Substate::new();
|
let mut unconfirmed_substate = Substate::new();
|
||||||
|
|
||||||
// at first create new contract
|
// create contract and transfer value to it if necessary
|
||||||
self.state.new_contract(¶ms.address);
|
let prev_bal = self.state.balance(¶ms.address);
|
||||||
|
|
||||||
// then transfer value to it
|
|
||||||
if let ActionValue::Transfer(val) = params.value {
|
if let ActionValue::Transfer(val) = params.value {
|
||||||
self.state.transfer_balance(¶ms.sender, ¶ms.address, &val);
|
self.state.sub_balance(¶ms.sender, &val);
|
||||||
|
self.state.new_contract(¶ms.address, val + prev_bal);
|
||||||
|
} else {
|
||||||
|
self.state.new_contract(¶ms.address, prev_bal);
|
||||||
}
|
}
|
||||||
|
|
||||||
let res = {
|
let res = {
|
||||||
|
@ -72,8 +72,8 @@ impl State {
|
|||||||
|
|
||||||
/// Create a new contract at address `contract`. If there is already an account at the address
|
/// Create a new contract at address `contract`. If there is already an account at the address
|
||||||
/// it will have its code reset, ready for `init_code()`.
|
/// it will have its code reset, ready for `init_code()`.
|
||||||
pub fn new_contract(&mut self, contract: &Address) {
|
pub fn new_contract(&mut self, contract: &Address, balance: U256) {
|
||||||
self.require_or_from(contract, false, || Account::new_contract(U256::from(0u8)), |r| r.reset_code());
|
self.cache.borrow_mut().insert(contract.clone(), Some(Account::new_contract(balance)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove an existing account.
|
/// Remove an existing account.
|
||||||
|
@ -182,8 +182,7 @@ fn do_json_test_for(vm: &VMType, json_data: &[u8]) -> Vec<String> {
|
|||||||
let code = xjson!(&s["code"]);
|
let code = xjson!(&s["code"]);
|
||||||
let _nonce: U256 = xjson!(&s["nonce"]);
|
let _nonce: U256 = xjson!(&s["nonce"]);
|
||||||
|
|
||||||
state.new_contract(&address);
|
state.new_contract(&address, balance);
|
||||||
state.add_balance(&address, &balance);
|
|
||||||
state.init_code(&address, code);
|
state.init_code(&address, code);
|
||||||
BTreeMap::from_json(&s["storage"]).into_iter().foreach(|(k, v)| state.set_storage(&address, k, v));
|
BTreeMap::from_json(&s["storage"]).into_iter().foreach(|(k, v)| state.set_storage(&address, k, v));
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user