RLP decoder refactoring
This commit is contained in:
10
src/block.rs
10
src/block.rs
@@ -45,14 +45,14 @@ impl Decodable for Block {
|
||||
if decoder.as_raw().len() != try!(decoder.as_rlp().payload_info()).total() {
|
||||
return Err(DecoderError::RlpIsTooBig);
|
||||
}
|
||||
let d = try!(decoder.as_list());
|
||||
if d.len() != 3 {
|
||||
let d = decoder.as_rlp();
|
||||
if d.item_count() != 3 {
|
||||
return Err(DecoderError::RlpIncorrectListLen);
|
||||
}
|
||||
Ok(Block {
|
||||
header: try!(Decodable::decode(&d[0])),
|
||||
transactions: try!(Decodable::decode(&d[1])),
|
||||
uncles: try!(Decodable::decode(&d[2])),
|
||||
header: try!(d.val_at(0)),
|
||||
transactions: try!(d.val_at(1)),
|
||||
uncles: try!(d.val_at(2)),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,12 +133,12 @@ impl HeapSizeOf for BlockDetails {
|
||||
|
||||
impl Decodable for BlockDetails {
|
||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||
let d = try!(decoder.as_list());
|
||||
let d = decoder.as_rlp();
|
||||
let details = BlockDetails {
|
||||
number: try!(Decodable::decode(&d[0])),
|
||||
total_difficulty: try!(Decodable::decode(&d[1])),
|
||||
parent: try!(Decodable::decode(&d[2])),
|
||||
children: try!(Decodable::decode(&d[3]))
|
||||
number: try!(d.val_at(0)),
|
||||
total_difficulty: try!(d.val_at(1)),
|
||||
parent: try!(d.val_at(2)),
|
||||
children: try!(d.val_at(3)),
|
||||
};
|
||||
Ok(details)
|
||||
}
|
||||
@@ -257,10 +257,10 @@ impl HeapSizeOf for TransactionAddress {
|
||||
|
||||
impl Decodable for TransactionAddress {
|
||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||
let d = try!(decoder.as_list());
|
||||
let d = decoder.as_rlp();
|
||||
let tx_address = TransactionAddress {
|
||||
block_hash: try!(Decodable::decode(&d[0])),
|
||||
index: try!(Decodable::decode(&d[1]))
|
||||
block_hash: try!(d.val_at(0)),
|
||||
index: try!(d.val_at(1)),
|
||||
};
|
||||
|
||||
Ok(tx_address)
|
||||
|
||||
@@ -267,20 +267,20 @@ impl Decodable for Action {
|
||||
|
||||
impl Decodable for Transaction {
|
||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||
let d = try!(decoder.as_list());
|
||||
if d.len() != 9 {
|
||||
let d = decoder.as_rlp();
|
||||
if d.item_count() != 9 {
|
||||
return Err(DecoderError::RlpIncorrectListLen);
|
||||
}
|
||||
Ok(Transaction {
|
||||
nonce: try!(Decodable::decode(&d[0])),
|
||||
gas_price: try!(Decodable::decode(&d[1])),
|
||||
gas: try!(Decodable::decode(&d[2])),
|
||||
action: try!(Decodable::decode(&d[3])),
|
||||
value: try!(Decodable::decode(&d[4])),
|
||||
data: try!(Decodable::decode(&d[5])),
|
||||
v: try!(u16::decode(&d[6])) as u8,
|
||||
r: try!(Decodable::decode(&d[7])),
|
||||
s: try!(Decodable::decode(&d[8])),
|
||||
nonce: try!(d.val_at(0)),
|
||||
gas_price: try!(d.val_at(1)),
|
||||
gas: try!(d.val_at(2)),
|
||||
action: try!(d.val_at(3)),
|
||||
value: try!(d.val_at(4)),
|
||||
data: try!(d.val_at(5)),
|
||||
v: try!(d.val_at(6)),
|
||||
r: try!(d.val_at(7)),
|
||||
s: try!(d.val_at(8)),
|
||||
hash: RefCell::new(None),
|
||||
sender: RefCell::new(None),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user