Skip to content

Commit

Permalink
Merge pull request #225 from anoma/improve-ibc-balances
Browse files Browse the repository at this point in the history
fix: fetch ibc balances
  • Loading branch information
Fraccaman authored Dec 18, 2024
2 parents 59dddc7 + c45dd8f commit 35719e1
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 35719e1

Please sign in to comment.