a274edffba
* Calculating gas fees * Ability to set custom fees * Added extra test * Removed commented code * Moved all msg types to common contract crate * Temporarily disabling get_tx method * Finishing up nymd client API * Comment fix * Remaining fee values * Some cleanup * Removed needless borrow * Fixed imports in contract tests * Moved error types around * New ValidatorClient * Experiment with new type of defaults * Removed dead module * Dealt with unwrap * Migrated mixnode to use new validator client * Migrated gateway to use new validator client * Mixnode and gateway adjustments * More exported defaults * Clients using new validator client * Fixed mixnode upgrade * Moved default values to a new crate * Changed behaviour of validator client features * Migrated basic functions of validator api * Updated config + fixed startup * Fixed wasm client build * Integration with the explorer api * Removed tokio dev dependency * Needless borrow * Fixex wasm client build * Fixed tauri client build * Needless borrows * Fixed client upgrade print * Removed redundant comments * Made note on aggregated verification key into a doc comment * Removed mixnet contract references from verloc * Modified default validators structure * Reformatted validator-api Cargo.toml file * Removed commented code * Made the doc comment example a no-run * Fixed a upgrade print... again * Adjusted the doc example * Removed unused import
81 lines
2.7 KiB
Rust
81 lines
2.7 KiB
Rust
// Copyright 2021 - Nym Technologies SA <contact@nymtech.net>
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
use crate::config::Config;
|
|
use config::defaults::DEFAULT_VALIDATOR_API_PORT;
|
|
use mixnet_contract::{GatewayBond, MixNodeBond};
|
|
use std::sync::Arc;
|
|
use tokio::sync::RwLock;
|
|
use validator_client::nymd::{CosmWasmClient, QueryNymdClient, SigningNymdClient};
|
|
use validator_client::ValidatorClientError;
|
|
|
|
#[derive(Clone)]
|
|
pub(crate) struct Client<C>(Arc<RwLock<validator_client::Client<C>>>);
|
|
|
|
impl Client<QueryNymdClient> {
|
|
pub(crate) fn new_query(config: &Config) -> Self {
|
|
// the api address is irrelevant here as **WE ARE THE API**
|
|
let api_url = format!("http://localhost:{}", DEFAULT_VALIDATOR_API_PORT)
|
|
.parse()
|
|
.unwrap();
|
|
let nymd_url = config.get_nymd_validator_url();
|
|
|
|
let mixnet_contract = config
|
|
.get_mixnet_contract_address()
|
|
.parse()
|
|
.expect("the mixnet contract address is invalid!");
|
|
|
|
let client_config = validator_client::Config::new(nymd_url, api_url, Some(mixnet_contract));
|
|
let inner =
|
|
validator_client::Client::new_query(client_config).expect("Failed to connect to nymd!");
|
|
|
|
Client(Arc::new(RwLock::new(inner)))
|
|
}
|
|
}
|
|
|
|
impl Client<SigningNymdClient> {
|
|
pub(crate) fn new_signing(config: &Config) -> Self {
|
|
// the api address is irrelevant here as **WE ARE THE API**
|
|
let api_url = format!("http://localhost:{}", DEFAULT_VALIDATOR_API_PORT)
|
|
.parse()
|
|
.unwrap();
|
|
let nymd_url = config.get_nymd_validator_url();
|
|
|
|
let mixnet_contract = config
|
|
.get_mixnet_contract_address()
|
|
.parse()
|
|
.expect("the mixnet contract address is invalid!");
|
|
let mnemonic = config
|
|
.get_mnemonic()
|
|
.parse()
|
|
.expect("the mnemonic is invalid!");
|
|
|
|
let client_config = validator_client::Config::new(nymd_url, api_url, Some(mixnet_contract));
|
|
let inner = validator_client::Client::new_signing(client_config, mnemonic)
|
|
.expect("Failed to connect to nymd!");
|
|
|
|
Client(Arc::new(RwLock::new(inner)))
|
|
}
|
|
}
|
|
|
|
impl<C> Client<C> {
|
|
pub(crate) async fn get_mixnodes(&self) -> Result<Vec<MixNodeBond>, ValidatorClientError>
|
|
where
|
|
C: CosmWasmClient + Sync,
|
|
{
|
|
self.0.read().await.get_all_nymd_mixnodes().await
|
|
}
|
|
|
|
pub(crate) async fn get_gateways(&self) -> Result<Vec<GatewayBond>, ValidatorClientError>
|
|
where
|
|
C: CosmWasmClient + Sync,
|
|
{
|
|
self.0.read().await.get_all_nymd_gateways().await
|
|
}
|
|
|
|
#[allow(dead_code)]
|
|
pub(crate) async fn some_rewarding_stuff_here(&self) {
|
|
todo!()
|
|
}
|
|
}
|