From 79c1cc02f74a554106d2a6ec37ea959e81105a42 Mon Sep 17 00:00:00 2001 From: Tomusdrw Date: Sat, 16 Jan 2016 17:17:43 +0100 Subject: [PATCH] Vec -> Bytes and clearing log API --- src/evm/ext.rs | 5 +++-- src/evm/interpreter.rs | 2 +- src/evm/jit.rs | 4 ++-- src/evm/tests.rs | 6 +++--- src/externalities.rs | 6 +++--- src/state.rs | 2 +- src/tests/executive.rs | 4 ++-- 7 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/evm/ext.rs b/src/evm/ext.rs index 921e0e16c..bc6e7d8f2 100644 --- a/src/evm/ext.rs +++ b/src/evm/ext.rs @@ -1,5 +1,6 @@ //! Interface for Evm externalities. +use common::Bytes; use util::hash::*; use util::uint::*; use evm::{Schedule, Error}; @@ -38,10 +39,10 @@ pub trait Ext { output: &mut [u8]) -> Result<(U256, bool), Error>; /// Returns code at given address - fn extcode(&self, address: &Address) -> Vec; + fn extcode(&self, address: &Address) -> Bytes; /// Creates log entry with given topics and data - fn log(&mut self, topics: Vec, data: Vec); + fn log(&mut self, topics: Vec, data: &[u8]); /// Should be called when transaction calls `RETURN` opcode. /// Returns gas_left if cost of returning the data is not too high. diff --git a/src/evm/interpreter.rs b/src/evm/interpreter.rs index e9e8b967c..c583b054d 100644 --- a/src/evm/interpreter.rs +++ b/src/evm/interpreter.rs @@ -614,7 +614,7 @@ impl Interpreter { .iter() .map(H256::from) .collect(); - ext.log(topics, mem.read_slice(offset, size).to_vec()); + ext.log(topics, mem.read_slice(offset, size)); }, instructions::PUSH1...instructions::PUSH32 => { let bytes = instructions::get_push_bytes(instruction); diff --git a/src/evm/jit.rs b/src/evm/jit.rs index 122947d32..126e6f5c9 100644 --- a/src/evm/jit.rs +++ b/src/evm/jit.rs @@ -7,7 +7,7 @@ use evm; struct RuntimeData { gas: U256, gas_price: U256, - call_data: Vec, + call_data: Bytes, address: Address, caller: Address, origin: Address, @@ -17,7 +17,7 @@ struct RuntimeData { gas_limit: U256, number: u64, timestamp: u64, - code: Vec + code: Bytes } impl RuntimeData { diff --git a/src/evm/tests.rs b/src/evm/tests.rs index 7e467e2ac..cf02d5efa 100644 --- a/src/evm/tests.rs +++ b/src/evm/tests.rs @@ -66,14 +66,14 @@ impl Ext for FakeExt { unimplemented!(); } - fn extcode(&self, address: &Address) -> Vec { + fn extcode(&self, address: &Address) -> Bytes { self.codes.get(address).unwrap_or(&Bytes::new()).clone() } - fn log(&mut self, topics: Vec, data: Vec) { + fn log(&mut self, topics: Vec, data: &[u8]) { self.logs.push(FakeLogEntry { topics: topics, - data: data + data: data.to_vec() }); } diff --git a/src/externalities.rs b/src/externalities.rs index 8c75a71f4..c6ab2ceed 100644 --- a/src/externalities.rs +++ b/src/externalities.rs @@ -187,7 +187,7 @@ impl<'a> Ext for Externalities<'a> { } } - fn extcode(&self, address: &Address) -> Vec { + fn extcode(&self, address: &Address) -> Bytes { self.state.code(address).unwrap_or(vec![]) } @@ -227,9 +227,9 @@ impl<'a> Ext for Externalities<'a> { } } - fn log(&mut self, topics: Vec, data: Bytes) { + fn log(&mut self, topics: Vec, data: &[u8]) { let address = self.params.address.clone(); - self.substate.logs.push(LogEntry::new(address, topics, data)); + self.substate.logs.push(LogEntry::new(address, topics, data.to_vec())); } fn suicide(&mut self, refund_address: &Address) { diff --git a/src/state.rs b/src/state.rs index 88280c2da..fc4d6f817 100644 --- a/src/state.rs +++ b/src/state.rs @@ -101,7 +101,7 @@ impl State { } /// Mutate storage of account `a` so that it is `value` for `key`. - pub fn code(&self, a: &Address) -> Option> { + pub fn code(&self, a: &Address) -> Option { self.get(a, true).as_ref().map(|a|a.code().map(|x|x.to_vec())).unwrap_or(None) } diff --git a/src/tests/executive.rs b/src/tests/executive.rs index e51ed2802..b251eb0d2 100644 --- a/src/tests/executive.rs +++ b/src/tests/executive.rs @@ -132,11 +132,11 @@ impl<'a> Ext for TestExt<'a> { res } - fn extcode(&self, address: &Address) -> Vec { + fn extcode(&self, address: &Address) -> Bytes { self.ext.extcode(address) } - fn log(&mut self, topics: Vec, data: Vec) { + fn log(&mut self, topics: Vec, data: &[u8]) { self.ext.log(topics, data) }