Transaction includes signature.

This commit is contained in:
Gav Wood 2016-01-11 20:36:29 +01:00
parent 4ca8fde530
commit 845ac87f88
3 changed files with 36 additions and 14 deletions

View File

@ -5,3 +5,8 @@ pub type LogBloom = H2048;
/// Constant 2048-bit datum for 0. Often used as a default. /// Constant 2048-bit datum for 0. Often used as a default.
pub static ZERO_LOGBLOOM: LogBloom = H2048([0x00; 256]); pub static ZERO_LOGBLOOM: LogBloom = H2048([0x00; 256]);
pub enum Seal {
With,
Without,
}

View File

@ -34,11 +34,6 @@ pub struct Header {
pub hash: RefCell<Option<H256>>, pub hash: RefCell<Option<H256>>,
} }
pub enum Seal {
With,
Without,
}
impl Header { impl Header {
/// Create a new, default-valued, header. /// Create a new, default-valued, header.
pub fn new() -> Header { pub fn new() -> Header {

View File

@ -1,4 +1,5 @@
use util::*; use util::*;
use basic_types::*;
pub enum Action { pub enum Action {
Create, Create,
@ -14,13 +15,14 @@ pub struct Transaction {
pub action: Action, pub action: Action,
pub value: U256, pub value: U256,
pub data: Bytes, pub data: Bytes,
pub signature: Signature,
hash: RefCell<Option<H256>>, //TODO: make this private hash: RefCell<Option<H256>>, //TODO: make this private
} }
impl RlpStandard for Transaction { impl Transaction {
fn rlp_append(&self, s: &mut RlpStream) { pub fn rlp_append_opt(&self, s: &mut RlpStream, with_seal: Seal) {
s.append_list(6); s.append_list(6 + match with_seal { Seal::With => 3, _ => 0 });
s.append(&self.nonce); s.append(&self.nonce);
s.append(&self.gas_price); s.append(&self.gas_price);
s.append(&self.gas); s.append(&self.gas);
@ -30,9 +32,29 @@ impl RlpStandard for Transaction {
}; };
s.append(&self.value); s.append(&self.value);
s.append(&self.data); s.append(&self.data);
match with_seal {
Seal::With => {
s.append(&(self.signature.as_slice()[64] as u16));
s.append(&&self.signature.as_slice()[0..32]);
s.append(&&self.signature.as_slice()[32..64]);
},
_ => {}
} }
} }
pub fn rlp_bytes_opt(&self, with_seal: Seal) -> Bytes {
let mut s = RlpStream::new();
self.rlp_append_opt(&mut s, with_seal);
s.out()
}
pub fn rlp_sha3_opt(&self, with_seal: Seal) -> H256 { self.rlp_bytes_opt(with_seal).sha3() }
}
impl RlpStandard for Transaction {
fn rlp_append(&self, s: &mut RlpStream) { self.rlp_append_opt(s, Seal::With) }
}
impl Transaction { impl Transaction {
/// Get the hash of this header (sha3 of the RLP). /// Get the hash of this header (sha3 of the RLP).
pub fn hash(&self) -> H256 { pub fn hash(&self) -> H256 {
@ -55,7 +77,9 @@ impl Transaction {
pub fn action(&self) -> &Action { &self.action } pub fn action(&self) -> &Action { &self.action }
/// Returns transaction sender. /// Returns transaction sender.
pub fn sender(&self) -> Address { Address::new() } pub fn sender(&self) -> Address {
Address::new()
}
} }
impl Decodable for Action { impl Decodable for Action {
@ -72,17 +96,15 @@ impl Decodable for Action {
impl Decodable for Transaction { impl Decodable for Transaction {
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder { fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
let d = try!(decoder.as_list()); let d = try!(decoder.as_list());
Ok(Transaction {
let transaction = Transaction {
nonce: try!(Decodable::decode(&d[0])), nonce: try!(Decodable::decode(&d[0])),
gas_price: try!(Decodable::decode(&d[1])), gas_price: try!(Decodable::decode(&d[1])),
gas: try!(Decodable::decode(&d[2])), gas: try!(Decodable::decode(&d[2])),
action: try!(Decodable::decode(&d[3])), action: try!(Decodable::decode(&d[3])),
value: try!(Decodable::decode(&d[4])), value: try!(Decodable::decode(&d[4])),
data: try!(Decodable::decode(&d[5])), data: try!(Decodable::decode(&d[5])),
signature: Signature::from_rsv(&try!(Decodable::decode(&d[6])), &try!(Decodable::decode(&d[7])), try!(u16::decode(&d[8])) as u8),
hash: RefCell::new(None) hash: RefCell::new(None)
}; })
Ok(transaction)
} }
} }