From 77babe6226a8c8b04662b9c5ba10a9e86886079f Mon Sep 17 00:00:00 2001 From: debris Date: Thu, 21 Jul 2016 16:26:49 +0200 Subject: [PATCH] added suicide details --- ethcore/src/executive.rs | 2 +- ethcore/src/externalities.rs | 8 +++++++- ethcore/src/substate.rs | 36 +++++++++++++++++++++--------------- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/ethcore/src/executive.rs b/ethcore/src/executive.rs index f5ff95d71..cc5c1ffde 100644 --- a/ethcore/src/executive.rs +++ b/ethcore/src/executive.rs @@ -433,7 +433,7 @@ impl<'a> Executive<'a> { self.state.add_balance(&self.info.author, &fees_value); // perform suicides - for address in &substate.suicides { + for (address, _) in &substate.suicides { self.state.kill_account(address); } diff --git a/ethcore/src/externalities.rs b/ethcore/src/externalities.rs index 8a44363fa..ae1ae9d3a 100644 --- a/ethcore/src/externalities.rs +++ b/ethcore/src/externalities.rs @@ -262,7 +262,13 @@ impl<'a, T, V> Ext for Externalities<'a, T, V> where T: 'a + Tracer, V: 'a + VMT trace!("Suiciding {} -> {} (xfer: {})", address, refund_address, balance); self.state.transfer_balance(&address, refund_address, &balance); } - self.substate.suicides.insert(address); + + let details = SuicideDetails { + refund_address: refund_address.clone(), + value: balance, + }; + + self.substate.suicides.insert(address, details); } fn schedule(&self) -> &Schedule { diff --git a/ethcore/src/substate.rs b/ethcore/src/substate.rs index 247bbb398..6cca224a6 100644 --- a/ethcore/src/substate.rs +++ b/ethcore/src/substate.rs @@ -15,14 +15,25 @@ // along with Parity. If not, see . //! Execution environment substate. -use common::*; +use std::collections::HashMap; +use util::{Address, U256}; +use log_entry::LogEntry; + +/// Details of the commited suicide. +#[derive(Debug, Default)] +pub struct SuicideDetails { + /// Suicided contract heir. + pub refund_address: Address, + /// Balance of the contract just before suicide. + pub value: U256, +} /// State changes which should be applied in finalize, /// after transaction is fully executed. #[derive(Debug, Default)] pub struct Substate { /// Any accounts that have suicided. - pub suicides: HashSet
, + pub suicides: HashMap, /// Any logs. pub logs: Vec, @@ -37,12 +48,7 @@ pub struct Substate { impl Substate { /// Creates new substate. pub fn new() -> Self { - Substate { - suicides: Default::default(), - logs: Default::default(), - sstore_clears_count: Default::default(), - contracts_created: Default::default(), - } + Substate::default() } /// Merge secondary substate `s` into self, accruing each element correspondingly. @@ -56,8 +62,8 @@ impl Substate { #[cfg(test)] mod tests { - use super::*; - use common::*; + use super::Substate; + use log_entry::LogEntry; #[test] fn created() { @@ -68,19 +74,19 @@ mod tests { #[test] fn accrue() { let mut sub_state = Substate::new(); - sub_state.contracts_created.push(address_from_u64(1u64)); + sub_state.contracts_created.push(1u64.into()); sub_state.logs.push(LogEntry { - address: address_from_u64(1u64), + address: 1u64.into(), topics: vec![], data: vec![] }); sub_state.sstore_clears_count = 5.into(); - sub_state.suicides.insert(address_from_u64(10u64)); + sub_state.suicides.insert(10u64.into(), Default::default()); let mut sub_state_2 = Substate::new(); - sub_state_2.contracts_created.push(address_from_u64(2u64)); + sub_state_2.contracts_created.push(2u64.into()); sub_state_2.logs.push(LogEntry { - address: address_from_u64(1u64), + address: 1u64.into(), topics: vec![], data: vec![] });