push to share code
This commit is contained in:
@@ -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 }
|
||||
|
||||
@@ -11,12 +11,11 @@ use bip39;
|
||||
|
||||
pub async fn offline_sign(mnemonic: bip39::Mnemonic, to: AccountId) -> Vec<u8> {
|
||||
|
||||
// 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<u8> {
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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<u8>;
|
||||
|
||||
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::<Vec<_>>());
|
||||
println!("signed");
|
||||
}
|
||||
@@ -73,4 +65,6 @@ async fn main() {
|
||||
}
|
||||
None => {println!("no command specified - nothing to do")}
|
||||
}
|
||||
|
||||
println!(" ~(0.o)~ ")
|
||||
}
|
||||
Reference in New Issue
Block a user