type changes

This commit is contained in:
mfahampshire
2023-07-03 22:45:15 +00:00
parent b03d8f57d3
commit a86ed7afb8
3 changed files with 25 additions and 14 deletions
@@ -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)
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)
@@ -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<u8> {
pub async fn offline_sign(mnemonic: bip39::Mnemonic, to: AccountId) -> Vec<u8> {
// 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 = "<SOME 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<u8> {
let send_msg = MsgSend {
from_address: signer_address.clone(),
to_address: to_address.clone(),
to_address: to.clone(),
amount,
}
.to_any()
@@ -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<bip39::Mnemonic>,
#[clap(short, long, global = true)]
#[clap(
help = "Overrides configuration as a file of environment variables."
)]
config_env_file: Option<std::path::PathBuf>,
#[clap(subcommand)]
command: Option<Commands>,
}
@@ -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::<Vec<_>>());
@@ -57,6 +71,6 @@ async fn main() {
Some(Commands::SendTx(sp_address)) => {
todo!();
}
None => {}
None => {println!("no command specified - nothing to do")}
}
}