Skip to content

Commit

Permalink
fixed <nil> block id signing
Browse files Browse the repository at this point in the history
  • Loading branch information
tomtau committed Nov 9, 2020
1 parent 2fa1678 commit e834853
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
15 changes: 10 additions & 5 deletions src/amino_types/proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,9 @@ impl SignableMsg for SignProposalRequest {

cp.encode_length_delimited(sign_bytes)?;
} else {
let cp = ProtoCanonicalProposal {
chain_id: chain_id.to_string(),
r#type: SignedMsgType::Proposal.to_u32() as i32,
height: proposal.height,
block_id: proposal.block_id.as_ref().map(|x| ProtoCanonicalBlockId {
let block_id = match proposal.block_id.as_ref() {
Some(x) if x.hash.is_empty() => None,
Some(x) => Some(ProtoCanonicalBlockId {
hash: x.hash.clone(),
part_set_header: x
.parts_header
Expand All @@ -154,6 +152,13 @@ impl SignableMsg for SignProposalRequest {
hash: y.hash.clone(),
}),
}),
None => None,
};
let cp = ProtoCanonicalProposal {
chain_id: chain_id.to_string(),
r#type: SignedMsgType::Proposal.to_u32() as i32,
height: proposal.height,
block_id,
pol_round: proposal.pol_round,
round: proposal.round,
timestamp: proposal.timestamp.map(Into::into),
Expand Down
16 changes: 11 additions & 5 deletions src/amino_types/vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,9 @@ impl SignableMsg for SignVoteRequest {

cv.encode_length_delimited(sign_bytes)?;
} else {
let cv = ProtoCanonicalVote {
r#type: vote.vote_type as i32,
height: vote.height,
round: vote.round as i64,
block_id: vote.block_id.as_ref().map(|x| ProtoCanonicalBlockId {
let block_id = match vote.block_id.as_ref() {
Some(x) if x.hash.is_empty() => None,
Some(x) => Some(ProtoCanonicalBlockId {
hash: x.hash.clone(),
part_set_header: x
.parts_header
Expand All @@ -214,6 +212,14 @@ impl SignableMsg for SignVoteRequest {
hash: y.hash.clone(),
}),
}),
None => None,
};

let cv = ProtoCanonicalVote {
r#type: vote.vote_type as i32,
height: vote.height,
round: vote.round as i64,
block_id,
timestamp: vote.timestamp.map(Into::into),
chain_id: chain_id.to_string(),
};
Expand Down

0 comments on commit e834853

Please sign in to comment.