diff --git a/demos/rust-cosmos-broadcaster-client/README.md b/demos/rust-cosmos-broadcaster-client/README.md index dff78945d5..8429ffe82a 100644 --- a/demos/rust-cosmos-broadcaster-client/README.md +++ b/demos/rust-cosmos-broadcaster-client/README.md @@ -1,3 +1,3 @@ cosmos broadcaster client code - sign txs offline and send thru the mixnet! -heavily pulling from the offline_signing.rs example file in the validator client code (s/o Jon for writing top examples) \ No newline at end of file +heavily pulling from the offline_signing.rs example file in the validator client code (s/o Jon for writing top examples) & the nym-cli tool (:hattip: mr vez) \ No newline at end of file diff --git a/demos/rust-cosmos-broadcaster-client/src/commands/commands.rs b/demos/rust-cosmos-broadcaster-client/src/commands/commands.rs index 110e57115b..78f1826b75 100644 --- a/demos/rust-cosmos-broadcaster-client/src/commands/commands.rs +++ b/demos/rust-cosmos-broadcaster-client/src/commands/commands.rs @@ -9,18 +9,15 @@ use cosmrs::tx::Msg; use cosmrs::{tx, AccountId, Coin, Denom}; use bip39; -pub async fn offline_sign(mnemonic: &String, to: &String) -> Vec { +pub async fn offline_sign(mnemonic: bip39::Mnemonic, to: AccountId) -> Vec { - // TODO load most of this from config file. in V2 take chain-id and tx-type as well + // TODO take coin amount from function args, + load most of network vars from config file. in V2 take chain-id and tx-type as well - for V1 see nym-cli and how it loads from get_network_details() in main.rsL88 let prefix = "n"; let denom: Denom = "unym".parse().unwrap(); - let signer_mnemonic: bip39::Mnemonic = mnemonic.parse().unwrap(); - // let signer_mnemonic: bip39::Mnemonic = "".parse().unwrap(); let validator = "https://qwerty-validator.qa.nymte.ch"; - let to_address: AccountId = to.parse().unwrap(); - // let to_address: AccountId = "n19kdst4srf76xgwe55jg32mpcpcyf6aqgp6qrdk".parse().unwrap(); - let signer = DirectSecp256k1HdWallet::from_mnemonic(prefix, signer_mnemonic); + + let signer = DirectSecp256k1HdWallet::from_mnemonic(prefix, mnemonic); let signer_address = signer.try_derive_accounts().unwrap()[0].address().clone(); // local 'client' ONLY signing messages @@ -43,7 +40,7 @@ pub async fn offline_sign(mnemonic: &String, to: &String) -> Vec { let send_msg = MsgSend { from_address: signer_address.clone(), - to_address: to_address.clone(), + to_address: to.clone(), amount, } .to_any() diff --git a/demos/rust-cosmos-broadcaster-client/src/main.rs b/demos/rust-cosmos-broadcaster-client/src/main.rs index 9f768bef21..6d64d6119b 100644 --- a/demos/rust-cosmos-broadcaster-client/src/main.rs +++ b/demos/rust-cosmos-broadcaster-client/src/main.rs @@ -9,12 +9,26 @@ use clap::{CommandFactory, Parser, Subcommand, Args}; // use cosmrs::tx::Msg; // use cosmrs::{tx, AccountId, Coin, Denom}; // use bip39; +use nym_validator_client::nyxd::AccountId; mod commands; #[derive(Debug, Parser)] #[clap(name = "nym cosmos tx signer ")] #[clap(about = "binary with which users can perform offline signing and transmission of signed tx to broadcaster via the mixnet ")] struct Cli { + // TODO make this import from file & remove from functions + // #[clap(long, global = true)] + // #[clap( + // help = "Provide the mnemonic for your account. You can also provide this is an env var called MNEMONIC." + // )] + // mnemonic: Option, + + #[clap(short, long, global = true)] + #[clap( + help = "Overrides configuration as a file of environment variables." + )] + config_env_file: Option, + #[clap(subcommand)] command: Option, } @@ -29,10 +43,10 @@ enum Commands { #[derive(Debug, Clone, Args)] struct OfflineSignTx { - /// mnemonic of signing + sending account (you!) - mnemonic: String, // TODO input validation.. look @ file loading first + /// mnemonic of signing + sending account (you!) - this will be removed and replaced with file + mnemonic: bip39::Mnemonic, /// recipient nyx chain address - to: String // TODO switch to proper cosmos address type + to: AccountId } #[derive(Debug, Args)] @@ -48,7 +62,7 @@ async fn main() { match &cli.command { Some(Commands::OfflineSignTx(OfflineSignTx { mnemonic, to } )) => { - let tx_bytes = commands::commands::offline_sign(mnemonic, to).await; + let tx_bytes = commands::commands::offline_sign(mnemonic.clone(), to.clone()).await; // TODO save as global var to pass to sendtx() println!("{:?}", tx_bytes.iter().collect::>()); @@ -57,6 +71,6 @@ async fn main() { Some(Commands::SendTx(sp_address)) => { todo!(); } - None => {} + None => {println!("no command specified - nothing to do")} } } \ No newline at end of file