Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fetch ibc balances #225

Merged
merged 1 commit into from
Dec 18, 2024
Merged
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
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
Loading