diff --git a/Cargo.lock b/Cargo.lock index f031158a5a..b5f0e610cf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4610,6 +4610,7 @@ dependencies = [ "sha2 0.9.9", "slip10_ed25519", "tempfile", + "tendermint-config", "tendermint-rpc", "thiserror", "tiny-bip39", diff --git a/crates/apps/src/lib/cli.rs b/crates/apps/src/lib/cli.rs index 12c6450850..3ad5f3198c 100644 --- a/crates/apps/src/lib/cli.rs +++ b/crates/apps/src/lib/cli.rs @@ -2566,7 +2566,7 @@ pub mod cmds { } #[derive(Clone, Debug)] - pub struct QueryEthBridgePool(pub args::Query); + pub struct QueryEthBridgePool(pub args::QueryWithoutCtx); impl SubCmd for QueryEthBridgePool { const CMD: &'static str = "query"; @@ -2574,18 +2574,18 @@ pub mod cmds { fn parse(matches: &ArgMatches) -> Option { matches .subcommand_matches(Self::CMD) - .map(|matches| Self(args::Query::parse(matches))) + .map(|matches| Self(args::QueryWithoutCtx::parse(matches))) } fn def() -> App { App::new(Self::CMD) .about("Get the contents of the Ethereum Bridge pool.") - .add_args::>() + .add_args::>() } } #[derive(Clone, Debug)] - pub struct QuerySignedBridgePool(pub args::Query); + pub struct QuerySignedBridgePool(pub args::QueryWithoutCtx); impl SubCmd for QuerySignedBridgePool { const CMD: &'static str = "query-signed"; @@ -2593,7 +2593,7 @@ pub mod cmds { fn parse(matches: &ArgMatches) -> Option { matches .subcommand_matches(Self::CMD) - .map(|matches| Self(args::Query::parse(matches))) + .map(|matches| Self(args::QueryWithoutCtx::parse(matches))) } fn def() -> App { @@ -2602,12 +2602,12 @@ pub mod cmds { "Get the contents of the Ethereum Bridge pool with a \ signed Merkle root.", ) - .add_args::>() + .add_args::>() } } #[derive(Clone, Debug)] - pub struct QueryRelayProgress(pub args::Query); + pub struct QueryRelayProgress(pub args::QueryWithoutCtx); impl SubCmd for QueryRelayProgress { const CMD: &'static str = "query-relayed"; @@ -2615,13 +2615,13 @@ pub mod cmds { fn parse(matches: &ArgMatches) -> Option { matches .subcommand_matches(Self::CMD) - .map(|matches| Self(args::Query::parse(matches))) + .map(|matches| Self(args::QueryWithoutCtx::parse(matches))) } fn def() -> App { App::new(Self::CMD) .about("Get the confirmation status of transfers to Ethereum.") - .add_args::>() + .add_args::>() } } @@ -2986,12 +2986,13 @@ pub mod args { pub const LEDGER_ADDRESS_ABOUT: &str = "Address of a ledger node as \"{scheme}://{host}:{port}\". If the \ scheme is not supplied, it is assumed to be TCP."; - pub const LEDGER_ADDRESS_DEFAULT: ArgDefault = - LEDGER_ADDRESS.default(DefaultFn(|| { + pub const CONFIG_RPC_LEDGER_ADDRESS: ArgDefaultFromCtx = + arg_default_from_ctx("node", DefaultFn(|| "".to_string())); + pub const LEDGER_ADDRESS: ArgDefault = arg("node") + .default(DefaultFn(|| { let raw = "127.0.0.1:26657"; TendermintAddress::from_str(raw).unwrap() })); - pub const LEDGER_ADDRESS: Arg = arg("node"); pub const LIST_FIND_ADDRESSES_ONLY: ArgFlag = flag("addr"); pub const LIST_FIND_KEYS_ONLY: ArgFlag = flag("keys"); pub const LOCALHOST: ArgFlag = flag("localhost"); @@ -3416,9 +3417,10 @@ pub mod args { impl CliToSdk> for RecommendBatch { fn to_sdk(self, ctx: &mut Context) -> RecommendBatch { + let query = self.query.to_sdk(ctx); let chain_ctx = ctx.borrow_chain_or_exit(); RecommendBatch:: { - query: self.query.to_sdk_ctxless(), + query, max_gas: self.max_gas, gas: self.gas, conversion_table: { @@ -3489,7 +3491,7 @@ pub mod args { impl CliToSdkCtxless> for BridgePoolProof { fn to_sdk_ctxless(self) -> BridgePoolProof { BridgePoolProof:: { - query: self.query.to_sdk_ctxless(), + ledger_address: self.ledger_address, transfers: self.transfers, relayer: self.relayer, } @@ -3498,11 +3500,11 @@ pub mod args { impl Args for BridgePoolProof { fn parse(matches: &ArgMatches) -> Self { - let query = Query::parse(matches); + let ledger_address = LEDGER_ADDRESS.parse(matches); let hashes = HASH_LIST.parse(matches); let relayer = RELAYER.parse(matches); Self { - query, + ledger_address, transfers: hashes .split_whitespace() .map(|hash| { @@ -3520,7 +3522,7 @@ pub mod args { } fn def(app: App) -> App { - app.add_args::>() + app.arg(LEDGER_ADDRESS.def().help(LEDGER_ADDRESS_ABOUT)) .arg(HASH_LIST.def().help( "Whitespace separated Keccak hash list of transfers in \ the Bridge pool.", @@ -3538,7 +3540,7 @@ pub mod args { { fn to_sdk_ctxless(self) -> RelayBridgePoolProof { RelayBridgePoolProof:: { - query: self.query.to_sdk_ctxless(), + ledger_address: self.ledger_address, transfers: self.transfers, relayer: self.relayer, confirmations: self.confirmations, @@ -3555,7 +3557,7 @@ pub mod args { impl Args for RelayBridgePoolProof { fn parse(matches: &ArgMatches) -> Self { let safe_mode = SAFE_MODE.parse(matches); - let query = Query::parse(matches); + let ledger_address = LEDGER_ADDRESS.parse(matches); let hashes = HASH_LIST.parse(matches); let relayer = RELAYER.parse(matches); let gas = ETH_GAS.parse(matches); @@ -3565,7 +3567,7 @@ pub mod args { let confirmations = ETH_CONFIRMATIONS.parse(matches); let sync = ETH_SYNC.parse(matches); Self { - query, + ledger_address, sync, transfers: hashes .split(' ') @@ -3590,7 +3592,7 @@ pub mod args { } fn def(app: App) -> App { - app.add_args::>() + app.arg(LEDGER_ADDRESS.def().help(LEDGER_ADDRESS_ABOUT)) .arg(SAFE_MODE.def().help( "Safe mode overrides keyboard interrupt signals, to \ ensure Ethereum transfers aren't canceled midway through.", @@ -3634,7 +3636,7 @@ pub mod args { { fn to_sdk_ctxless(self) -> BridgeValidatorSet { BridgeValidatorSet:: { - query: self.query.to_sdk_ctxless(), + ledger_address: self.ledger_address, epoch: self.epoch, } } @@ -3642,17 +3644,19 @@ pub mod args { impl Args for BridgeValidatorSet { fn parse(matches: &ArgMatches) -> Self { - let query = Query::parse(matches); + let ledger_address = LEDGER_ADDRESS.parse(matches); let epoch = EPOCH.parse(matches); - Self { query, epoch } + Self { + ledger_address, + epoch, + } } fn def(app: App) -> App { - app.add_args::>().arg( - EPOCH.def().help( + app.arg(LEDGER_ADDRESS.def().help(LEDGER_ADDRESS_ABOUT)) + .arg(EPOCH.def().help( "The epoch of the Bridge set of validators to query.", - ), - ) + )) } } @@ -3661,7 +3665,7 @@ pub mod args { { fn to_sdk_ctxless(self) -> GovernanceValidatorSet { GovernanceValidatorSet:: { - query: self.query.to_sdk_ctxless(), + ledger_address: self.ledger_address, epoch: self.epoch, } } @@ -3669,15 +3673,19 @@ pub mod args { impl Args for GovernanceValidatorSet { fn parse(matches: &ArgMatches) -> Self { - let query = Query::parse(matches); + let ledger_address = LEDGER_ADDRESS.parse(matches); let epoch = EPOCH.parse(matches); - Self { query, epoch } + Self { + ledger_address, + epoch, + } } fn def(app: App) -> App { - app.add_args::>().arg(EPOCH.def().help( - "The epoch of the Governance set of validators to query.", - )) + app.arg(LEDGER_ADDRESS.def().help(LEDGER_ADDRESS_ABOUT)) + .arg(EPOCH.def().help( + "The epoch of the Governance set of validators to query.", + )) } } @@ -3686,7 +3694,7 @@ pub mod args { { fn to_sdk_ctxless(self) -> ValidatorSetProof { ValidatorSetProof:: { - query: self.query.to_sdk_ctxless(), + ledger_address: self.ledger_address, epoch: self.epoch, } } @@ -3694,17 +3702,21 @@ pub mod args { impl Args for ValidatorSetProof { fn parse(matches: &ArgMatches) -> Self { - let query = Query::parse(matches); + let ledger_address = LEDGER_ADDRESS.parse(matches); let epoch = EPOCH.parse(matches); - Self { query, epoch } + Self { + ledger_address, + epoch, + } } fn def(app: App) -> App { - app.add_args::>().arg( - EPOCH - .def() - .help("The epoch of the set of validators to be proven."), - ) + app.arg(LEDGER_ADDRESS.def().help(LEDGER_ADDRESS_ABOUT)) + .arg( + EPOCH.def().help( + "The epoch of the set of validators to be proven.", + ), + ) } } @@ -3714,7 +3726,7 @@ pub mod args { fn to_sdk_ctxless(self) -> ValidatorSetUpdateRelay { ValidatorSetUpdateRelay:: { daemon: self.daemon, - query: self.query.to_sdk_ctxless(), + ledger_address: self.ledger_address, confirmations: self.confirmations, eth_rpc_endpoint: (), epoch: self.epoch, @@ -3731,9 +3743,9 @@ pub mod args { impl Args for ValidatorSetUpdateRelay { fn parse(matches: &ArgMatches) -> Self { + let ledger_address = LEDGER_ADDRESS.parse(matches); let safe_mode = SAFE_MODE.parse(matches); let daemon = DAEMON_MODE.parse(matches); - let query = Query::parse(matches); let epoch = EPOCH.parse(matches); let gas = ETH_GAS.parse(matches); let gas_price = ETH_GAS_PRICE.parse(matches); @@ -3746,9 +3758,9 @@ pub mod args { let success_dur = DAEMON_MODE_SUCCESS_DUR.parse(matches).map(|dur| dur.0); Self { + ledger_address, sync, daemon, - query, epoch, gas, gas_price, @@ -3762,7 +3774,7 @@ pub mod args { } fn def(app: App) -> App { - app.add_args::>() + app.arg(LEDGER_ADDRESS.def().help(LEDGER_ADDRESS_ABOUT)) .arg(SAFE_MODE.def().help( "Safe mode overrides keyboard interrupt signals, to \ ensure Ethereum transfers aren't canceled midway through.", @@ -5879,12 +5891,13 @@ pub mod args { type Address = WalletAddress; type BalanceOwner = WalletBalanceOwner; type BpConversionTable = PathBuf; + type ConfigRpcTendermintAddress = ConfigRpcAddress; type Data = PathBuf; type EthereumAddress = String; type Keypair = WalletKeypair; type NativeAddress = (); type PublicKey = WalletPublicKey; - type TendermintAddress = TendermintAddress; + type TendermintAddress = tendermint_config::net::Address; type TransferSource = WalletTransferSource; type TransferTarget = WalletTransferTarget; type ViewingKey = WalletViewingKey; @@ -5900,7 +5913,7 @@ pub mod args { output_folder: self.output_folder, force: self.force, broadcast_only: self.broadcast_only, - ledger_address: (), + ledger_address: ctx.get(&self.ledger_address), initialized_account_alias: self.initialized_account_alias, wallet_alias_force: self.wallet_alias_force, fee_amount: self.fee_amount, @@ -5959,7 +5972,7 @@ pub mod args { return once the transaction is added to the mempool.", )) .arg( - LEDGER_ADDRESS_DEFAULT + CONFIG_RPC_LEDGER_ADDRESS .def() .help(LEDGER_ADDRESS_ABOUT) // This used to be "ledger-address", alias for compatibility @@ -6055,7 +6068,7 @@ pub mod args { let dump_tx = DUMP_TX.parse(matches); let force = FORCE.parse(matches); let broadcast_only = BROADCAST_ONLY.parse(matches); - let ledger_address = LEDGER_ADDRESS_DEFAULT.parse(matches); + let ledger_address = CONFIG_RPC_LEDGER_ADDRESS.parse(matches); let initialized_account_alias = ALIAS_OPT.parse(matches); let fee_amount = FEE_AMOUNT_OPT.parse(matches).map(InputAmount::Unvalidated); @@ -6103,16 +6116,44 @@ pub mod args { } } - impl CliToSdkCtxless> for Query { - fn to_sdk_ctxless(self) -> Query { - Query:: { ledger_address: () } + impl CliToSdk> for Query { + fn to_sdk(self, ctx: &mut Context) -> Query { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + Query:: { + ledger_address: chain_ctx.get(&self.ledger_address), + } } } impl Args for Query { fn def(app: App) -> App { app.arg( - LEDGER_ADDRESS_DEFAULT + CONFIG_RPC_LEDGER_ADDRESS + .def() + .help(LEDGER_ADDRESS_ABOUT) + // This used to be "ledger-address", alias for compatibility + .alias("ledger-address"), + ) + } + + fn parse(matches: &ArgMatches) -> Self { + let ledger_address = CONFIG_RPC_LEDGER_ADDRESS.parse(matches); + Self { ledger_address } + } + } + + impl CliToSdkCtxless> for QueryWithoutCtx { + fn to_sdk_ctxless(self) -> QueryWithoutCtx { + QueryWithoutCtx:: { + ledger_address: self.ledger_address, + } + } + } + + impl Args for QueryWithoutCtx { + fn def(app: App) -> App { + app.arg( + LEDGER_ADDRESS .def() .help(LEDGER_ADDRESS_ABOUT) // This used to be "ledger-address", alias for compatibility @@ -6121,7 +6162,7 @@ pub mod args { } fn parse(matches: &ArgMatches) -> Self { - let ledger_address = LEDGER_ADDRESS_DEFAULT.parse(matches); + let ledger_address = LEDGER_ADDRESS.parse(matches); Self { ledger_address } } } diff --git a/crates/apps/src/lib/cli/api.rs b/crates/apps/src/lib/cli/api.rs index 0748e77549..3a5db7d33e 100644 --- a/crates/apps/src/lib/cli/api.rs +++ b/crates/apps/src/lib/cli/api.rs @@ -5,12 +5,10 @@ use namada_sdk::queries::Client; use namada_sdk::rpc::wait_until_node_is_synched; use tendermint_config::net::Address as TendermintAddress; -use crate::client::utils; - /// Trait for clients that can be used with the CLI. #[async_trait::async_trait(?Send)] pub trait CliClient: Client + Sync { - fn from_tendermint_address(address: &mut TendermintAddress) -> Self; + fn from_tendermint_address(address: &TendermintAddress) -> Self; async fn wait_until_node_is_synced( &self, io: &impl Io, @@ -19,8 +17,8 @@ pub trait CliClient: Client + Sync { #[async_trait::async_trait(?Send)] impl CliClient for HttpClient { - fn from_tendermint_address(address: &mut TendermintAddress) -> Self { - HttpClient::new(utils::take_config_address(address)).unwrap() + fn from_tendermint_address(address: &TendermintAddress) -> Self { + HttpClient::new(address.clone()).unwrap() } async fn wait_until_node_is_synced( diff --git a/crates/apps/src/lib/cli/client.rs b/crates/apps/src/lib/cli/client.rs index 2ae441d2d2..b7f41dc6a2 100644 --- a/crates/apps/src/lib/cli/client.rs +++ b/crates/apps/src/lib/cli/client.rs @@ -23,11 +23,13 @@ impl CliApi { use NamadaClientWithContext as Sub; match cmd { // Ledger cmds - Sub::TxCustom(TxCustom(mut args)) => { + Sub::TxCustom(TxCustom(args)) => { + // TODO: too much boilerplate to setup client + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.tx.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.tx.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); @@ -48,44 +50,48 @@ impl CliApi { ) } } - Sub::TxTransfer(TxTransfer(mut args)) => { + Sub::TxTransfer(TxTransfer(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.tx.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.tx.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); let namada = ctx.to_sdk(client, io); tx::submit_transfer(&namada, args).await?; } - Sub::TxIbcTransfer(TxIbcTransfer(mut args)) => { + Sub::TxIbcTransfer(TxIbcTransfer(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.tx.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.tx.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); let namada = ctx.to_sdk(client, io); tx::submit_ibc_transfer(&namada, args).await?; } - Sub::TxUpdateAccount(TxUpdateAccount(mut args)) => { + Sub::TxUpdateAccount(TxUpdateAccount(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.tx.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.tx.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); let namada = ctx.to_sdk(client, io); tx::submit_update_account(&namada, args).await?; } - Sub::TxInitAccount(TxInitAccount(mut args)) => { + Sub::TxInitAccount(TxInitAccount(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.tx.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.tx.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); @@ -106,11 +112,12 @@ impl CliApi { ) } } - Sub::TxBecomeValidator(TxBecomeValidator(mut args)) => { + Sub::TxBecomeValidator(TxBecomeValidator(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.tx.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.tx.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); @@ -130,11 +137,12 @@ impl CliApi { tx::submit_become_validator(&namada, &mut config, args) .await?; } - Sub::TxInitValidator(TxInitValidator(mut args)) => { + Sub::TxInitValidator(TxInitValidator(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.tx.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.tx.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); @@ -154,88 +162,96 @@ impl CliApi { tx::submit_init_validator(&namada, &mut config, args) .await?; } - Sub::TxInitProposal(TxInitProposal(mut args)) => { + Sub::TxInitProposal(TxInitProposal(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.tx.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.tx.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); let namada = ctx.to_sdk(client, io); tx::submit_init_proposal(&namada, args).await?; } - Sub::TxVoteProposal(TxVoteProposal(mut args)) => { + Sub::TxVoteProposal(TxVoteProposal(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.tx.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.tx.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); let namada = ctx.to_sdk(client, io); tx::submit_vote_proposal(&namada, args).await?; } - Sub::TxRevealPk(TxRevealPk(mut args)) => { + Sub::TxRevealPk(TxRevealPk(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.tx.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.tx.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); let namada = ctx.to_sdk(client, io); tx::submit_reveal_pk(&namada, args).await?; } - Sub::Bond(Bond(mut args)) => { + Sub::Bond(Bond(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.tx.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.tx.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); let namada = ctx.to_sdk(client, io); tx::submit_bond(&namada, args).await?; } - Sub::Unbond(Unbond(mut args)) => { + Sub::Unbond(Unbond(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.tx.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.tx.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); let namada = ctx.to_sdk(client, io); tx::submit_unbond(&namada, args).await?; } - Sub::Withdraw(Withdraw(mut args)) => { + Sub::Withdraw(Withdraw(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.tx.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.tx.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); let namada = ctx.to_sdk(client, io); tx::submit_withdraw(&namada, args).await?; } - Sub::ClaimRewards(ClaimRewards(mut args)) => { + Sub::ClaimRewards(ClaimRewards(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.tx.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.tx.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); let namada = ctx.to_sdk(client, io); tx::submit_claim_rewards(&namada, args).await?; } - Sub::Redelegate(Redelegate(mut args)) => { + Sub::Redelegate(Redelegate(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.tx.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.tx.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); @@ -243,12 +259,13 @@ impl CliApi { tx::submit_redelegate(&namada, args).await?; } Sub::TxCommissionRateChange(TxCommissionRateChange( - mut args, + args, )) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.tx.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.tx.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); @@ -256,13 +273,12 @@ impl CliApi { tx::submit_validator_commission_change(&namada, args) .await?; } - Sub::TxChangeConsensusKey(TxChangeConsensusKey( - mut args, - )) => { + Sub::TxChangeConsensusKey(TxChangeConsensusKey(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.tx.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.tx.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); @@ -286,11 +302,12 @@ impl CliApi { ) .await?; } - Sub::TxMetadataChange(TxMetadataChange(mut args)) => { + Sub::TxMetadataChange(TxMetadataChange(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.tx.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.tx.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); @@ -300,48 +317,48 @@ impl CliApi { } // Eth bridge Sub::AddToEthBridgePool(args) => { - let mut args = args.0; + let args = args.0; + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.tx.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.tx.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); let namada = ctx.to_sdk(client, io); tx::submit_bridge_pool_tx(&namada, args).await?; } - Sub::TxUnjailValidator(TxUnjailValidator(mut args)) => { + Sub::TxUnjailValidator(TxUnjailValidator(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.tx.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.tx.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); let namada = ctx.to_sdk(client, io); tx::submit_unjail_validator(&namada, args).await?; } - Sub::TxDeactivateValidator(TxDeactivateValidator( - mut args, - )) => { + Sub::TxDeactivateValidator(TxDeactivateValidator(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.tx.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.tx.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); let namada = ctx.to_sdk(client, io); tx::submit_deactivate_validator(&namada, args).await?; } - Sub::TxReactivateValidator(TxReactivateValidator( - mut args, - )) => { + Sub::TxReactivateValidator(TxReactivateValidator(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.tx.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.tx.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); @@ -349,12 +366,13 @@ impl CliApi { tx::submit_reactivate_validator(&namada, args).await?; } Sub::TxUpdateStewardCommission( - TxUpdateStewardCommission(mut args), + TxUpdateStewardCommission(args), ) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.tx.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.tx.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); @@ -362,11 +380,12 @@ impl CliApi { tx::submit_update_steward_commission(&namada, args) .await?; } - Sub::TxResignSteward(TxResignSteward(mut args)) => { + Sub::TxResignSteward(TxResignSteward(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.tx.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.tx.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); @@ -374,19 +393,23 @@ impl CliApi { tx::submit_resign_steward(&namada, args).await?; } // Ledger queries - Sub::QueryEpoch(QueryEpoch(mut args)) => { + Sub::QueryEpoch(QueryEpoch(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address(&mut args.ledger_address) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let namada = ctx.to_sdk(client, io); rpc::query_and_print_epoch(&namada).await; } - Sub::QueryValidatorState(QueryValidatorState(mut args)) => { + Sub::QueryValidatorState(QueryValidatorState(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.query.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.query.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); @@ -394,62 +417,70 @@ impl CliApi { rpc::query_and_print_validator_state(&namada, args) .await; } - Sub::QueryTransfers(QueryTransfers(mut args)) => { + Sub::QueryTransfers(QueryTransfers(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.query.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.query.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); let namada = ctx.to_sdk(client, io); rpc::query_transfers(&namada, args).await; } - Sub::QueryConversions(QueryConversions(mut args)) => { + Sub::QueryConversions(QueryConversions(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.query.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.query.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); let namada = ctx.to_sdk(client, io); rpc::query_conversions(&namada, args).await; } - Sub::QueryMaspRewardTokens(QueryMaspRewardTokens( - mut args, - )) => { + Sub::QueryMaspRewardTokens(QueryMaspRewardTokens(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address(&mut args.ledger_address) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let namada = ctx.to_sdk(client, io); rpc::query_masp_reward_tokens(&namada).await; } - Sub::QueryBlock(QueryBlock(mut args)) => { + Sub::QueryBlock(QueryBlock(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address(&mut args.ledger_address) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let namada = ctx.to_sdk(client, io); rpc::query_block(&namada).await; } - Sub::QueryBalance(QueryBalance(mut args)) => { + Sub::QueryBalance(QueryBalance(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.query.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.query.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); let namada = ctx.to_sdk(client, io); rpc::query_balance(&namada, args).await; } - Sub::QueryBonds(QueryBonds(mut args)) => { + Sub::QueryBonds(QueryBonds(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.query.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.query.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); @@ -458,22 +489,24 @@ impl CliApi { .await .expect("expected successful query of bonds"); } - Sub::QueryBondedStake(QueryBondedStake(mut args)) => { + Sub::QueryBondedStake(QueryBondedStake(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.query.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.query.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); let namada = ctx.to_sdk(client, io); rpc::query_bonded_stake(&namada, args).await; } - Sub::QueryCommissionRate(QueryCommissionRate(mut args)) => { + Sub::QueryCommissionRate(QueryCommissionRate(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.query.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.query.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); @@ -481,110 +514,120 @@ impl CliApi { rpc::query_and_print_commission_rate(&namada, args) .await; } - Sub::QueryMetaData(QueryMetaData(mut args)) => { + Sub::QueryMetaData(QueryMetaData(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.query.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.query.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); let namada = ctx.to_sdk(client, io); rpc::query_and_print_metadata(&namada, args).await; } - Sub::QuerySlashes(QuerySlashes(mut args)) => { + Sub::QuerySlashes(QuerySlashes(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.query.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.query.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); let namada = ctx.to_sdk(client, io); rpc::query_slashes(&namada, args).await; } - Sub::QueryRewards(QueryRewards(mut args)) => { + Sub::QueryRewards(QueryRewards(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.query.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.query.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); let namada = ctx.to_sdk(client, io); rpc::query_and_print_rewards(&namada, args).await; } - Sub::QueryDelegations(QueryDelegations(mut args)) => { + Sub::QueryDelegations(QueryDelegations(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.query.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.query.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); let namada = ctx.to_sdk(client, io); rpc::query_delegations(&namada, args).await; } - Sub::QueryFindValidator(QueryFindValidator(mut args)) => { + Sub::QueryFindValidator(QueryFindValidator(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.query.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.query.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); let namada = ctx.to_sdk(client, io); rpc::query_find_validator(&namada, args).await; } - Sub::QueryResult(QueryResult(mut args)) => { + Sub::QueryResult(QueryResult(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.query.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.query.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); let namada = ctx.to_sdk(client, io); rpc::query_result(&namada, args).await; } - Sub::QueryRawBytes(QueryRawBytes(mut args)) => { + Sub::QueryRawBytes(QueryRawBytes(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.query.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.query.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); let namada = ctx.to_sdk(client, io); rpc::query_raw_bytes(&namada, args).await; } - Sub::QueryProposal(QueryProposal(mut args)) => { + Sub::QueryProposal(QueryProposal(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.query.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.query.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); let namada = ctx.to_sdk(client, io); rpc::query_proposal(&namada, args).await; } - Sub::QueryProposalResult(QueryProposalResult(mut args)) => { + Sub::QueryProposalResult(QueryProposalResult(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.query.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.query.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); let namada = ctx.to_sdk(client, io); rpc::query_proposal_result(&namada, args).await; } - Sub::QueryProposalVotes(QueryProposalVotes(mut args)) => { + Sub::QueryProposalVotes(QueryProposalVotes(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.query.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.query.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); @@ -592,45 +635,49 @@ impl CliApi { rpc::query_proposal_votes(&namada, args).await; } Sub::QueryProtocolParameters(QueryProtocolParameters( - mut args, + args, )) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.query.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.query.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); let namada = ctx.to_sdk(client, io); rpc::query_protocol_parameters(&namada, args).await; } - Sub::QueryPgf(QueryPgf(mut args)) => { + Sub::QueryPgf(QueryPgf(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.query.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.query.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); let namada = ctx.to_sdk(client, io); rpc::query_pgf(&namada, args).await; } - Sub::QueryAccount(QueryAccount(mut args)) => { + Sub::QueryAccount(QueryAccount(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.query.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.query.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); let namada = ctx.to_sdk(client, io); rpc::query_account(&namada, args).await; } - Sub::SignTx(SignTx(mut args)) => { + Sub::SignTx(SignTx(args)) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.tx.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.tx.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); @@ -638,12 +685,13 @@ impl CliApi { tx::sign_tx(&namada, args).await?; } Sub::GenIbcShieldedTransafer(GenIbcShieldedTransafer( - mut args, + args, )) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.query.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.query.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); @@ -687,9 +735,9 @@ impl CliApi { Utils::EpochSleep(EpochSleep(args)) => { let mut ctx = cli::Context::new::(global_args) .expect("expected to construct a context"); - let mut ledger_address = args.ledger_address.clone(); - let client = - C::from_tendermint_address(&mut ledger_address); + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = chain_ctx.get(&args.ledger_address); + let client = C::from_tendermint_address(&ledger_address); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); let namada = ctx.to_sdk(client, io); diff --git a/crates/apps/src/lib/cli/context.rs b/crates/apps/src/lib/cli/context.rs index 4f31ee6445..0dec1f5939 100644 --- a/crates/apps/src/lib/cli/context.rs +++ b/crates/apps/src/lib/cli/context.rs @@ -18,6 +18,7 @@ use namada_sdk::masp::fs::FsShieldedUtils; use namada_sdk::masp::ShieldedContext; use namada_sdk::wallet::Wallet; use namada_sdk::{Namada, NamadaImpl}; +use tendermint_config::net::Address as TendermintAddress; use super::args; use crate::cli::utils; @@ -68,6 +69,15 @@ pub type WalletPublicKey = FromContext; /// either in the wallet pub type WalletBalanceOwner = FromContext; +/// RPC address of a locally configured node +pub type ConfigRpcAddress = FromContext; + +impl From for ConfigRpcAddress { + fn from(value: TendermintAddress) -> Self { + FromContext::new(value.to_string()) + } +} + /// Command execution context #[derive(Debug)] pub struct Context { @@ -409,6 +419,19 @@ impl ArgFromContext for Address { } } +impl ArgFromContext for TendermintAddress { + fn arg_from_ctx( + ctx: &ChainContext, + raw: impl AsRef, + ) -> Result { + if raw.as_ref().is_empty() { + return Ok(ctx.config.ledger.cometbft.rpc.laddr.clone()); + } + Self::from_str(raw.as_ref()) + .map_err(|err| format!("Invalid Tendermint address: {err}")) + } +} + impl ArgFromMutContext for common::SecretKey { fn arg_from_mut_ctx( ctx: &mut ChainContext, diff --git a/crates/apps/src/lib/cli/relayer.rs b/crates/apps/src/lib/cli/relayer.rs index 7dc360db4f..e46f568023 100644 --- a/crates/apps/src/lib/cli/relayer.rs +++ b/crates/apps/src/lib/cli/relayer.rs @@ -22,12 +22,13 @@ impl CliApi { let (sub, mut ctx) = *boxed; match sub { EthBridgePoolWithCtx::RecommendBatch(RecommendBatch( - mut args, + args, )) => { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + let ledger_address = + chain_ctx.get(&args.query.ledger_address); let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.query.ledger_address, - ) + C::from_tendermint_address(&ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk(&mut ctx); @@ -38,22 +39,18 @@ impl CliApi { } cli::NamadaRelayer::EthBridgePoolWithoutCtx(sub) => match sub { EthBridgePoolWithoutCtx::ConstructProof(ConstructProof( - mut args, + args, )) => { let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.query.ledger_address, - ) + C::from_tendermint_address(&args.ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk_ctxless(); bridge_pool::construct_proof(&client, &io, args).await?; } - EthBridgePoolWithoutCtx::RelayProof(RelayProof(mut args)) => { + EthBridgePoolWithoutCtx::RelayProof(RelayProof(args)) => { let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.query.ledger_address, - ) + C::from_tendermint_address(&args.ledger_address) }); client.wait_until_node_is_synced(&io).await?; let eth_client = @@ -65,41 +62,37 @@ impl CliApi { .await?; } EthBridgePoolWithoutCtx::QueryPool(QueryEthBridgePool( - mut query, + query, )) => { let client = client.unwrap_or_else(|| { - C::from_tendermint_address(&mut query.ledger_address) + C::from_tendermint_address(&query.ledger_address) }); client.wait_until_node_is_synced(&io).await?; bridge_pool::query_bridge_pool(&client, &io).await?; } EthBridgePoolWithoutCtx::QuerySigned( - QuerySignedBridgePool(mut query), + QuerySignedBridgePool(query), ) => { let client = client.unwrap_or_else(|| { - C::from_tendermint_address(&mut query.ledger_address) + C::from_tendermint_address(&query.ledger_address) }); client.wait_until_node_is_synced(&io).await?; bridge_pool::query_signed_bridge_pool(&client, &io).await?; } EthBridgePoolWithoutCtx::QueryRelays(QueryRelayProgress( - mut query, + query, )) => { let client = client.unwrap_or_else(|| { - C::from_tendermint_address(&mut query.ledger_address) + C::from_tendermint_address(&query.ledger_address) }); client.wait_until_node_is_synced(&io).await?; bridge_pool::query_relay_progress(&client, &io).await?; } }, cli::NamadaRelayer::ValidatorSet(sub) => match sub { - ValidatorSet::BridgeValidatorSet(BridgeValidatorSet( - mut args, - )) => { + ValidatorSet::BridgeValidatorSet(BridgeValidatorSet(args)) => { let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.query.ledger_address, - ) + C::from_tendermint_address(&args.ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk_ctxless(); @@ -109,12 +102,10 @@ impl CliApi { .await?; } ValidatorSet::GovernanceValidatorSet( - GovernanceValidatorSet(mut args), + GovernanceValidatorSet(args), ) => { let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.query.ledger_address, - ) + C::from_tendermint_address(&args.ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk_ctxless(); @@ -123,13 +114,9 @@ impl CliApi { ) .await?; } - ValidatorSet::ValidatorSetProof(ValidatorSetProof( - mut args, - )) => { + ValidatorSet::ValidatorSetProof(ValidatorSetProof(args)) => { let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.query.ledger_address, - ) + C::from_tendermint_address(&args.ledger_address) }); client.wait_until_node_is_synced(&io).await?; let args = args.to_sdk_ctxless(); @@ -139,12 +126,10 @@ impl CliApi { .await?; } ValidatorSet::ValidatorSetUpdateRelay( - ValidatorSetUpdateRelay(mut args), + ValidatorSetUpdateRelay(args), ) => { let client = client.unwrap_or_else(|| { - C::from_tendermint_address( - &mut args.query.ledger_address, - ) + C::from_tendermint_address(&args.ledger_address) }); client.wait_until_node_is_synced(&io).await?; let eth_client = diff --git a/crates/apps/src/lib/client/utils.rs b/crates/apps/src/lib/client/utils.rs index 7823e41457..a2d5115654 100644 --- a/crates/apps/src/lib/client/utils.rs +++ b/crates/apps/src/lib/client/utils.rs @@ -35,7 +35,6 @@ use crate::config::{ self, genesis, get_default_namada_folder, Config, TendermintMode, }; use crate::facade::tendermint::node::Id as TendermintNodeId; -use crate::facade::tendermint_config::net::Address as TendermintAddress; use crate::node::ledger::tendermint_node; use crate::wallet::{pre_genesis, CliWalletUtils}; use crate::wasm_loader; @@ -1174,19 +1173,6 @@ where task.join().unwrap() } -/// Replace the contents of `addr` with a dummy address. -#[inline] -pub fn take_config_address(addr: &mut TendermintAddress) -> TendermintAddress { - std::mem::replace( - addr, - TendermintAddress::Tcp { - peer_id: None, - host: String::new(), - port: 0, - }, - ) -} - #[cfg(not(test))] fn safe_exit(code: i32) -> ! { crate::cli::safe_exit(code) diff --git a/crates/apps/src/lib/config/genesis/transactions.rs b/crates/apps/src/lib/config/genesis/transactions.rs index 66398b98af..68a3040eb8 100644 --- a/crates/apps/src/lib/config/genesis/transactions.rs +++ b/crates/apps/src/lib/config/genesis/transactions.rs @@ -64,6 +64,8 @@ pub trait TxToSign { /// Return a dummy set of tx arguments to sign with the /// hardware wallet. fn get_tx_args(use_device: bool) -> TxArgs { + use std::str::FromStr; + TxArgs { dry_run: false, dry_run_wrapper: false, @@ -71,7 +73,10 @@ fn get_tx_args(use_device: bool) -> TxArgs { output_folder: None, force: false, broadcast_only: false, - ledger_address: (), + ledger_address: tendermint_config::net::Address::from_str( + "127.0.0.1:26657", + ) + .unwrap(), initialized_account_alias: None, wallet_alias_force: false, fee_amount: None, diff --git a/crates/apps/src/lib/node/ledger/shell/testing/client.rs b/crates/apps/src/lib/node/ledger/shell/testing/client.rs index 4347fcfaa2..6f34737f22 100644 --- a/crates/apps/src/lib/node/ledger/shell/testing/client.rs +++ b/crates/apps/src/lib/node/ledger/shell/testing/client.rs @@ -93,7 +93,7 @@ pub fn run( #[async_trait::async_trait(?Send)] impl<'a> CliClient for &'a MockNode { - fn from_tendermint_address(_: &mut TendermintAddress) -> Self { + fn from_tendermint_address(_: &TendermintAddress) -> Self { unreachable!("MockNode should always be instantiated at test start.") } diff --git a/crates/sdk/Cargo.toml b/crates/sdk/Cargo.toml index 8b3e683835..707dfa97de 100644 --- a/crates/sdk/Cargo.toml +++ b/crates/sdk/Cargo.toml @@ -99,6 +99,7 @@ serde.workspace = true serde_json.workspace = true sha2.workspace = true slip10_ed25519.workspace = true +tendermint-config.workspace = true tendermint-rpc = { workspace = true, optional = true } thiserror.workspace = true tiny-bip39.workspace = true diff --git a/crates/sdk/src/args.rs b/crates/sdk/src/args.rs index ed94a327b3..098a2d18d7 100644 --- a/crates/sdk/src/args.rs +++ b/crates/sdk/src/args.rs @@ -50,8 +50,13 @@ pub trait NamadaTypes: Clone + std::fmt::Debug { type NativeAddress: Clone + std::fmt::Debug; /// Represents a key pair type Keypair: Clone + std::fmt::Debug; - /// Represents the address of a Tendermint endpoint + /// Represents the address of a Tendermint endpoint (used in context-less + /// CLI commands where chain config isn't available) type TendermintAddress: Clone + std::fmt::Debug; + /// RPC address of a locally configured node + type ConfigRpcTendermintAddress: Clone + + std::fmt::Debug + + From; /// Represents the address of an Ethereum endpoint type EthereumAddress: Clone + std::fmt::Debug; /// Represents a viewing key @@ -89,12 +94,13 @@ impl NamadaTypes for SdkTypes { type Address = Address; type BalanceOwner = namada_core::types::masp::BalanceOwner; type BpConversionTable = HashMap; + type ConfigRpcTendermintAddress = tendermint_config::net::Address; type Data = Vec; type EthereumAddress = (); type Keypair = namada_core::types::key::common::SecretKey; type NativeAddress = Address; type PublicKey = namada_core::types::key::common::PublicKey; - type TendermintAddress = (); + type TendermintAddress = tendermint_config::net::Address; type TransferSource = namada_core::types::masp::TransferSource; type TransferTarget = namada_core::types::masp::TransferTarget; type ViewingKey = namada_core::types::masp::ExtendedViewingKey; @@ -103,6 +109,13 @@ impl NamadaTypes for SdkTypes { /// Common query arguments #[derive(Clone, Debug)] pub struct Query { + /// The address of the ledger node as host:port + pub ledger_address: C::ConfigRpcTendermintAddress, +} + +/// Common query arguments +#[derive(Clone, Debug)] +pub struct QueryWithoutCtx { /// The address of the ledger node as host:port pub ledger_address: C::TendermintAddress, } @@ -1908,7 +1921,7 @@ pub struct Tx { /// Do not wait for the transaction to be added to the blockchain pub broadcast_only: bool, /// The address of the ledger node as host:port - pub ledger_address: C::TendermintAddress, + pub ledger_address: C::ConfigRpcTendermintAddress, /// If any new account is initialized by the tx, use the given alias to /// save it in the wallet. pub initialized_account_alias: Option, @@ -1988,7 +2001,7 @@ pub trait TxBuilder: Sized { /// The address of the ledger node as host:port fn ledger_address(self, ledger_address: C::TendermintAddress) -> Self { self.tx(|x| Tx { - ledger_address, + ledger_address: C::ConfigRpcTendermintAddress::from(ledger_address), ..x }) } @@ -2359,8 +2372,8 @@ impl EthereumBridgePool { /// Bridge pool proof arguments. #[derive(Debug, Clone)] pub struct BridgePoolProof { - /// The query parameters. - pub query: Query, + /// The address of the ledger node as host:port + pub ledger_address: C::TendermintAddress, /// The keccak hashes of transfers to /// acquire a proof of. pub transfers: Vec, @@ -2376,8 +2389,8 @@ pub struct BridgePoolProof { /// Arguments to an Ethereum Bridge pool relay operation. #[derive(Debug, Clone)] pub struct RelayBridgePoolProof { - /// The query parameters. - pub query: Query, + /// The address of the ledger node as host:port + pub ledger_address: C::TendermintAddress, /// The hashes of the transfers to be relayed pub transfers: Vec, /// The Namada address for receiving fees for relaying @@ -2406,8 +2419,8 @@ pub struct RelayBridgePoolProof { /// Bridge validator set arguments. #[derive(Debug, Clone)] pub struct BridgeValidatorSet { - /// The query parameters. - pub query: Query, + /// The address of the ledger node as host:port + pub ledger_address: C::TendermintAddress, /// The epoch to query. pub epoch: Option, } @@ -2415,8 +2428,8 @@ pub struct BridgeValidatorSet { /// Governance validator set arguments. #[derive(Debug, Clone)] pub struct GovernanceValidatorSet { - /// The query parameters. - pub query: Query, + /// The address of the ledger node as host:port + pub ledger_address: C::TendermintAddress, /// The epoch to query. pub epoch: Option, } @@ -2424,8 +2437,8 @@ pub struct GovernanceValidatorSet { /// Validator set proof arguments. #[derive(Debug, Clone)] pub struct ValidatorSetProof { - /// The query parameters. - pub query: Query, + /// The address of the ledger node as host:port + pub ledger_address: C::TendermintAddress, /// The epoch to query. pub epoch: Option, } @@ -2436,8 +2449,8 @@ pub struct ValidatorSetUpdateRelay { /// Run in daemon mode, which will continuously /// perform validator set updates. pub daemon: bool, - /// The query parameters. - pub query: Query, + /// The address of the ledger node as host:port + pub ledger_address: C::TendermintAddress, /// The number of block confirmations on Ethereum. pub confirmations: u64, /// The Ethereum RPC endpoint. diff --git a/crates/sdk/src/lib.rs b/crates/sdk/src/lib.rs index 8a310ed3a2..3daa6b91a0 100644 --- a/crates/sdk/src/lib.rs +++ b/crates/sdk/src/lib.rs @@ -127,7 +127,10 @@ pub trait Namada: Sized + MaybeSync + MaybeSend { output_folder: None, force: false, broadcast_only: false, - ledger_address: (), + ledger_address: tendermint_config::net::Address::from_str( + "127.0.0.1:26657", + ) + .unwrap(), initialized_account_alias: None, wallet_alias_force: false, fee_amount: None, @@ -642,7 +645,10 @@ where output_folder: None, force: false, broadcast_only: false, - ledger_address: (), + ledger_address: tendermint_config::net::Address::from_str( + "127.0.0.1:26657", + ) + .unwrap(), initialized_account_alias: None, wallet_alias_force: false, fee_amount: None, diff --git a/wasm/Cargo.lock b/wasm/Cargo.lock index f900692a5d..5eed10bcfb 100644 --- a/wasm/Cargo.lock +++ b/wasm/Cargo.lock @@ -3626,6 +3626,7 @@ dependencies = [ "serde_json", "sha2 0.9.9", "slip10_ed25519", + "tendermint-config", "tendermint-rpc", "thiserror", "tiny-bip39", diff --git a/wasm_for_tests/wasm_source/Cargo.lock b/wasm_for_tests/wasm_source/Cargo.lock index 14ae08625a..9d3bf56d6b 100644 --- a/wasm_for_tests/wasm_source/Cargo.lock +++ b/wasm_for_tests/wasm_source/Cargo.lock @@ -3626,6 +3626,7 @@ dependencies = [ "serde_json", "sha2 0.9.9", "slip10_ed25519", + "tendermint-config", "tendermint-rpc", "thiserror", "tiny-bip39",