Skip to content

Commit

Permalink
fix: fetch ibc balances
Browse files Browse the repository at this point in the history
  • Loading branch information
Fraccaman committed Dec 17, 2024
1 parent 59dddc7 commit c45dd8f
Showing 1 changed file with 24 additions and 26 deletions.
50 changes: 24 additions & 26 deletions shared/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;
Expand Down

0 comments on commit c45dd8f

Please sign in to comment.