Various improvements to tracing & diagnostics. (#1707)

* Various improvements to tracing & diagnostics.

- Manage possibility of `Account` not having code for `PodAccount`
- New RPC: `trace_sendRawTransaction`
- See raw transaction dump when inspecting over RPC

* Fix test

* Remove one of the dupe error messages

* Remove unneeded `&`s

* Reformat and extremely minor optimisation

* Minor optimisation

* Remove unneeded let

* Fix tests.

* Additional fix.

* Minor rename.

[ci:skip]

* Bowing to the pressure.
This commit is contained in:
Gav Wood 2016-07-26 16:48:50 +02:00 committed by GitHub
parent 53a975d1dc
commit 7cf807d1b4
9 changed files with 111 additions and 44 deletions

View File

@ -61,8 +61,8 @@ impl Account {
nonce: pod.nonce, nonce: pod.nonce,
storage_root: SHA3_NULL_RLP, storage_root: SHA3_NULL_RLP,
storage_overlay: RefCell::new(pod.storage.into_iter().map(|(k, v)| (k, (Filth::Dirty, v))).collect()), storage_overlay: RefCell::new(pod.storage.into_iter().map(|(k, v)| (k, (Filth::Dirty, v))).collect()),
code_hash: Some(pod.code.sha3()), code_hash: pod.code.as_ref().map(|c| c.sha3()),
code_cache: pod.code, code_cache: pod.code.as_ref().map_or_else(|| { warn!("POD account with unknown code is being created! Assuming no code."); vec![] }, |c| c.clone()),
filth: Filth::Dirty, filth: Filth::Dirty,
} }
} }

View File

@ -28,8 +28,8 @@ pub struct PodAccount {
pub balance: U256, pub balance: U256,
/// The nonce of the account. /// The nonce of the account.
pub nonce: U256, pub nonce: U256,
/// The code of the account. /// The code of the account or `None` in the special case that it is unknown.
pub code: Bytes, pub code: Option<Bytes>,
/// The storage of the account. /// The storage of the account.
pub storage: BTreeMap<H256, H256>, pub storage: BTreeMap<H256, H256>,
} }
@ -38,7 +38,7 @@ impl PodAccount {
/// Construct new object. /// Construct new object.
#[cfg(test)] #[cfg(test)]
pub fn new(balance: U256, nonce: U256, code: Bytes, storage: BTreeMap<H256, H256>) -> PodAccount { pub fn new(balance: U256, nonce: U256, code: Bytes, storage: BTreeMap<H256, H256>) -> PodAccount {
PodAccount { balance: balance, nonce: nonce, code: code, storage: storage } PodAccount { balance: balance, nonce: nonce, code: Some(code), storage: storage }
} }
/// Convert Account to a PodAccount. /// Convert Account to a PodAccount.
@ -48,7 +48,7 @@ impl PodAccount {
balance: *acc.balance(), balance: *acc.balance(),
nonce: *acc.nonce(), nonce: *acc.nonce(),
storage: acc.storage_overlay().iter().fold(BTreeMap::new(), |mut m, (k, &(_, ref v))| {m.insert(k.clone(), v.clone()); m}), storage: acc.storage_overlay().iter().fold(BTreeMap::new(), |mut m, (k, &(_, ref v))| {m.insert(k.clone(), v.clone()); m}),
code: acc.code().unwrap().to_vec(), code: acc.code().map(|x| x.to_vec()),
} }
} }
@ -58,14 +58,15 @@ impl PodAccount {
stream.append(&self.nonce); stream.append(&self.nonce);
stream.append(&self.balance); stream.append(&self.balance);
stream.append(&sec_trie_root(self.storage.iter().map(|(k, v)| (k.to_vec(), encode(&U256::from(v.as_slice())).to_vec())).collect())); stream.append(&sec_trie_root(self.storage.iter().map(|(k, v)| (k.to_vec(), encode(&U256::from(v.as_slice())).to_vec())).collect()));
stream.append(&self.code.sha3()); stream.append(&self.code.as_ref().unwrap_or(&vec![]).sha3());
stream.out() stream.out()
} }
/// Place additional data into given hash DB. /// Place additional data into given hash DB.
pub fn insert_additional(&self, db: &mut AccountDBMut) { pub fn insert_additional(&self, db: &mut AccountDBMut) {
if !self.code.is_empty() { match self.code {
db.insert(&self.code); Some(ref c) if !c.is_empty() => { db.insert(c); }
_ => {}
} }
let mut r = H256::new(); let mut r = H256::new();
let mut t = SecTrieDBMut::new(db, &mut r); let mut t = SecTrieDBMut::new(db, &mut r);
@ -80,7 +81,7 @@ impl From<ethjson::blockchain::Account> for PodAccount {
PodAccount { PodAccount {
balance: a.balance.into(), balance: a.balance.into(),
nonce: a.nonce.into(), nonce: a.nonce.into(),
code: a.code.into(), code: Some(a.code.into()),
storage: a.storage.into_iter().map(|(key, value)| { storage: a.storage.into_iter().map(|(key, value)| {
let key: U256 = key.into(); let key: U256 = key.into();
let value: U256 = value.into(); let value: U256 = value.into();
@ -95,7 +96,7 @@ impl From<ethjson::spec::Account> for PodAccount {
PodAccount { PodAccount {
balance: a.balance.map_or_else(U256::zero, Into::into), balance: a.balance.map_or_else(U256::zero, Into::into),
nonce: a.nonce.map_or_else(U256::zero, Into::into), nonce: a.nonce.map_or_else(U256::zero, Into::into),
code: vec![], code: Some(vec![]),
storage: BTreeMap::new() storage: BTreeMap::new()
} }
} }
@ -103,7 +104,13 @@ impl From<ethjson::spec::Account> for PodAccount {
impl fmt::Display for PodAccount { impl fmt::Display for PodAccount {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "(bal={}; nonce={}; code={} bytes, #{}; storage={} items)", self.balance, self.nonce, self.code.len(), self.code.sha3(), self.storage.len()) write!(f, "(bal={}; nonce={}; code={} bytes, #{}; storage={} items)",
self.balance,
self.nonce,
self.code.as_ref().map_or(0, |c| c.len()),
self.code.as_ref().map_or_else(H256::new, |c| c.sha3()),
self.storage.len()
)
} }
} }
@ -114,13 +121,13 @@ pub fn diff_pod(pre: Option<&PodAccount>, post: Option<&PodAccount>) -> Option<A
(None, Some(x)) => Some(AccountDiff { (None, Some(x)) => Some(AccountDiff {
balance: Diff::Born(x.balance), balance: Diff::Born(x.balance),
nonce: Diff::Born(x.nonce), nonce: Diff::Born(x.nonce),
code: Diff::Born(x.code.clone()), code: Diff::Born(x.code.as_ref().expect("account is newly created; newly created accounts must be given code; all caches should remain in place; qed").clone()),
storage: x.storage.iter().map(|(k, v)| (k.clone(), Diff::Born(v.clone()))).collect(), storage: x.storage.iter().map(|(k, v)| (k.clone(), Diff::Born(v.clone()))).collect(),
}), }),
(Some(x), None) => Some(AccountDiff { (Some(x), None) => Some(AccountDiff {
balance: Diff::Died(x.balance), balance: Diff::Died(x.balance),
nonce: Diff::Died(x.nonce), nonce: Diff::Died(x.nonce),
code: Diff::Died(x.code.clone()), code: Diff::Died(x.code.as_ref().expect("account is deleted; only way to delete account is running SUICIDE; account must have had own code cached to make operation; all caches should remain in place; qed").clone()),
storage: x.storage.iter().map(|(k, v)| (k.clone(), Diff::Died(v.clone()))).collect(), storage: x.storage.iter().map(|(k, v)| (k.clone(), Diff::Died(v.clone()))).collect(),
}), }),
(Some(pre), Some(post)) => { (Some(pre), Some(post)) => {
@ -130,7 +137,10 @@ pub fn diff_pod(pre: Option<&PodAccount>, post: Option<&PodAccount>) -> Option<A
let r = AccountDiff { let r = AccountDiff {
balance: Diff::new(pre.balance, post.balance), balance: Diff::new(pre.balance, post.balance),
nonce: Diff::new(pre.nonce, post.nonce), nonce: Diff::new(pre.nonce, post.nonce),
code: Diff::new(pre.code.clone(), post.code.clone()), code: match (pre.code.clone(), post.code.clone()) {
(Some(pre_code), Some(post_code)) => Diff::new(pre_code, post_code),
_ => Diff::Same,
},
storage: storage.into_iter().map(|k| storage: storage.into_iter().map(|k|
(k.clone(), Diff::new( (k.clone(), Diff::new(
pre.storage.get(&k).cloned().unwrap_or_else(H256::new), pre.storage.get(&k).cloned().unwrap_or_else(H256::new),
@ -156,7 +166,7 @@ mod test {
#[test] #[test]
fn existence() { fn existence() {
let a = PodAccount{balance: 69.into(), nonce: 0.into(), code: vec![], storage: map![]}; let a = PodAccount{balance: 69.into(), nonce: 0.into(), code: Some(vec![]), storage: map![]};
assert_eq!(diff_pod(Some(&a), Some(&a)), None); assert_eq!(diff_pod(Some(&a), Some(&a)), None);
assert_eq!(diff_pod(None, Some(&a)), Some(AccountDiff{ assert_eq!(diff_pod(None, Some(&a)), Some(AccountDiff{
balance: Diff::Born(69.into()), balance: Diff::Born(69.into()),
@ -168,8 +178,8 @@ mod test {
#[test] #[test]
fn basic() { fn basic() {
let a = PodAccount{balance: 69.into(), nonce: 0.into(), code: vec![], storage: map![]}; let a = PodAccount{balance: 69.into(), nonce: 0.into(), code: Some(vec![]), storage: map![]};
let b = PodAccount{balance: 42.into(), nonce: 1.into(), code: vec![], storage: map![]}; let b = PodAccount{balance: 42.into(), nonce: 1.into(), code: Some(vec![]), storage: map![]};
assert_eq!(diff_pod(Some(&a), Some(&b)), Some(AccountDiff { assert_eq!(diff_pod(Some(&a), Some(&b)), Some(AccountDiff {
balance: Diff::Changed(69.into(), 42.into()), balance: Diff::Changed(69.into(), 42.into()),
nonce: Diff::Changed(0.into(), 1.into()), nonce: Diff::Changed(0.into(), 1.into()),
@ -180,8 +190,8 @@ mod test {
#[test] #[test]
fn code() { fn code() {
let a = PodAccount{balance: 0.into(), nonce: 0.into(), code: vec![], storage: map![]}; let a = PodAccount{balance: 0.into(), nonce: 0.into(), code: Some(vec![]), storage: map![]};
let b = PodAccount{balance: 0.into(), nonce: 1.into(), code: vec![0], storage: map![]}; let b = PodAccount{balance: 0.into(), nonce: 1.into(), code: Some(vec![0]), storage: map![]};
assert_eq!(diff_pod(Some(&a), Some(&b)), Some(AccountDiff { assert_eq!(diff_pod(Some(&a), Some(&b)), Some(AccountDiff {
balance: Diff::Same, balance: Diff::Same,
nonce: Diff::Changed(0.into(), 1.into()), nonce: Diff::Changed(0.into(), 1.into()),
@ -195,13 +205,13 @@ mod test {
let a = PodAccount { let a = PodAccount {
balance: 0.into(), balance: 0.into(),
nonce: 0.into(), nonce: 0.into(),
code: vec![], code: Some(vec![]),
storage: map_into![1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 0, 6 => 0, 7 => 0] storage: map_into![1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 0, 6 => 0, 7 => 0]
}; };
let b = PodAccount { let b = PodAccount {
balance: 0.into(), balance: 0.into(),
nonce: 0.into(), nonce: 0.into(),
code: vec![], code: Some(vec![]),
storage: map_into![1 => 1, 2 => 3, 3 => 0, 5 => 0, 7 => 7, 8 => 0, 9 => 9] storage: map_into![1 => 1, 2 => 3, 3 => 0, 5 => 0, 7 => 7, 8 => 0, 9 => 9]
}; };
assert_eq!(diff_pod(Some(&a), Some(&b)), Some(AccountDiff { assert_eq!(diff_pod(Some(&a), Some(&b)), Some(AccountDiff {

View File

@ -18,14 +18,13 @@
use std::sync::{Weak, Arc}; use std::sync::{Weak, Arc};
use jsonrpc_core::*; use jsonrpc_core::*;
use std::collections::BTreeMap; use util::rlp::{UntrustedRlp, View};
//use util::H256;
use ethcore::client::{BlockChainClient, CallAnalytics, TransactionID, TraceId}; use ethcore::client::{BlockChainClient, CallAnalytics, TransactionID, TraceId};
use ethcore::miner::MinerService; use ethcore::miner::MinerService;
use ethcore::transaction::{Transaction as EthTransaction, SignedTransaction, Action}; use ethcore::transaction::{Transaction as EthTransaction, SignedTransaction, Action};
use v1::traits::Traces; use v1::traits::Traces;
use v1::helpers::CallRequest as CRequest; use v1::helpers::CallRequest as CRequest;
use v1::types::{TraceFilter, LocalizedTrace, Trace, BlockNumber, Index, CallRequest, Bytes, StateDiff, VMTrace, H256}; use v1::types::{TraceFilter, LocalizedTrace, BlockNumber, Index, CallRequest, Bytes, TraceResults, H256};
/// Traces api implementation. /// Traces api implementation.
pub struct TracesClient<C, M> where C: BlockChainClient, M: MinerService { pub struct TracesClient<C, M> where C: BlockChainClient, M: MinerService {
@ -126,22 +125,31 @@ impl<C, M> Traces for TracesClient<C, M> where C: BlockChainClient + 'static, M:
state_diffing: flags.contains(&("stateDiff".to_owned())), state_diffing: flags.contains(&("stateDiff".to_owned())),
}; };
let signed = try!(self.sign_call(request)); let signed = try!(self.sign_call(request));
let r = take_weak!(self.client).call(&signed, analytics); match take_weak!(self.client).call(&signed, analytics) {
if let Ok(executed) = r { Ok(e) => to_value(&TraceResults::from(e)),
// TODO maybe add other stuff to this? _ => Ok(Value::Null),
let mut ret = map!["output".to_owned() => to_value(&Bytes(executed.output)).unwrap()]; }
if let Some(trace) = executed.trace { })
ret.insert("trace".to_owned(), to_value(&Trace::from(trace)).unwrap()); }
}
if let Some(vm_trace) = executed.vm_trace { fn raw_transaction(&self, params: Params) -> Result<Value, Error> {
ret.insert("vmTrace".to_owned(), to_value(&VMTrace::from(vm_trace)).unwrap()); try!(self.active());
} trace!(target: "jsonrpc", "call: {:?}", params);
if let Some(state_diff) = executed.state_diff { from_params::<(Bytes, Vec<String>)>(params)
ret.insert("stateDiff".to_owned(), to_value(&StateDiff::from(state_diff)).unwrap()); .and_then(|(raw_transaction, flags)| {
} let raw_transaction = raw_transaction.to_vec();
return Ok(Value::Object(ret)) let analytics = CallAnalytics {
transaction_tracing: flags.contains(&("trace".to_owned())),
vm_tracing: flags.contains(&("vmTrace".to_owned())),
state_diffing: flags.contains(&("stateDiff".to_owned())),
};
match UntrustedRlp::new(&raw_transaction).as_val() {
Ok(signed) => match take_weak!(self.client).call(&signed, analytics) {
Ok(e) => to_value(&TraceResults::from(e)),
_ => Ok(Value::Null),
},
Err(_) => Err(Error::invalid_params()),
} }
Ok(Value::Null)
}) })
} }
} }

View File

@ -367,7 +367,7 @@ fn rpc_eth_pending_transaction_by_hash() {
tester.miner.pending_transactions.lock().insert(H256::zero(), tx); tester.miner.pending_transactions.lock().insert(H256::zero(), tx);
} }
let response = r#"{"jsonrpc":"2.0","result":{"blockHash":null,"blockNumber":null,"creates":null,"from":"0x0f65fe9276bc9a24ae7083ae28e2660ef72df99e","gas":"0x5208","gasPrice":"0x01","hash":"0x41df922fd0d4766fcc02e161f8295ec28522f329ae487f14d811e4b64c8d6e31","input":"0x","nonce":"0x00","to":"0x095e7baea6a6c7c4c2dfeb977efac326af552d87","transactionIndex":null,"value":"0x0a"},"id":1}"#; let response = r#"{"jsonrpc":"2.0","result":{"blockHash":null,"blockNumber":null,"creates":null,"from":"0x0f65fe9276bc9a24ae7083ae28e2660ef72df99e","gas":"0x5208","gasPrice":"0x01","hash":"0x41df922fd0d4766fcc02e161f8295ec28522f329ae487f14d811e4b64c8d6e31","input":"0x","nonce":"0x00","raw":"0xf85f800182520894095e7baea6a6c7c4c2dfeb977efac326af552d870a801ba048b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353a0efffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804","to":"0x095e7baea6a6c7c4c2dfeb977efac326af552d87","transactionIndex":null,"value":"0x0a"},"id":1}"#;
let request = r#"{ let request = r#"{
"jsonrpc": "2.0", "jsonrpc": "2.0",
"method": "eth_getTransactionByHash", "method": "eth_getTransactionByHash",

View File

@ -35,6 +35,9 @@ pub trait Traces: Sized + Send + Sync + 'static {
/// Executes the given call and returns a number of possible traces for it. /// Executes the given call and returns a number of possible traces for it.
fn call(&self, _: Params) -> Result<Value, Error>; fn call(&self, _: Params) -> Result<Value, Error>;
/// Executes the given raw transaction and returns a number of possible traces for it.
fn raw_transaction(&self, _: Params) -> Result<Value, Error>;
/// Should be used to convert object to io delegate. /// Should be used to convert object to io delegate.
fn to_delegate(self) -> IoDelegate<Self> { fn to_delegate(self) -> IoDelegate<Self> {
let mut delegate = IoDelegate::new(Arc::new(self)); let mut delegate = IoDelegate::new(Arc::new(self));
@ -43,6 +46,7 @@ pub trait Traces: Sized + Send + Sync + 'static {
delegate.add_method("trace_transaction", Traces::transaction_traces); delegate.add_method("trace_transaction", Traces::transaction_traces);
delegate.add_method("trace_block", Traces::block_traces); delegate.add_method("trace_block", Traces::block_traces);
delegate.add_method("trace_call", Traces::call); delegate.add_method("trace_call", Traces::call);
delegate.add_method("trace_rawTransaction", Traces::raw_transaction);
delegate delegate
} }

View File

@ -103,7 +103,7 @@ mod tests {
fn test_serialize_block_transactions() { fn test_serialize_block_transactions() {
let t = BlockTransactions::Full(vec![Transaction::default()]); let t = BlockTransactions::Full(vec![Transaction::default()]);
let serialized = serde_json::to_string(&t).unwrap(); let serialized = serde_json::to_string(&t).unwrap();
assert_eq!(serialized, r#"[{"hash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x00","blockHash":null,"blockNumber":null,"transactionIndex":null,"from":"0x0000000000000000000000000000000000000000","to":null,"value":"0x00","gasPrice":"0x00","gas":"0x00","input":"0x","creates":null}]"#); assert_eq!(serialized, r#"[{"hash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x00","blockHash":null,"blockNumber":null,"transactionIndex":null,"from":"0x0000000000000000000000000000000000000000","to":null,"value":"0x00","gasPrice":"0x00","gas":"0x00","input":"0x","creates":null,"raw":"0x"}]"#);
let t = BlockTransactions::Hashes(vec![H256::default().into()]); let t = BlockTransactions::Hashes(vec![H256::default().into()]);
let serialized = serde_json::to_string(&t).unwrap(); let serialized = serde_json::to_string(&t).unwrap();

View File

@ -42,6 +42,6 @@ pub use self::transaction::Transaction;
pub use self::transaction_request::{TransactionRequest, TransactionConfirmation, TransactionModification}; pub use self::transaction_request::{TransactionRequest, TransactionConfirmation, TransactionModification};
pub use self::call_request::CallRequest; pub use self::call_request::CallRequest;
pub use self::receipt::Receipt; pub use self::receipt::Receipt;
pub use self::trace::{Trace, LocalizedTrace, StateDiff, VMTrace}; pub use self::trace::{LocalizedTrace, TraceResults};
pub use self::trace_filter::TraceFilter; pub use self::trace_filter::TraceFilter;
pub use self::uint::U256; pub use self::uint::U256;

View File

@ -21,6 +21,7 @@ use ethcore::trace::{Trace as EthTrace, LocalizedTrace as EthLocalizedTrace};
use ethcore::trace as et; use ethcore::trace as et;
use ethcore::state_diff; use ethcore::state_diff;
use ethcore::account_diff; use ethcore::account_diff;
use ethcore::client::Executed;
use util::Uint; use util::Uint;
use v1::types::{Bytes, H160, H256, U256}; use v1::types::{Bytes, H160, H256, U256};
@ -193,6 +194,7 @@ impl From<account_diff::AccountDiff> for AccountDiff {
} }
} }
#[derive(Debug)]
/// Serde-friendly `StateDiff` shadow. /// Serde-friendly `StateDiff` shadow.
pub struct StateDiff(BTreeMap<H160, AccountDiff>); pub struct StateDiff(BTreeMap<H160, AccountDiff>);
@ -444,6 +446,32 @@ impl From<EthTrace> for Trace {
} }
} }
#[derive(Debug, Serialize)]
/// A diff of some chunk of memory.
pub struct TraceResults {
/// The output of the call/create
pub output: Vec<u8>,
/// The transaction trace.
pub trace: Option<Trace>,
/// The transaction trace.
#[serde(rename="vmTrace")]
pub vm_trace: Option<VMTrace>,
/// The transaction trace.
#[serde(rename="stateDiff")]
pub state_diff: Option<StateDiff>,
}
impl From<Executed> for TraceResults {
fn from(t: Executed) -> Self {
TraceResults {
output: t.output.into(),
trace: t.trace.map(Into::into),
vm_trace: t.vm_trace.map(Into::into),
state_diff: t.state_diff.map(Into::into),
}
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use serde_json; use serde_json;
@ -451,6 +479,18 @@ mod tests {
use v1::types::{Bytes, U256, H256, H160}; use v1::types::{Bytes, U256, H256, H160};
use super::*; use super::*;
#[test]
fn should_serialize_trace_results() {
let r = TraceResults {
output: vec![0x60],
trace: None,
vm_trace: None,
state_diff: None,
};
let serialized = serde_json::to_string(&r).unwrap();
assert_eq!(serialized, r#"{"output":[96],"trace":null,"vmTrace":null,"stateDiff":null}"#);
}
#[test] #[test]
fn test_trace_serialize() { fn test_trace_serialize() {
let t = LocalizedTrace { let t = LocalizedTrace {

View File

@ -14,6 +14,7 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>. // along with Parity. If not, see <http://www.gnu.org/licenses/>.
use util::rlp::encode;
use ethcore::contract_address; use ethcore::contract_address;
use ethcore::transaction::{LocalizedTransaction, Action, SignedTransaction}; use ethcore::transaction::{LocalizedTransaction, Action, SignedTransaction};
use v1::types::{Bytes, H160, H256, U256}; use v1::types::{Bytes, H160, H256, U256};
@ -49,6 +50,8 @@ pub struct Transaction {
pub input: Bytes, pub input: Bytes,
/// Creates contract /// Creates contract
pub creates: Option<H160>, pub creates: Option<H160>,
/// Raw transaction data
pub raw: Bytes,
} }
impl From<LocalizedTransaction> for Transaction { impl From<LocalizedTransaction> for Transaction {
@ -72,6 +75,7 @@ impl From<LocalizedTransaction> for Transaction {
Action::Create => Some(contract_address(&t.sender().unwrap(), &t.nonce).into()), Action::Create => Some(contract_address(&t.sender().unwrap(), &t.nonce).into()),
Action::Call(_) => None, Action::Call(_) => None,
}, },
raw: encode(&t.signed).to_vec().into(),
} }
} }
} }
@ -97,6 +101,7 @@ impl From<SignedTransaction> for Transaction {
Action::Create => Some(contract_address(&t.sender().unwrap(), &t.nonce).into()), Action::Create => Some(contract_address(&t.sender().unwrap(), &t.nonce).into()),
Action::Call(_) => None, Action::Call(_) => None,
}, },
raw: encode(&t).to_vec().into(),
} }
} }
} }
@ -110,7 +115,7 @@ mod tests {
fn test_transaction_serialize() { fn test_transaction_serialize() {
let t = Transaction::default(); let t = Transaction::default();
let serialized = serde_json::to_string(&t).unwrap(); let serialized = serde_json::to_string(&t).unwrap();
assert_eq!(serialized, r#"{"hash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x00","blockHash":null,"blockNumber":null,"transactionIndex":null,"from":"0x0000000000000000000000000000000000000000","to":null,"value":"0x00","gasPrice":"0x00","gas":"0x00","input":"0x","creates":null}"#); assert_eq!(serialized, r#"{"hash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x00","blockHash":null,"blockNumber":null,"transactionIndex":null,"from":"0x0000000000000000000000000000000000000000","to":null,"value":"0x00","gasPrice":"0x00","gas":"0x00","input":"0x","creates":null,"raw":"0x"}"#);
} }
} }