Skip to content

Commit e3708be

Browse files
authored
Merge pull request #444 from namada-net/grarco/extended-ibc-addresses
All addresses in IBC transfer
2 parents 05ba846 + 5e6c96e commit e3708be

File tree

1 file changed

+53
-28
lines changed

1 file changed

+53
-28
lines changed

shared/src/utils.rs

Lines changed: 53 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::collections::BTreeMap;
2+
13
use anyhow::Context;
24
use namada_ibc::apps::nft_transfer::types::PORT_ID_STR as NFT_PORT_ID_STR;
35
use namada_ibc::apps::transfer::types::packet::PacketData as FtPacketData;
@@ -10,7 +12,7 @@ use namada_ibc::core::channel::types::msgs::PacketMsg;
1012
use namada_ibc::core::channel::types::packet::Packet;
1113
use namada_ibc::core::handler::types::msgs::MsgEnvelope;
1214
use namada_ibc::core::host::types::identifiers::{ChannelId, PortId};
13-
use namada_sdk::address::Address;
15+
use namada_sdk::address::{Address, IBC};
1416
use namada_sdk::token::Transfer;
1517

1618
use crate::id::Id;
@@ -275,34 +277,57 @@ pub fn transfer_to_ibc_tx_kind(
275277
&transfer.message.packet_data.token.denom,
276278
)?;
277279

278-
let transfer_data = TransferData {
279-
sources: crate::ser::AccountsMap(
280-
[(
281-
convert_account(
282-
&transfer.message.packet_data,
283-
token.clone(),
284-
true,
285-
)
286-
.expect("Should be able to convert sender"),
287-
denominated_amount,
288-
)]
289-
.into(),
290-
),
291-
targets: crate::ser::AccountsMap(
292-
[(
293-
ChainAddress::ExternalAccount(
294-
transfer.message.packet_data.receiver.to_string(),
295-
token,
296-
),
297-
denominated_amount,
298-
)]
299-
.into(),
280+
// Extract the sources, targets and shielded section hash from the
281+
// transfer data. Remove the occurences of the IBC address since we
282+
// will replace them with more accurate data
283+
let (mut sources, mut targets, shielded_section_hash) = transfer
284+
.transfer
285+
.clone()
286+
.map(|t| {
287+
(
288+
t.sources
289+
.into_iter()
290+
.filter_map(|(source, amount)| {
291+
(source.owner != IBC).then_some((
292+
ChainAddress::ChainAccount(source),
293+
amount,
294+
))
295+
})
296+
.collect::<BTreeMap<_, _>>(),
297+
t.targets
298+
.into_iter()
299+
.filter_map(|(target, amount)| {
300+
(target.owner != IBC).then_some((
301+
ChainAddress::ChainAccount(target),
302+
amount,
303+
))
304+
})
305+
.collect::<BTreeMap<_, _>>(),
306+
t.shielded_section_hash,
307+
)
308+
})
309+
.unwrap_or_default();
310+
// Extend sources and targets with the actual IBC addresses
311+
sources.insert(
312+
convert_account(
313+
&transfer.message.packet_data,
314+
token.clone(),
315+
true,
316+
)
317+
.expect("Should be able to convert sender"),
318+
denominated_amount,
319+
);
320+
targets.insert(
321+
ChainAddress::ExternalAccount(
322+
transfer.message.packet_data.receiver.to_string(),
323+
token,
300324
),
301-
shielded_section_hash: transfer
302-
.transfer
303-
.clone()
304-
.map(|t| t.shielded_section_hash)
305-
.unwrap_or_default(),
325+
denominated_amount,
326+
);
327+
let transfer_data = TransferData {
328+
sources: crate::ser::AccountsMap(sources),
329+
targets: crate::ser::AccountsMap(targets),
330+
shielded_section_hash,
306331
};
307332

308333
if transfer.transfer.is_some() {

0 commit comments

Comments
 (0)