From 4a012e17c3acebb0acd17cd0a7f20ebe0f9a6890 Mon Sep 17 00:00:00 2001 From: mfahampshire Date: Tue, 4 Jul 2023 15:40:40 +0200 Subject: [PATCH] push to share code --- .../rust-cosmos-broadcaster-client/Cargo.toml | 1 + .../src/commands/commands.rs | 46 +++++++++---------- .../src/main.rs | 20 +++----- 3 files changed, 30 insertions(+), 37 deletions(-) diff --git a/demos/rust-cosmos-broadcaster-client/Cargo.toml b/demos/rust-cosmos-broadcaster-client/Cargo.toml index b1c4c341b2..1e87d83cad 100644 --- a/demos/rust-cosmos-broadcaster-client/Cargo.toml +++ b/demos/rust-cosmos-broadcaster-client/Cargo.toml @@ -8,6 +8,7 @@ edition = "2021" [dependencies] clap = { version = "4.0", features = ["derive"] } +nym-cli-commands = { path = "../../common/commands" } nym-validator-client = { path = "../../common/client-libs/validator-client", features = ["nyxd-client"] } nym-network-defaults = { path = "../../common/network-defaults" } async-trait = { workspace = true, optional = true } diff --git a/demos/rust-cosmos-broadcaster-client/src/commands/commands.rs b/demos/rust-cosmos-broadcaster-client/src/commands/commands.rs index be04e5c6a2..af33555eae 100644 --- a/demos/rust-cosmos-broadcaster-client/src/commands/commands.rs +++ b/demos/rust-cosmos-broadcaster-client/src/commands/commands.rs @@ -11,12 +11,11 @@ use bip39; pub async fn offline_sign(mnemonic: bip39::Mnemonic, to: AccountId) -> Vec { - // 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 + // TODO take coin amount from function args, + load network vars from config file. let prefix = "n"; let denom: Denom = "unym".parse().unwrap(); let validator = "https://qwerty-validator.qa.nymte.ch"; - let signer = DirectSecp256k1HdWallet::from_mnemonic(prefix, mnemonic); let signer_address = signer.try_derive_accounts().unwrap()[0].address().clone(); @@ -38,32 +37,31 @@ pub async fn offline_sign(mnemonic: bip39::Mnemonic, to: AccountId) -> Vec { amount: 12345u32.into(), }]; - let send_msg = MsgSend { - from_address: signer_address.clone(), - to_address: to.clone(), - amount, - } - .to_any() - .unwrap(); + let send_msg = MsgSend { + from_address: signer_address.clone(), + to_address: to.clone(), + amount, + } + .to_any() + .unwrap(); - let memo = "example memo"; - let fee = tx::Fee::from_amount_and_gas( - Coin { - denom, - amount: 2500u32.into(), - }, - 100000, - ); + let memo = "example memo"; + let fee = tx::Fee::from_amount_and_gas( + Coin { + denom, + amount: 2500u32.into(), + }, + 100000, + ); - let tx_raw = tx_signer - .sign_direct(&signer_address, vec![send_msg], fee, memo, signer_data) - .unwrap(); + let tx_raw = tx_signer + .sign_direct(&signer_address, vec![send_msg], fee, memo, signer_data) + .unwrap(); - // TODO return this from function - let tx_bytes = tx_raw.to_bytes().unwrap(); - - tx_bytes + // TODO return this from function + let tx_bytes = tx_raw.to_bytes().unwrap(); + tx_bytes } diff --git a/demos/rust-cosmos-broadcaster-client/src/main.rs b/demos/rust-cosmos-broadcaster-client/src/main.rs index 6d64d6119b..551f09c7c4 100644 --- a/demos/rust-cosmos-broadcaster-client/src/main.rs +++ b/demos/rust-cosmos-broadcaster-client/src/main.rs @@ -1,22 +1,13 @@ use clap::{CommandFactory, Parser, Subcommand, Args}; -// use cosmrs::bip32::secp256k1::elliptic_curve::generic_array::sequence; -// use nym_validator_client::nyxd::CosmWasmClient; -// use nym_validator_client::signing::direct_wallet::DirectSecp256k1HdWallet; -// use nym_validator_client::signing::tx_signer::TxSigner; -// use nym_validator_client::signing::SignerData; -// use cosmrs::bank::MsgSend; -// use cosmrs::rpc::{self, HttpClient}; -// use cosmrs::tx::Msg; -// use cosmrs::{tx, AccountId, Coin, Denom}; -// use bip39; use nym_validator_client::nyxd::AccountId; +// use nym_cli_commands::context::{get_network_details, ClientArgs}; 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 + // TODO make this import from file & remove from cli args // #[clap(long, global = true)] // #[clap( // help = "Provide the mnemonic for your account. You can also provide this is an env var called MNEMONIC." @@ -57,14 +48,15 @@ struct SendTx { #[tokio::main] async fn main() { + + let tx_bytes: Vec; let cli = Cli::parse(); match &cli.command { Some(Commands::OfflineSignTx(OfflineSignTx { mnemonic, to } )) => { - let tx_bytes = commands::commands::offline_sign(mnemonic.clone(), to.clone()).await; + 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::>()); println!("signed"); } @@ -73,4 +65,6 @@ async fn main() { } None => {println!("no command specified - nothing to do")} } + + println!(" ~(0.o)~ ") } \ No newline at end of file