added suicide details

This commit is contained in:
debris 2016-07-21 16:26:49 +02:00
parent 8ab56ea3d1
commit 77babe6226
3 changed files with 29 additions and 17 deletions

View File

@ -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);
}

View File

@ -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 {

View File

@ -15,14 +15,25 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
//! 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<Address>,
pub suicides: HashMap<Address, SuicideDetails>,
/// Any logs.
pub logs: Vec<LogEntry>,
@ -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![]
});