-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6edeb43
commit 1c0f31f
Showing
4 changed files
with
115 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use crate::types::{BlockVersion, Proposal, Vote}; | ||
#[cfg(feature = "impl-rlp")] | ||
use rlp::{Decodable, DecoderError, Encodable, Rlp, RlpStream}; | ||
|
||
#[cfg(feature = "impl-rlp")] | ||
impl Encodable for BlockVersion { | ||
fn rlp_append(&self, s: &mut RlpStream) { | ||
let ver: u8 = (*self).into(); | ||
s.begin_list(1).append(&ver); | ||
} | ||
} | ||
|
||
#[cfg(feature = "impl-rlp")] | ||
impl Decodable for BlockVersion { | ||
fn decode(r: &Rlp) -> Result<Self, DecoderError> { | ||
let ver: u8 = r.val_at(0)?; | ||
ver.try_into() | ||
.map_err(|_| DecoderError::Custom("Invalid block version")) | ||
} | ||
} | ||
|
||
#[cfg(feature = "impl-rlp")] | ||
impl Encodable for Vote { | ||
fn rlp_append(&self, s: &mut RlpStream) { | ||
let vote_type: u8 = self.vote_type; | ||
s.begin_list(4) | ||
.append(&self.height) | ||
.append(&self.round) | ||
.append(&vote_type) | ||
.append(&self.block_hash.to_vec()); | ||
} | ||
} | ||
|
||
#[cfg(feature = "impl-rlp")] | ||
impl Encodable for Proposal { | ||
fn rlp_append(&self, s: &mut RlpStream) { | ||
s.begin_list(13) | ||
.append(&self.version) | ||
.append(&self.prev_hash) | ||
.append(&self.proposer) | ||
.append(&self.prev_state_root) | ||
.append(&self.transactions_root) | ||
.append(&self.signed_txs_hash) | ||
.append(&self.timestamp) | ||
.append(&self.number) | ||
.append(&self.gas_limit.as_u64()) | ||
.append_list(&self.extra_data) | ||
.append(&self.proof) | ||
.append(&self.call_system_script_count) | ||
.append_list(&self.tx_hashes); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters