Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 0 additions & 52 deletions shared/src/block.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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,
Expand All @@ -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<String, String>,
) -> 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,
Expand Down
17 changes: 17 additions & 0 deletions shared/src/block_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ pub enum EventKind {
FungibleTokenPacket,
MaspFeePayment,
MaspTransfer,
TxWasmName,
Unknown,
}

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,
Expand Down Expand Up @@ -218,6 +220,10 @@ pub enum TxAttributesType {
},
MaspFeePayment(MaspTxData),
MaspTransfer(MaspTxData),
WasmName {
name: String,
inner_tx_hash: Id,
},
}

impl TxAttributesType {
Expand Down Expand Up @@ -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,
})
}
}
}

Expand Down
50 changes: 31 additions & 19 deletions shared/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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()),
}))
Expand Down
Loading