Skip to content

Commit

Permalink
Merge branch 'yuji/fix-ibc-gen-shielded' (#2311)
Browse files Browse the repository at this point in the history
* origin/yuji/fix-ibc-gen-shielded:
  add SDK changelog
  fix parsing token address
  add changelog
  non-namada token to ibc-gen-shielded
  • Loading branch information
Gianmarco Fraccaroli committed Dec 27, 2023
2 parents 6fff25c + c6fb627 commit 833de58
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .changelog/unreleased/SDK/2308-fix-ibc-gen-shielded.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- ibc-gen-shielded can set non-Namada token
([\#2308](https://github.com/anoma/namada/issues/2308))
2 changes: 2 additions & 0 deletions .changelog/unreleased/bug-fixes/2308-fix-ibc-gen-shielded.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Non-Namada token can be given to ibc-gen-shielded
([\#2308](https://github.com/anoma/namada/issues/2308))
5 changes: 3 additions & 2 deletions apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3034,6 +3034,7 @@ pub mod args {
pub const TM_ADDRESS: Arg<String> = arg("tm-address");
pub const TOKEN_OPT: ArgOpt<WalletAddress> = TOKEN.opt();
pub const TOKEN: Arg<WalletAddress> = arg("token");
pub const TOKEN_STR: Arg<String> = arg("token");
pub const TRANSFER_SOURCE: Arg<WalletTransferSource> = arg("source");
pub const TRANSFER_TARGET: Arg<WalletTransferTarget> = arg("target");
pub const TRANSPARENT: ArgFlag = flag("transparent");
Expand Down Expand Up @@ -5532,7 +5533,7 @@ pub mod args {
query,
output_folder: self.output_folder,
target: chain_ctx.get(&self.target),
token: chain_ctx.get(&self.token),
token: self.token,
amount: self.amount,
port_id: self.port_id,
channel_id: self.channel_id,
Expand All @@ -5545,7 +5546,7 @@ pub mod args {
let query = Query::parse(matches);
let output_folder = OUTPUT_FOLDER_PATH.parse(matches);
let target = TRANSFER_TARGET.parse(matches);
let token = TOKEN.parse(matches);
let token = TOKEN_STR.parse(matches);
let amount = InputAmount::Unvalidated(AMOUNT.parse(matches));
let port_id = PORT_ID.parse(matches);
let channel_id = CHANNEL_ID.parse(matches);
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2397,8 +2397,8 @@ pub struct GenIbcShieldedTransafer<C: NamadaTypes = SdkTypes> {
pub output_folder: Option<PathBuf>,
/// The target address
pub target: C::TransferTarget,
/// The token address
pub token: C::Address,
/// The token address which could be a non-namada address
pub token: String,
/// Transferred token amount
pub amount: InputAmount,
/// Port ID via which the token is received
Expand Down
12 changes: 7 additions & 5 deletions sdk/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1214,12 +1214,14 @@ pub async fn format_denominated_amount(
/// Look up the IBC denomination from a IbcToken.
pub async fn query_ibc_denom<N: Namada>(
context: &N,
token: &Address,
token: impl AsRef<str>,
owner: Option<&Address>,
) -> String {
let hash = match token {
Address::Internal(InternalAddress::IbcToken(hash)) => hash.to_string(),
_ => return token.to_string(),
let hash = match Address::decode(token.as_ref()) {
Ok(Address::Internal(InternalAddress::IbcToken(hash))) => {
hash.to_string()
}
_ => return token.as_ref().to_string(),
};

if let Some(owner) = owner {
Expand All @@ -1246,5 +1248,5 @@ pub async fn query_ibc_denom<N: Namada>(
}
}

token.to_string()
token.as_ref().to_string()
}
3 changes: 2 additions & 1 deletion sdk/src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2038,7 +2038,8 @@ pub async fn build_ibc_transfer(
.map_err(|e| Error::from(QueryError::Wasm(e.to_string())))?;

let ibc_denom =
rpc::query_ibc_denom(context, &args.token, Some(&source)).await;
rpc::query_ibc_denom(context, &args.token.to_string(), Some(&source))
.await;
let token = PrefixedCoin {
denom: ibc_denom.parse().expect("Invalid IBC denom"),
// Set the IBC amount as an integer
Expand Down

0 comments on commit 833de58

Please sign in to comment.