first pass done of client
This commit is contained in:
@@ -9,7 +9,9 @@ edition = "2021"
|
||||
[dependencies]
|
||||
clap = { version = "4.0", features = ["derive"] }
|
||||
nym-bin-common = { path = "../../common/bin-common"}
|
||||
nym-sphinx-addressing = { path = "../../common/nymsphinx/addressing" }
|
||||
nym-sdk = { path = "../../sdk/rust/nym-sdk" }
|
||||
nym-crypto = { path = "../../common/crypto" }
|
||||
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" }
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use cosmrs::bip32::secp256k1::elliptic_curve::generic_array::sequence;
|
||||
use nym_sphinx_addressing::clients::Recipient;
|
||||
use nym_validator_client::nyxd::CosmWasmClient;
|
||||
use nym_validator_client::signing::direct_wallet::DirectSecp256k1HdWallet;
|
||||
use nym_validator_client::signing::tx_signer::TxSigner;
|
||||
@@ -10,6 +11,7 @@ use cosmrs::{tx, AccountId, Coin, Denom};
|
||||
use bip39;
|
||||
use bs58;
|
||||
use nym_sdk::mixnet;
|
||||
// use nymsphinx::addressing::Recipient;
|
||||
|
||||
pub async fn offline_sign(mnemonic: bip39::Mnemonic, to: AccountId) -> String {
|
||||
|
||||
@@ -66,36 +68,34 @@ pub async fn offline_sign(mnemonic: bip39::Mnemonic, to: AccountId) -> String {
|
||||
|
||||
}
|
||||
|
||||
pub async fn send_tx(base58_tx: String, sp_address: String) -> Option<Vec<mixnet::ReconstructedMessage>> /*String*/ {
|
||||
// 1. decode base58 -> vec<u8>
|
||||
println!("this is where we decode the base58 string");
|
||||
|
||||
// 2. get nym client address
|
||||
let client = mixnet::MixnetClientBuilder::new_ephemeral()
|
||||
pub async fn send_tx(base58_tx: String, sp_address: Recipient) -> Option<Vec<mixnet::ReconstructedMessage>> /*String*/ {
|
||||
// TODO move to its own function and pass created client as arg
|
||||
let config_dir = std::path::PathBuf::from("/tmp/mixnet-client");
|
||||
let storage_paths = mixnet::StoragePaths::new_from_dir(&config_dir).unwrap();
|
||||
let client = mixnet::MixnetClientBuilder::new_with_default_storage(storage_paths)
|
||||
.await
|
||||
.unwrap()
|
||||
.build()
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let mut client = client.connect_to_mixnet().await.unwrap();
|
||||
|
||||
let our_address = client.nym_address();
|
||||
println!("Our client nym address is: {our_address}");
|
||||
|
||||
// 3. send message w sdk to broadcaster who will do:
|
||||
// send message w sdk to broadcaster who will do:
|
||||
/*
|
||||
// broadcast the tx
|
||||
let res = rpc::Client::broadcast_tx_commit(&broadcaster, tx_bytes.into())
|
||||
.await
|
||||
.unwrap();
|
||||
*/
|
||||
// client.send_str(sp_address, signedtx);
|
||||
// println!("Waiting for message");
|
||||
client.send_str(sp_address, &base58_tx).await; // send as base58 encoded and it can be decoded by the SP
|
||||
println!("\nWaiting for reply\n");
|
||||
let res = client.wait_for_messages().await;
|
||||
|
||||
// disconnect client
|
||||
// return the res to return to main thread
|
||||
client.disconnect().await;
|
||||
// String::from("your tx hash")
|
||||
res
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use clap::{CommandFactory, Parser, Subcommand, Args};
|
||||
use cosmrs::bip32::PublicKey;
|
||||
use nym_sdk::mixnet::Recipient;
|
||||
use nym_validator_client::nyxd::AccountId;
|
||||
// use nym_cli_commands::context::{get_network_details, ClientArgs};
|
||||
// use nym_crypto::asymmetric::identity;
|
||||
use nym_crypto::asymmetric::identity;
|
||||
mod commands;
|
||||
use nym_bin_common::logging::setup_logging;
|
||||
use nym_sphinx_addressing;
|
||||
|
||||
// use common::nymsphinx::addressing;
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
#[clap(name = "nym cosmos tx signer ")]
|
||||
@@ -16,13 +23,8 @@ struct Cli {
|
||||
// )]
|
||||
// mnemonic: Option<bip39::Mnemonic>,
|
||||
|
||||
// TODO add for diff network
|
||||
// #[clap(short, long, global = true)]
|
||||
// #[clap(
|
||||
// help = "Overrides configuration as a file of environment variables."
|
||||
// )]
|
||||
// config_env_file: Option<std::path::PathBuf>,
|
||||
|
||||
// TODO add SP address
|
||||
|
||||
#[clap(subcommand)]
|
||||
command: Option<Commands>,
|
||||
}
|
||||
@@ -48,21 +50,23 @@ struct SendTx {
|
||||
/// the base58 encoded signed payload created in OfflineSign()
|
||||
base58_payload: String,
|
||||
/// the nym address of the broadcaster service provider
|
||||
sp_address: String
|
||||
sp_address: Recipient
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
setup_logging();
|
||||
let cli = Cli::parse();
|
||||
let sp_address = "4roCqqdh1mG76gYT2das1wNBER3e5AzxC5dsA4zoWoLh.2iRzCRhzVMod7Ar5MnGt3X3zJGR7c4NxvK8cXCnxMYe3@2xU4CBE6QiiYt6EyBXSALwxkNvM7gqJfjHXaMkjiFmYW";
|
||||
|
||||
// TODO take from args
|
||||
let sp_address = Recipient::try_from_base58_string("6e5KeP3Ks6iA3832K2MvCvQJb9zF3HMHwY8XjLhwAGGt.ZCH8YTky6GkApmra3EGbfgQk2VwdPaRH8R1wUfAnv3Q@BNjYZPxzcJwczXHHgBxCAyVJKxN6LPteDRrKapxWmexv").unwrap();
|
||||
|
||||
match &cli.command {
|
||||
Some(Commands::OfflineSignTx(OfflineSignTx { mnemonic, to } )) => {
|
||||
let base58_tx_bytes = commands::commands::offline_sign(mnemonic.clone(), to.clone()).await;
|
||||
|
||||
println!("signed tx payload: \n\n{}\n\n", &base58_tx_bytes);
|
||||
println!("do you wish to send the signed tx? y/n");
|
||||
println!("base58 encoded signed tx payload: \n\n{}\n\n", &base58_tx_bytes);
|
||||
println!("do you wish to send the tx? y/n");
|
||||
|
||||
let mut input = String::new();
|
||||
let stdin = std::io::stdin();
|
||||
@@ -70,7 +74,7 @@ async fn main() {
|
||||
|
||||
if input.chars().next().unwrap() == 'y' { // TODO add proper parsing for getting y/n
|
||||
println!("\nsending tx thru the mixnet to broadcaster service");
|
||||
let tx_hash = commands::commands::send_tx(base58_tx_bytes, sp_address.to_string()).await;
|
||||
let tx_hash = commands::commands::send_tx(base58_tx_bytes, sp_address).await;
|
||||
println!("the response from the broadcaster: {:#?}", tx_hash);
|
||||
} else if input.chars().next().unwrap() == 'n' {
|
||||
println!("\nok, you can send the signed tx at a later date by passing the base58 string above as the argument for send-tx")
|
||||
@@ -79,7 +83,8 @@ async fn main() {
|
||||
}
|
||||
}
|
||||
Some(Commands::SendTx(SendTx { base58_payload, sp_address} )) => {
|
||||
todo!();
|
||||
let tx_hash = commands::commands::send_tx(base58_payload.clone(), sp_address.clone()).await;
|
||||
println!("the response from the broadcaster: {:#?}", tx_hash);
|
||||
}
|
||||
None => {println!("no command specified - nothing to do")}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user