Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Commit

Permalink
feat: decode more kind of txs in the server (#148)
Browse files Browse the repository at this point in the history
We were not decoding some type of transaction. This PR add everything
that was missing.
  • Loading branch information
rllola authored Feb 21, 2024
1 parent 58837b2 commit 2febefa
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions src/server/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use namada_sdk::types::key::common::PublicKey;
use namada_sdk::{
account::{InitAccount, UpdateAccount},
borsh::BorshDeserialize,
governance::VoteProposalData,
governance::{InitProposalData, VoteProposalData},
tx::data::{
pgf::UpdateStewardCommission,
pos::{Bond, Unbond, Withdraw},
pos::{Bond, CommissionChange, ConsensusKeyChange, MetaDataChange, Unbond, Withdraw},
},
types::token,
types::{address::Address, eth_bridge_pool::PendingTransfer},
Expand Down Expand Up @@ -36,7 +36,7 @@ pub enum TxDecoded {
Bond(Bond),
RevealPK(PublicKey),
VoteProposal(VoteProposalData),
BecomeValidator(Box<BecomeValidator>),
InitValidator(Box<BecomeValidator>),
Unbond(Unbond),
Withdraw(Withdraw),
InitAccount(InitAccount),
Expand All @@ -45,6 +45,15 @@ pub enum TxDecoded {
UpdateStewardCommission(UpdateStewardCommission),
EthPoolBridge(PendingTransfer),
Ibc(IbcTx),
BecomeValidator(Box<BecomeValidator>),
ConsensusKeyChange(ConsensusKeyChange),
CommissionChange(CommissionChange),
MetaDataChange(MetaDataChange),
ClaimRewards(Withdraw),
DeactivateValidator(Address),
InitProposal(InitProposalData),
ReactivateValidator(Address),
UnjailValidator(Address),
}

// we have a variant for MsgTransfer, but there are other message types
Expand Down Expand Up @@ -128,7 +137,7 @@ impl TxInfo {
VoteProposalData::try_from_slice(&self.data()).map(TxDecoded::VoteProposal)?
}
"tx_init_validator" => BecomeValidator::try_from_slice(&self.data())
.map(|t| TxDecoded::BecomeValidator(Box::new(t)))?,
.map(|t| TxDecoded::InitValidator(Box::new(t)))?,
"tx_unbond" => Unbond::try_from_slice(&self.data()).map(TxDecoded::Unbond)?,
"tx_withdraw" => Withdraw::try_from_slice(&self.data()).map(TxDecoded::Withdraw)?,
"tx_init_account" => {
Expand All @@ -151,6 +160,31 @@ impl TxInfo {
"tx_bridge_pool" => {
PendingTransfer::try_from_slice(&self.data()).map(TxDecoded::EthPoolBridge)?
}
"tx_become_validator" => BecomeValidator::try_from_slice(&self.data())
.map(|t| TxDecoded::InitValidator(Box::new(t)))?,
"tx_change_consensus_key" => ConsensusKeyChange::try_from_slice(&self.data())
.map(TxDecoded::ConsensusKeyChange)?,
"tx_change_validator_commission" => CommissionChange::try_from_slice(&self.data())
.map(TxDecoded::CommissionChange)?,
"tx_change_validator_metadata" => {
MetaDataChange::try_from_slice(&self.data()).map(TxDecoded::MetaDataChange)?
}
"tx_claim_rewards" => {
Withdraw::try_from_slice(&self.data()).map(TxDecoded::ClaimRewards)?
}
"tx_deactivate_validator" => {
Address::try_from_slice(&self.data()).map(TxDecoded::DeactivateValidator)?
}
"tx_init_proposal" => {
InitProposalData::try_from_slice(&self.data()).map(TxDecoded::InitProposal)?
}
"tx_reactivate_validator" => {
Address::try_from_slice(&self.data()).map(TxDecoded::ReactivateValidator)?
}
"tx_unjail_validator" => {
Address::try_from_slice(&self.data()).map(TxDecoded::UnjailValidator)?
}

_ => {
return Err(Error::InvalidTxData(format!(
"unsupported type_tx {}",
Expand Down

0 comments on commit 2febefa

Please sign in to comment.