diff --git a/shared/src/block.rs b/shared/src/block.rs index 24e920ad..025b6bdd 100644 --- a/shared/src/block.rs +++ b/shared/src/block.rs @@ -1,5 +1,4 @@ use std::collections::{BTreeMap, HashSet}; -use std::str::FromStr; use namada_ibc::IbcMessage; use namada_ibc::core::channel::types::msgs::{MsgRecvPacket, PacketMsg}; @@ -32,14 +31,6 @@ use crate::vote::GovernanceVote; pub type Epoch = u32; pub type BlockHeight = u32; -#[derive(Debug, Clone)] -pub enum EventKind { - Applied, - Rejected, - Accepted, - Unknown, -} - #[derive(Debug, Clone, Default, Copy)] pub enum TxEventStatusCode { Ok, @@ -56,49 +47,6 @@ impl From<&str> for TxEventStatusCode { } } -#[derive(Debug, Clone, Default)] -pub struct TxAttributes { - pub code: TxEventStatusCode, - pub gas: u64, - pub hash: Id, - pub height: u64, - pub info: String, -} - -impl TxAttributes { - pub fn deserialize( - event_kind: &EventKind, - attributes: &BTreeMap, - ) -> Self { - match event_kind { - EventKind::Unknown => Self::default(), - _ => Self { - code: attributes - .get("code") - .map(|code| TxEventStatusCode::from(code.as_str())) - .unwrap() - .to_owned(), - gas: attributes - .get("gas_used") - .map(|gas| u64::from_str(gas).unwrap()) - .unwrap() - .to_owned(), - hash: attributes - .get("hash") - .map(|hash| Id::Hash(hash.to_lowercase())) - .unwrap() - .to_owned(), - height: attributes - .get("height") - .map(|height| u64::from_str(height).unwrap()) - .unwrap() - .to_owned(), - info: attributes.get("info").unwrap().to_owned(), - }, - } - } -} - #[derive(Debug, Clone, Default)] pub struct Block { pub hash: Id, diff --git a/shared/src/block_result.rs b/shared/src/block_result.rs index 80290ebb..9f1cd58f 100644 --- a/shared/src/block_result.rs +++ b/shared/src/block_result.rs @@ -33,6 +33,7 @@ pub enum EventKind { FungibleTokenPacket, MaspFeePayment, MaspTransfer, + TxWasmName, Unknown, } @@ -40,6 +41,7 @@ impl From<&String> for EventKind { fn from(value: &String) -> Self { match value.as_str() { "tx/applied" => Self::Applied, + "tx/tx-wasm-name" => Self::TxWasmName, "send_packet" => Self::IbcCore(IbcCorePacketKind::Send), "recv_packet" => Self::IbcCore(IbcCorePacketKind::Recv), "fungible_token_packet" => Self::FungibleTokenPacket, @@ -218,6 +220,10 @@ pub enum TxAttributesType { }, MaspFeePayment(MaspTxData), MaspTransfer(MaspTxData), + WasmName { + name: String, + inner_tx_hash: Id, + }, } impl TxAttributesType { @@ -355,6 +361,17 @@ impl TxAttributesType { Some(Self::MaspTransfer(MaspTxData { indexed_tx, data })) } + EventKind::TxWasmName => { + let name = attributes.get("code-name").unwrap().to_string(); + let inner_tx_hash = Id::Hash( + attributes.get("inner-tx-hash").unwrap().to_string(), + ); + + Some(Self::WasmName { + name, + inner_tx_hash, + }) + } } } diff --git a/shared/src/transaction.rs b/shared/src/transaction.rs index 6249e5f5..ca80acb2 100644 --- a/shared/src/transaction.rs +++ b/shared/src/transaction.rs @@ -20,7 +20,7 @@ use namada_tx::{IndexedTx, Section, Tx}; use serde::Serialize; use crate::block::BlockHeight; -use crate::block_result::{BlockResult, TxEventStatusCode}; +use crate::block_result::{BlockResult, TxAttributesType, TxEventStatusCode}; use crate::checksums::Checksums; use crate::id::Id; use crate::ser::{IbcMessage, TransferData}; @@ -419,31 +419,43 @@ impl Transaction { bytes, )) .unwrap() - }); + }) + .expect("tx code id must always be present"); let tx_data = transaction.data(&tx_commitment).unwrap_or_default(); - let tx_kind = if let Some(id) = tx_code_id { - if let Some(tx_kind_name) = - checksums.get_name_by_id(&id) - { - TransactionKind::from( - &id, - &tx_kind_name, - &tx_data, - native_token.to_owned(), + let tx_kind_name = block_results + .begin_events + .iter() + .chain(block_results.end_events.iter()) + .find_map(|event| { + event.attributes.as_ref().and_then( + |attr| match attr { + TxAttributesType::WasmName { + name, + inner_tx_hash: h, + } if !name.is_empty() + && *h == inner_tx_id => + { + Some(name.clone()) + } + _ => None, + }, ) - } else { - TransactionKind::Unknown(Some(UnknownTransaction { - id: Some(id), - name: None, - data: Some(tx_data.clone()), - })) - } + }) + .or_else(|| checksums.get_name_by_id(&tx_code_id)); + + let tx_kind = if let Some(tx_kind_name) = tx_kind_name { + TransactionKind::from( + &tx_code_id, + &tx_kind_name, + &tx_data, + native_token.to_owned(), + ) } else { TransactionKind::Unknown(Some(UnknownTransaction { - id: None, + id: Some(tx_code_id), name: None, data: Some(tx_data.clone()), }))