Skip to content

Commit

Permalink
feat: wrap revealed pk data into struct
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszjasiuk committed Jul 3, 2024
1 parent eaa6ef8 commit b135add
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion shared/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ impl Block {
.flat_map(|(_, txs)| txs)
.filter_map(|tx| match &tx.kind {
TransactionKind::RevealPk(data) => {
let namada_public_key = data.clone();
let namada_public_key = data.public_key.clone();

Some((
PublicKey::from(namada_public_key.clone()),
Expand Down
15 changes: 11 additions & 4 deletions shared/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ use crate::block_result::{BlockResult, TxEventStatusCode};
use crate::checksums::Checksums;
use crate::id::Id;

// We wrap public key in a struct so we serialize data as object instead of
// string
#[derive(Serialize, Debug, Clone)]
pub struct RevealPkData {
pub public_key: PublicKey,
}

#[derive(Serialize, Debug, Clone)]
#[serde(untagged)]
pub enum TransactionKind {
Expand All @@ -36,7 +43,7 @@ pub enum TransactionKind {
InitProposal(InitProposalData),
MetadataChange(MetaDataChange),
CommissionChange(CommissionChange),
RevealPk(PublicKey),
RevealPk(RevealPkData),
Unknown,
}

Expand Down Expand Up @@ -86,10 +93,10 @@ impl TransactionKind {
CommissionChange::try_from_slice(data)
.expect("Cannot deserialize CommissionChange"),
),
"tx_reveal_pk" => TransactionKind::RevealPk(
PublicKey::try_from_slice(data)
"tx_reveal_pk" => TransactionKind::RevealPk(RevealPkData {
public_key: PublicKey::try_from_slice(data)
.expect("Cannot deserialize PublicKey"),
),
}),
_ => TransactionKind::Unknown,
}
}
Expand Down

0 comments on commit b135add

Please sign in to comment.