Skip to content

Commit

Permalink
Merge pull request #67 from yihuang/impl-lite-commit
Browse files Browse the repository at this point in the history
impl lite::Commit for commit::SignedHeader
  • Loading branch information
liamsi committed Nov 13, 2019
2 parents 5071ede + 3e48382 commit 3e987fe
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion tendermint/src/rpc/endpoint/commit.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! `/commit` endpoint JSONRPC wrapper

use crate::{block, rpc};
use crate::{amino_types::vote::CanonicalVote, block, lite, rpc, vote::SignedVote, Hash};
use serde::{Deserialize, Serialize};

/// Get commit information about a specific block
Expand Down Expand Up @@ -46,3 +46,26 @@ pub struct SignedHeader {
/// Commit containing signatures for the header
pub commit: block::Commit,
}

impl lite::Commit for SignedHeader {
type Vote = SignedVote;
fn header_hash(&self) -> Hash {
self.commit.block_id.hash
}
fn into_vec(&self) -> Vec<Option<Self::Vote>> {
let chain_id = self.header.chain_id.to_string();
let mut votes = self.commit.precommits.clone().into_vec();
votes
.drain(..)
.map(|opt| {
opt.map(|vote| {
SignedVote::new(
CanonicalVote::new((&vote).into(), &chain_id),
vote.validator_address,
vote.signature,
)
})
})
.collect()
}
}

0 comments on commit 3e987fe

Please sign in to comment.