Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only allow tnam1... addresses in balances.toml #3645

Merged
merged 6 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading