Skip to content

Commit

Permalink
Merge pull request #3645 from anoma/tiago/implicit-addr-balances-toml…
Browse files Browse the repository at this point in the history
…-fix

Only allow `tnam1...` addresses in `balances.toml`
  • Loading branch information
mergify[bot] authored Aug 14, 2024
2 parents b44b022 + 5098900 commit 125af64
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 159 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Fix genesis bonds from implicit accounts. Now, only addresses
of the form `tnam1...` are supported in `balances.toml`.
([\#3645](https://github.com/anoma/namada/pull/3645))
8 changes: 4 additions & 4 deletions crates/apps_lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3187,7 +3187,7 @@ pub mod args {
use super::utils::*;
use super::{ArgGroup, ArgMatches};
use crate::client::utils::PRE_GENESIS_DIR;
use crate::config::genesis::GenesisAddress;
use crate::config::genesis::AddrOrPk;
use crate::config::{self, Action, ActionAtHeight};
use crate::facade::tendermint::Timeout;
use crate::facade::tendermint_rpc::Url;
Expand Down Expand Up @@ -3308,7 +3308,7 @@ pub mod args {
)
}),
);
pub const GENESIS_BOND_SOURCE: ArgOpt<GenesisAddress> = arg_opt("source");
pub const GENESIS_BOND_SOURCE: ArgOpt<AddrOrPk> = arg_opt("source");
pub const GENESIS_PATH: Arg<PathBuf> = arg("genesis-path");
pub const GENESIS_TIME: Arg<DateTimeUtc> = arg("genesis-time");
pub const GENESIS_VALIDATOR: ArgOpt<String> =
Expand Down Expand Up @@ -8003,7 +8003,7 @@ pub mod args {

#[derive(Clone, Debug)]
pub struct GenesisBond {
pub source: GenesisAddress,
pub source: AddrOrPk,
pub validator: EstablishedAddress,
pub bond_amount: token::DenominatedAmount,
pub output: PathBuf,
Expand All @@ -8014,7 +8014,7 @@ pub mod args {
let validator = GENESIS_VALIDATOR_ADDRESS.parse(matches);
let source =
GENESIS_BOND_SOURCE.parse(matches).unwrap_or_else(|| {
GenesisAddress::EstablishedAddress(validator.clone())
AddrOrPk::Address(Address::Established(validator.clone()))
});
let bond_amount = AMOUNT.parse(matches);
let output = PATH.parse(matches);
Expand Down
2 changes: 1 addition & 1 deletion crates/apps_lib/src/cli/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ impl CliApi {
utils::init_network(global_args, args);
}
ClientUtils::GenesisBond(GenesisBond(args)) => {
utils::genesis_bond(args)
utils::genesis_bond(global_args, args)
}
ClientUtils::DeriveGenesisAddresses(
DeriveGenesisAddresses(args),
Expand Down
31 changes: 30 additions & 1 deletion crates/apps_lib/src/client/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use flate2::read::GzDecoder;
use flate2::write::GzEncoder;
use flate2::Compression;
use itertools::Either;
use namada_sdk::address::Address;
use namada_sdk::args::DeviceTransport;
use namada_sdk::chain::ChainId;
use namada_sdk::dec::Dec;
Expand All @@ -29,6 +30,7 @@ use crate::config::genesis::chain::DeriveEstablishedAddress;
use crate::config::genesis::transactions::{
sign_delegation_bond_tx, sign_validator_account_tx, UnsignedTransactions,
};
use crate::config::genesis::{AddrOrPk, GenesisAddress};
use crate::config::global::GlobalConfig;
use crate::config::{self, genesis, get_default_namada_folder, TendermintMode};
use crate::facade::tendermint::node::Id as TendermintNodeId;
Expand Down Expand Up @@ -602,13 +604,40 @@ pub fn init_genesis_established_account(
}

/// Bond to a validator at pre-genesis.
pub fn genesis_bond(args: args::GenesisBond) {
pub fn genesis_bond(global_args: args::Global, args: args::GenesisBond) {
let args::GenesisBond {
source,
validator,
bond_amount,
output: toml_path,
} = args;

let (wallet, _wallet_file) =
load_pre_genesis_wallet_or_exit(&global_args.base_dir);
let source = match source {
AddrOrPk::Address(addr) => match &addr {
Address::Established(established) => {
GenesisAddress::EstablishedAddress(established.clone())
}
Address::Implicit(internal) => {
match wallet.find_public_key_from_implicit_addr(internal) {
Ok(pk) => GenesisAddress::PublicKey(StringEncoded::new(pk)),
Err(err) => {
eprintln!(
"Couldn't find the PK associated with the given \
implicit address {addr} in the wallet: {err}"
);
safe_exit(1)
}
}
}
Address::Internal(_) => {
eprintln!("Unexpected internal address as bond source");
safe_exit(1);
}
},
AddrOrPk::PublicKey(pk) => GenesisAddress::PublicKey(pk),
};
let txs = genesis::transactions::init_bond(source, validator, bond_amount);

let toml_path_str = toml_path.to_string_lossy();
Expand Down
Loading

0 comments on commit 125af64

Please sign in to comment.