From 421d2d1174c3aa74f280fa673af23165b4ac45b0 Mon Sep 17 00:00:00 2001 From: debris Date: Wed, 9 Dec 2015 00:45:33 +0100 Subject: [PATCH] signature agnostic transaction --- src/blockheader.rs | 5 +++++ src/lib.rs | 1 + src/transaction.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 src/transaction.rs diff --git a/src/blockheader.rs b/src/blockheader.rs index 2467127e2..50a8d9c35 100644 --- a/src/blockheader.rs +++ b/src/blockheader.rs @@ -64,3 +64,8 @@ impl Encodable for BlockHeader { } } +#[cfg(test)] +mod tests { + fn encoding_and_decoding() { + } +} diff --git a/src/lib.rs b/src/lib.rs index b55c90299..8037140df 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -77,6 +77,7 @@ extern crate ethcore_util as util; extern crate evmjit; pub mod blockheader; +pub mod transaction; #[test] fn it_works() { diff --git a/src/transaction.rs b/src/transaction.rs new file mode 100644 index 000000000..3b27ef03d --- /dev/null +++ b/src/transaction.rs @@ -0,0 +1,42 @@ +use util::hash::*; +use util::uint::*; +use util::rlp::*; + +pub struct Transaction { + nonce: U256, + gas_price: U256, + gas: U256, + receive_address: Option
, + value: U256, + data: Vec, +} + +impl Encodable for Transaction { + fn encode(&self, encoder: &mut E) where E: Encoder { + encoder.emit_list(| e | { + self.nonce.encode(e); + self.gas_price.encode(e); + self.gas.encode(e); + self.receive_address.encode(e); + self.value.encode(e); + self.data.encode(e); + }) + } +} + +impl Decodable for Transaction { + fn decode(decoder: &D) -> Result where D: Decoder { + decoder.read_list(| d | { + let transaction = Transaction { + nonce: try!(Decodable::decode(&d[0])), + gas_price: try!(Decodable::decode(&d[1])), + gas: try!(Decodable::decode(&d[2])), + receive_address: try!(Decodable::decode(&d[3])), + value: try!(Decodable::decode(&d[4])), + data: try!(Decodable::decode(&d[5])), + }; + Ok(transaction) + }) + } +} +