From c45dd8fba37fda8c872238bf9ab96b6df336cbd0 Mon Sep 17 00:00:00 2001 From: Gianmarco Fraccaroli Date: Tue, 17 Dec 2024 15:21:35 +0100 Subject: [PATCH] fix: fetch ibc balances --- shared/src/block.rs | 50 ++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/shared/src/block.rs b/shared/src/block.rs index 44b81232..2d8c608c 100644 --- a/shared/src/block.rs +++ b/shared/src/block.rs @@ -388,38 +388,36 @@ impl Block { let (msg, packet_data) = data?; let denom = packet_data.token.denom.to_string(); - // If the denom is the native token, we can just return the - // receiver + let ibc_trace = format!( + "{}/{}/{}", + msg.packet.port_id_on_b, + msg.packet.chan_id_on_b, + packet_data.token.denom + ); + + let trace = Id::IbcTrace(ibc_trace.clone()); + let address = namada_ibc::trace::convert_to_address(ibc_trace) + .expect("Failed to convert IBC trace to address"); + + let mut balances = vec![BalanceChange::new( + Id::Account(String::from(packet_data.receiver.as_ref())), + Token::Ibc(IbcToken { + address: Id::from(address.clone()), + trace, + }), + )]; + + // If the denom contains the namada native token, try to fetch + // the balance if denom.contains(&native_token.to_string()) { - vec![BalanceChange::new( + balances.push(BalanceChange::new( Id::Account(String::from( packet_data.receiver.as_ref(), )), Token::Native(native_token.clone()), - )] - } else { - let ibc_trace = format!( - "{}/{}/{}", - msg.packet.port_id_on_b, - msg.packet.chan_id_on_b, - packet_data.token.denom - ); - - let trace = Id::IbcTrace(ibc_trace.clone()); - let address = - namada_ibc::trace::convert_to_address(ibc_trace) - .expect("Failed to convert IBC trace to address"); - - vec![BalanceChange::new( - Id::Account(String::from( - packet_data.receiver.as_ref(), - )), - Token::Ibc(IbcToken { - address: Id::from(address.clone()), - trace, - }), - )] + )) } + balances } TransactionKind::TransparentTransfer(data) => { let data = data.as_ref()?;