push to share
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use std::time::Duration;
|
||||
use nym_cli_commands::validator::mixnet::Mixnet;
|
||||
use nym_crypto::generic_array::sequence;
|
||||
use nym_sphinx_addressing::clients::Recipient;
|
||||
@@ -5,16 +6,19 @@ 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 nym_validator_client::nyxd::cosmwasm_client::types;
|
||||
use cosmrs::bank::MsgSend;
|
||||
use cosmrs::rpc::{HttpClient, Id};
|
||||
use cosmrs::tx::Msg;
|
||||
use cosmrs::{tx, AccountId, Coin, Denom};
|
||||
use bip39;
|
||||
use bs58;
|
||||
use nym_sdk::mixnet::{self, MixnetClient};
|
||||
use nym_sdk::mixnet::{self, MixnetClient, ReconstructedMessage};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use crate::commands::reqres::SequenceRequest;
|
||||
|
||||
use super::reqres::SequenceRequestResponse;
|
||||
|
||||
pub async fn offline_sign(mnemonic: bip39::Mnemonic, to: AccountId, client: &mut MixnetClient , sp_address: Recipient) -> String {
|
||||
|
||||
// TODO take coin amount from function args, + load network vars from config file.
|
||||
@@ -31,17 +35,23 @@ pub async fn offline_sign(mnemonic: bip39::Mnemonic, to: AccountId, client: &mut
|
||||
let message = SequenceRequest{
|
||||
validator,
|
||||
signer_address,
|
||||
// request_type: String::from("sequence_request")
|
||||
};
|
||||
|
||||
// send req to client
|
||||
client.send_str(sp_address, &serde_json::to_string(&message).unwrap()).await;
|
||||
|
||||
let res = client.wait_for_messages().await;
|
||||
for i in res.unwrap().iter() {
|
||||
println!("{:#?}", i.message);
|
||||
}
|
||||
// parse json of res to get signer_data and chain_id, store in SeqResData struct
|
||||
|
||||
todo!()
|
||||
// parse json of res to get signer_data and chain_id, store in SeqResData struct to create and sign tx
|
||||
|
||||
for r in res.unwrap().iter() {
|
||||
let message = String::from_utf8(r.message.clone());
|
||||
let p = message.unwrap();
|
||||
let sequence: SequenceRequestResponse = serde_json::from_str(&p).unwrap();
|
||||
};
|
||||
|
||||
let placeholder = String::from("placeholder reponse when working on offline_sign()");
|
||||
placeholder
|
||||
|
||||
|
||||
/*
|
||||
// use the response to create SignerData instance
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use cosmrs::rpc::{Id};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use cosmrs::{AccountId};
|
||||
use cosmrs::{tx, AccountId, Coin, Denom, tendermint};
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
pub struct SequenceRequest {
|
||||
@@ -9,11 +9,15 @@ pub struct SequenceRequest {
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
pub struct SequenceResponse {
|
||||
pub sequence_response: u8,
|
||||
pub chain_id: Id
|
||||
// pub struct SequenceResponse {
|
||||
// pub sequence_response: u8,
|
||||
// pub chain_id: Id
|
||||
// }
|
||||
pub struct SequenceRequestResponse {
|
||||
pub account_number: u64,
|
||||
pub sequence: u64,
|
||||
pub chain_id: tendermint::chain::Id
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
pub struct BroadcastRequest {
|
||||
pub base58_tx_bytes: String
|
||||
@@ -34,7 +38,7 @@ pub enum RequestTypes {
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum ResponseTypes {
|
||||
Sequence(SequenceResponse),
|
||||
Sequence(SequenceRequestResponse),
|
||||
Broadcast(BroadcastResponse)
|
||||
}
|
||||
|
||||
|
||||
@@ -52,8 +52,7 @@ async fn main() {
|
||||
let cli = Cli::parse();
|
||||
// TODO look @ arg env setup from NR main.rs
|
||||
// TODO take from args
|
||||
let sp_address = Recipient::try_from_base58_string("58t3wcC14TYvhbq8ATpoQmf9jtJ44pYYU1oj9KKYokQu.BAR7nDgfJxSpatuXB97gqa1rvhfeTvHgVmPkJrvU8pz6@DfNMqQRy6pPkU8Z5rBsxRwzDUzAMXHPFwMhjF16ScZqn").unwrap();
|
||||
|
||||
let sp_address = Recipient::try_from_base58_string("HfbesQm2pRYCN4BAdYXhkqXBbV1Pp929mtKsESVeWXh8.8AgoUPUQbXNBCPaqAaWd3vnxhc9484qwfgrrQwBngQk2@Ck8zpXTSXMtS9YZ7k7a5BiaoLZfffWuqGWLndujh4Lw4").unwrap();
|
||||
let config_dir = PathBuf::from("/tmp/cosmos-broadcaster-mixnet-client-2");
|
||||
let storage_paths = StoragePaths::new_from_dir(&config_dir).unwrap();
|
||||
let client = MixnetClientBuilder::new_with_default_storage(storage_paths)
|
||||
|
||||
@@ -8,7 +8,7 @@ use nym_validator_client::nyxd::CosmWasmClient;
|
||||
// use cosmrs::bank::MsgSend;
|
||||
use cosmrs::rpc::{HttpClient, Id, Client};
|
||||
// use cosmrs::tx::Msg;
|
||||
use cosmrs::{tx, AccountId, Coin, Denom};
|
||||
use cosmrs::{tx, AccountId, Coin, Denom, tendermint};
|
||||
// use bip39;
|
||||
use bs58;
|
||||
use nym_sdk::mixnet::{self, MixnetClient};
|
||||
@@ -23,11 +23,9 @@ pub async fn get_sequence(validator: String, signer_address: AccountId) -> Seque
|
||||
let broadcaster = HttpClient::new(validator.as_str()).unwrap();
|
||||
|
||||
// get signer information
|
||||
// TODO look @ how you can return SequenceResponse type from cosmwasm
|
||||
let sequence = broadcaster.get_sequence(&signer_address).await.unwrap();
|
||||
let chain_id = broadcaster.get_chain_id().await.unwrap();
|
||||
// todo!()
|
||||
let res = SequenceRequestResponse { sequence: 9, chain_id: cosmrs::rpc::Id::Str(String::from("chain_id_placeholder")) };
|
||||
let chain_id: tendermint::chain::Id = broadcaster.get_chain_id().await.unwrap();
|
||||
let res = SequenceRequestResponse { account_number: sequence.account_number, sequence: sequence.sequence, chain_id };
|
||||
res
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use cosmrs::rpc::{HttpClient, Id};
|
||||
// use cosmrs::rpc::{HttpClient, Id};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use cosmrs::{tx, AccountId, Coin, Denom};
|
||||
use cosmrs::{tx, AccountId, Coin, Denom, tendermint};
|
||||
use nym_validator_client::nyxd::cosmwasm_client::types::SequenceResponse;
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
@@ -11,8 +11,9 @@ pub struct SequenceRequest {
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
pub struct SequenceRequestResponse {
|
||||
pub sequence: u8, // fix this - should be cosmwasmclient::SequenceResponse
|
||||
pub chain_id: Id
|
||||
pub account_number: u64,
|
||||
pub sequence: u64,
|
||||
pub chain_id: tendermint::chain::Id
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
use nym_sdk::mixnet::{Recipient, MixnetClient, StoragePaths, MixnetClientBuilder};
|
||||
use nym_validator_client::nyxd::AccountId;
|
||||
use nym_bin_common::logging::setup_logging;
|
||||
use std::path::PathBuf;
|
||||
use std::{path::PathBuf, time::Duration};
|
||||
mod commands;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use cosmrs::{rpc::{Id}};
|
||||
use nym_sphinx_anonymous_replies::{self, requests::RepliableMessage};
|
||||
use nym_sphinx_anonymous_replies::{self, requests::{RepliableMessage, AnonymousSenderTag}};
|
||||
use crate::commands::reqres;
|
||||
// pull in ::reply::{MixnetAddress, MixnetMessage}
|
||||
use nym_validator_client::nyxd::cosmwasm_client::types;
|
||||
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
setup_logging();
|
||||
// setup_logging();
|
||||
// TODO put client creation in own fn
|
||||
let config_dir = PathBuf::from("/tmp/cosmos-broadcaster-mixnet-server-2");
|
||||
let storage_paths = StoragePaths::new_from_dir(&config_dir).unwrap();
|
||||
@@ -31,8 +33,8 @@ async fn main() {
|
||||
* add threads!
|
||||
*/
|
||||
println!("\nWaiting for message");
|
||||
if let Some(received) = client.wait_for_messages().await {
|
||||
for r in &received {
|
||||
let received = client.wait_for_messages().await;
|
||||
for r in received.unwrap().iter() {
|
||||
let s = String::from_utf8(r.message.clone());
|
||||
if s.is_ok() {
|
||||
let p = s.unwrap();
|
||||
@@ -43,17 +45,18 @@ async fn main() {
|
||||
println!("\nincoming sequence request details:\nvalidator: {},\nsigner address: {}\n", request.validator, request.signer_address);
|
||||
let sequence: reqres::SequenceRequestResponse = commands::commands::get_sequence(request.validator, request.signer_address).await;
|
||||
print!("debug print -------- {:#?}", sequence);
|
||||
|
||||
// send back to sender via SURBS...
|
||||
// TODO how to properly parse to AnonymousSenderTag?
|
||||
// TODO make a rust sdk example of replying via SURBs
|
||||
println!("debug print SENDER TAG --------- {:#?}", r.sender_tag);
|
||||
|
||||
if Some(r.sender_tag).is_some() {
|
||||
// TODO construct reply
|
||||
let return_recipient = MixnetAddress::from(r.sender_tag);
|
||||
// send back thru mixnet
|
||||
client.send_str(return_recipient, &serde_json::to_string(&sequence).unwrap()).await;
|
||||
println!("debug print ---- sending reply ");
|
||||
let return_recipient: AnonymousSenderTag = r.sender_tag.unwrap();
|
||||
println!("{}", &return_recipient);
|
||||
|
||||
// todo actually return sequence serialised as json
|
||||
client.send_str_reply(return_recipient, "quicktest an0n reply").await;
|
||||
println!("sent reply - sleeping for 20");
|
||||
tokio::time::sleep(Duration::from_secs(20)).await;
|
||||
println!("stopped sleep");
|
||||
|
||||
} else {
|
||||
// // TODO replace with actual error type to return
|
||||
println!("no surbs cannot reply an0n")
|
||||
@@ -64,8 +67,7 @@ async fn main() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
client.disconnect().await;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user