Skip to content

Commit

Permalink
remove Address::Foreign
Browse files Browse the repository at this point in the history
  • Loading branch information
yito88 committed Sep 29, 2023
1 parent aaf01f2 commit b04b744
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 55 deletions.
4 changes: 0 additions & 4 deletions apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4783,7 +4783,6 @@ pub mod args {
GenIbcShieldedTransafer::<SdkTypes> {
query: self.query.to_sdk(ctx),
output_folder: self.output_folder,
sender: self.sender,
target: ctx.get(&self.target),
token: ctx.get(&self.token),
trace_path: self.trace_path,
Expand All @@ -4798,7 +4797,6 @@ pub mod args {
fn parse(matches: &ArgMatches) -> Self {
let query = Query::parse(matches);
let output_folder = OUTPUT_FOLDER_PATH.parse(matches);
let sender = SENDER.parse(matches);
let target = TRANSFER_TARGET.parse(matches);
let token = TOKEN.parse(matches);
let trace_path = TRACE_PATH.parse(matches);
Expand All @@ -4808,7 +4806,6 @@ pub mod args {
Self {
query,
output_folder,
sender,
target,
token,
trace_path,
Expand All @@ -4823,7 +4820,6 @@ pub mod args {
.arg(OUTPUT_FOLDER_PATH.def().help(
"The output folder path where the artifact will be stored.",
))
.arg(SENDER.def().help("The foreign sender address."))
.arg(TRANSFER_TARGET.def().help("The target address."))
.arg(TOKEN.def().help("The transfer token."))
.arg(TRACE_PATH.def().help("The IBC trace path of the token."))
Expand Down
1 change: 0 additions & 1 deletion core/src/ledger/storage_api/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ where
}
Address::Implicit(_) => Ok(true),
Address::Internal(_) => Ok(false),
Address::Foreign(_) => Ok(false),
}
}

Expand Down
14 changes: 0 additions & 14 deletions core/src/types/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ const PREFIX_ESTABLISHED: &str = "est";
const PREFIX_IMPLICIT: &str = "imp";
/// Fixed-length address strings prefix for internal addresses.
const PREFIX_INTERNAL: &str = "ano";
/// Fixed-length address strings prefix for foreign addresses.
const PREFIX_FOREIGN: &str = "for";
/// Fixed-length address strings prefix for IBC addresses.
const PREFIX_IBC: &str = "ibc";
/// Fixed-length address strings prefix for Ethereum addresses.
Expand Down Expand Up @@ -136,8 +134,6 @@ pub enum Address {
Implicit(ImplicitAddress),
/// An internal address represents a module with a native VP
Internal(InternalAddress),
/// An foreign address is provided from other chains
Foreign(String),
}

// We're using the string format of addresses (bech32m) for ordering to ensure
Expand Down Expand Up @@ -200,7 +196,6 @@ impl Address {
Some(hash_hex)
}
Address::Internal(_) => None,
Address::Foreign(_) => None,
}
}

Expand Down Expand Up @@ -259,9 +254,6 @@ impl Address {
debug_assert_eq!(string.len(), FIXED_LEN_STRING_BYTES);
string
}
Address::Foreign(addr) => {
format!("{}::{}", PREFIX_FOREIGN, addr)
}
}
.into_bytes();
string.resize(FIXED_LEN_STRING_BYTES, b' ');
Expand Down Expand Up @@ -382,9 +374,6 @@ impl Address {
"Invalid ERC20 internal address".to_string(),
)),
},
Some((PREFIX_FOREIGN, raw)) => {
Ok(Address::Foreign(raw.to_string()))
}
_ => Err(DecodeError::InvalidInnerEncoding(
ErrorKind::InvalidData,
"Invalid address prefix".to_string(),
Expand All @@ -408,9 +397,6 @@ impl Address {
Address::Internal(kind) => {
format!("Internal {}: {}", kind, self.encode())
}
Address::Foreign(_) => {
format!("Foreign: {}", self.encode())
}
}
}
}
Expand Down
1 change: 0 additions & 1 deletion shared/src/ledger/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,6 @@ where

accepted
}
Address::Foreign(_) => Ok(true),
};

// Returning error from here will short-circuit the VP parallel
Expand Down
2 changes: 0 additions & 2 deletions shared/src/sdk/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -898,8 +898,6 @@ pub struct GenIbcShieldedTransafer<C: NamadaTypes = SdkTypes> {
pub query: Query<C>,
/// The output directory path to where serialize the data
pub output_folder: Option<PathBuf>,
/// The foreign sender address
pub sender: String,
/// The target address
pub target: C::TransferTarget,
/// The token address
Expand Down
1 change: 0 additions & 1 deletion shared/src/sdk/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ pub async fn known_address<C: crate::ledger::queries::Client + Sync>(
query_has_storage_key(client, &key).await
}
Address::Implicit(_) | Address::Internal(_) => Ok(true),
Address::Foreign(_) => Ok(false),
}
}

Expand Down
7 changes: 1 addition & 6 deletions shared/src/sdk/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,6 @@ pub async fn find_pk<
"Internal address {} doesn't have any signing keys.",
addr
)),
Address::Foreign(_) => other_err(format!(
"Foreign address {} doesn't have any signing keys.",
addr
)),
}
}

Expand Down Expand Up @@ -278,8 +274,7 @@ pub async fn aux_signing_data<
Some(AccountPublicKeysMap::from_iter(public_keys.clone())),
1u8,
),
Some(owner @ Address::Internal(_))
| Some(owner @ Address::Foreign(_)) => {
Some(owner @ Address::Internal(_)) => {
return Err(Error::from(TxError::InvalidAccount(owner.encode())));
}
None => (None, 0u8),
Expand Down
50 changes: 27 additions & 23 deletions shared/src/sdk/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use namada_core::ledger::governance::storage::proposal::ProposalType;
use namada_core::ledger::governance::storage::vote::StorageProposalVote;
use namada_core::ledger::ibc::storage::channel_key;
use namada_core::ledger::pgf::cli::steward::Commission;
use namada_core::types::address::{masp, Address};
use namada_core::types::address::{masp, Address, InternalAddress};
use namada_core::types::dec::Dec;
use namada_core::types::hash::Hash;
use namada_core::types::token::MaspDenom;
Expand Down Expand Up @@ -2031,7 +2031,7 @@ pub async fn gen_ibc_shielded_transfer<
Some(_) => None,
None => return Ok(None),
};
let source = Address::Foreign(args.sender.clone());
let source = Address::Internal(InternalAddress::Ibc);
let (src_port_id, src_channel_id) =
get_ibc_src_port_channel(client, &args.port_id, &args.channel_id)
.await?;
Expand Down Expand Up @@ -2101,30 +2101,34 @@ async fn get_ibc_src_port_channel<C: crate::ledger::queries::Client + Sync>(
use crate::ibc_proto::protobuf::Protobuf;

let channel_key = channel_key(dest_port_id, dest_channel_id);
match rpc::query_storage_value_bytes::<C>(client, &channel_key, None, false)
.await
{
Ok((Some(bytes), _)) => {
let channel = ChannelEnd::decode_vec(&bytes).map_err(|_| {
let bytes =
rpc::query_storage_value_bytes::<C>(client, &channel_key, None, false)
.await?
.0
.ok_or_else(|| {
Error::Other(format!(
"Decoding channel end failed: port {}, channel {}",
dest_port_id, dest_channel_id
"No channel end: port {dest_port_id}, channel \
{dest_channel_id}"
))
})?;
if let Some(src_channel) = channel.remote.channel_id() {
Ok((channel.remote.port_id.clone(), src_channel.clone()))
} else {
Err(Error::Other(format!(
"The source channel doesn't exist: port {dest_port_id}, \
channel {dest_channel_id}"
)))
}
}
_ => Err(Error::Other(format!(
"Reading channel end failed: port {dest_port_id}, channel \
{dest_channel_id}"
))),
}
let channel = ChannelEnd::decode_vec(&bytes).map_err(|_| {
Error::Other(format!(
"Decoding channel end failed: port {dest_port_id}, channel \
{dest_channel_id}",
))
})?;
channel
.remote
.channel_id()
.map(|src_channel| {
(channel.remote.port_id.clone(), src_channel.clone())
})
.ok_or_else(|| {
Error::Other(format!(
"The source channel doesn't exist: port {dest_port_id}, \
channel {dest_channel_id}"
))
})
}

async fn expect_dry_broadcast<
Expand Down
3 changes: 0 additions & 3 deletions tests/src/e2e/ibc_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -939,16 +939,13 @@ fn shielded_transfer(
) -> Result<()> {
// Get masp proof for the following IBC transfer from the destination chain
// It will send 10 BTC from Chain A to PA(B) on Chain B
let sender = find_address(test_a, ALBERT)?;
let rpc_b = get_actor_rpc(test_b, &Who::Validator(0));
let output_folder = test_b.test_dir.path().to_string_lossy();
let amount = Amount::native_whole(10).to_string_native();
let args = [
"ibc-gen-shielded",
"--output-folder-path",
&output_folder,
"--sender",
&sender.to_string(),
"--target",
AB_PAYMENT_ADDRESS,
"--token",
Expand Down

0 comments on commit b04b744

Please sign in to comment.