correct workaround for RLP issue

This commit is contained in:
Robert Habermeier 2017-03-23 16:00:00 +01:00
parent 10a470a5fa
commit 974f89d5bf

View File

@ -738,12 +738,10 @@ pub mod header_proof {
impl Encodable for Response { impl Encodable for Response {
fn rlp_append(&self, s: &mut RlpStream) { fn rlp_append(&self, s: &mut RlpStream) {
s.begin_list(3).begin_list(self.proof.len()); s.begin_list(3)
for item in &self.proof { .append_list::<Vec<u8>,_>(&self.proof[..])
s.append_list(&item); .append(&self.hash)
} .append(&self.td);
s.append(&self.hash).append(&self.td);
} }
} }
} }
@ -1052,9 +1050,8 @@ pub mod account {
impl Decodable for Response { impl Decodable for Response {
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> { fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
let proof: Result<_, _> = rlp.at(0)?.iter().map(|x| x.as_list()).collect();
Ok(Response { Ok(Response {
proof: proof?, proof: rlp.list_at(0)?,
nonce: rlp.val_at(1)?, nonce: rlp.val_at(1)?,
balance: rlp.val_at(2)?, balance: rlp.val_at(2)?,
code_hash: rlp.val_at(3)?, code_hash: rlp.val_at(3)?,
@ -1065,12 +1062,9 @@ pub mod account {
impl Encodable for Response { impl Encodable for Response {
fn rlp_append(&self, s: &mut RlpStream) { fn rlp_append(&self, s: &mut RlpStream) {
s.begin_list(5).begin_list(self.proof.len()); s.begin_list(5)
for item in &self.proof { .append_list::<Vec<u8>,_>(&self.proof[..])
s.append_list(&item); .append(&self.nonce)
}
s.append(&self.nonce)
.append(&self.balance) .append(&self.balance)
.append(&self.code_hash) .append(&self.code_hash)
.append(&self.storage_root); .append(&self.storage_root);
@ -1200,9 +1194,8 @@ pub mod storage {
impl Decodable for Response { impl Decodable for Response {
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> { fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
let proof: Result<_, _> = rlp.at(0)?.iter().map(|x| x.as_list()).collect();
Ok(Response { Ok(Response {
proof: proof?, proof: rlp.list_at(0)?,
value: rlp.val_at(1)?, value: rlp.val_at(1)?,
}) })
} }
@ -1210,11 +1203,9 @@ pub mod storage {
impl Encodable for Response { impl Encodable for Response {
fn rlp_append(&self, s: &mut RlpStream) { fn rlp_append(&self, s: &mut RlpStream) {
s.begin_list(2).begin_list(self.proof.len()); s.begin_list(2)
for item in &self.proof { .append_list::<Vec<u8>,_>(&self.proof[..])
s.append_list(&item); .append(&self.value);
}
s.append(&self.value);
} }
} }
} }
@ -1543,7 +1534,7 @@ mod tests {
let full_req = Request::HeaderProof(req.clone()); let full_req = Request::HeaderProof(req.clone());
let res = HeaderProofResponse { let res = HeaderProofResponse {
proof: Vec::new(), proof: vec![vec![1, 2, 3], vec![4, 5, 6]],
hash: Default::default(), hash: Default::default(),
td: 100.into(), td: 100.into(),
}; };