Remove everywhere sp contract is used

This commit is contained in:
Jon Häggblad
2024-05-20 09:38:22 +02:00
parent 3cd9c6ad13
commit ebc30ec248
34 changed files with 7 additions and 1014 deletions
Generated
-16
View File
@@ -3956,7 +3956,6 @@ dependencies = [
"nym-node-requests",
"nym-node-tester-utils",
"nym-pemstore",
"nym-service-provider-directory-common",
"nym-sphinx",
"nym-task",
"nym-topology",
@@ -4138,7 +4137,6 @@ dependencies = [
"nym-multisig-contract-common",
"nym-network-defaults",
"nym-pemstore",
"nym-service-provider-directory-common",
"nym-sphinx",
"nym-types",
"nym-validator-client",
@@ -5283,19 +5281,6 @@ dependencies = [
"url",
]
[[package]]
name = "nym-service-provider-directory-common"
version = "0.1.0"
dependencies = [
"cosmwasm-schema",
"cosmwasm-std",
"cw-controllers",
"cw-utils",
"cw2",
"nym-contracts-common",
"thiserror",
]
[[package]]
name = "nym-service-providers-common"
version = "0.1.0"
@@ -5720,7 +5705,6 @@ dependencies = [
"nym-mixnet-contract-common",
"nym-multisig-contract-common",
"nym-network-defaults",
"nym-service-provider-directory-common",
"nym-vesting-contract-common",
"prost 0.12.4",
"reqwest 0.12.4",
-1
View File
@@ -39,7 +39,6 @@ members = [
"common/cosmwasm-smart-contracts/group-contract",
"common/cosmwasm-smart-contracts/mixnet-contract",
"common/cosmwasm-smart-contracts/multisig-contract",
"common/cosmwasm-smart-contracts/service-provider-directory",
"common/cosmwasm-smart-contracts/vesting-contract",
"common/country-group",
"common/credential-storage",
@@ -20,7 +20,6 @@ nym-vesting-contract-common = { path = "../../cosmwasm-smart-contracts/vesting-c
nym-coconut-bandwidth-contract-common = { path = "../../cosmwasm-smart-contracts/coconut-bandwidth-contract" }
nym-multisig-contract-common = { path = "../../cosmwasm-smart-contracts/multisig-contract" }
nym-group-contract-common = { path = "../../cosmwasm-smart-contracts/group-contract" }
nym-service-provider-directory-common = { path = "../../cosmwasm-smart-contracts/service-provider-directory" }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
nym-http-api-client = { path = "../../../common/http-api-client"}
@@ -85,14 +84,6 @@ name = "offline_signing"
# (traits would need to be moved around and refactored themselves)
required-features = ["http-client"]
[[example]]
name = "query_service_provider_directory"
required-features = ["http-client"]
[[example]]
name = "query_name_service"
required-features = ["http-client"]
[features]
default = ["http-client"]
http-client = ["cosmrs/rpc"]
@@ -1,37 +0,0 @@
use std::str::FromStr;
use cosmrs::AccountId;
use nym_name_service_common::Address;
use nym_network_defaults::{setup_env, NymNetworkDetails};
use nym_validator_client::nyxd::contract_traits::{
NameServiceQueryClient, PagedNameServiceQueryClient,
};
#[tokio::main]
async fn main() {
setup_env(Some("../../../envs/qa.env"));
let network_details = NymNetworkDetails::new_from_env();
let config =
nym_validator_client::Config::try_from_nym_network_details(&network_details).unwrap();
let client = nym_validator_client::Client::new_query(config).unwrap();
let config = client.nyxd.get_name_service_config().await.unwrap();
println!("config: {config:?}");
let names_paged = client.nyxd.get_names_paged(None, None).await.unwrap();
println!("names (paged): {names_paged:#?}");
let names = client.nyxd.get_all_names().await.unwrap();
println!("names: {names:#?}");
let owner = AccountId::from_str("n1hmf957kc7arcd39rl7xq8l0a4zyg7kxnv7su87").unwrap();
let names_by_owner = client.nyxd.get_names_by_owner(owner).await.unwrap();
println!("names (by owner): {names_by_owner:#?}");
let nym_address = Address::new("client_id.client_key@gateway_id").unwrap();
let names_by_address = client.nyxd.get_names_by_address(nym_address).await.unwrap();
println!("names (by address): {names_by_address:#?}");
let service_info = client.nyxd.get_name_entry(1).await;
println!("service info: {service_info:#?}");
}
@@ -1,45 +0,0 @@
use std::str::FromStr;
use cosmrs::AccountId;
use nym_network_defaults::{setup_env, NymNetworkDetails};
use nym_service_provider_directory_common::NymAddress;
use nym_validator_client::nyxd::contract_traits::{
PagedSpDirectoryQueryClient, SpDirectoryQueryClient,
};
#[tokio::main]
async fn main() {
setup_env(Some("../../../envs/qa.env"));
let network_details = NymNetworkDetails::new_from_env();
let config =
nym_validator_client::Config::try_from_nym_network_details(&network_details).unwrap();
let client = nym_validator_client::Client::new_query(config).unwrap();
let config = client.nyxd.get_service_config().await.unwrap();
println!("config: {config:?}");
let services_paged = client.nyxd.get_services_paged(None, None).await.unwrap();
println!("services (paged): {services_paged:#?}");
let services = client.nyxd.get_all_services().await.unwrap();
println!("services: {services:#?}");
let announcer = AccountId::from_str("n1hmf957kc7arcd39rl7xq8l0a4zyg7kxnv7su87").unwrap();
let services_by_announcer = client
.nyxd
.get_services_by_announcer(announcer)
.await
.unwrap();
println!("services (by announcer): {services_by_announcer:#?}");
let nym_address = NymAddress::new("foo.bar@gateway");
let services_by_nym_address = client
.nyxd
.get_services_by_nym_address(nym_address)
.await
.unwrap();
assert_eq!(services_by_announcer, services_by_nym_address);
let service_info = client.nyxd.get_service_info(1).await;
println!("service info: {service_info:#?}");
}
@@ -25,7 +25,6 @@ pub use nym_coconut_dkg_common::types::EpochId;
use nym_http_api_client::{ApiClient, NO_PARAMS};
use nym_mixnet_contract_common::mixnode::MixNodeDetails;
use nym_mixnet_contract_common::{GatewayBond, IdentityKeyRef, MixId};
use nym_service_provider_directory_common::response::ServicesListResponse;
pub mod error;
pub mod routes;
@@ -491,12 +490,6 @@ pub trait NymApiClientExt: ApiClient {
)
.await
}
async fn get_service_providers(&self) -> Result<ServicesListResponse, NymAPIError> {
log::trace!("Getting service providers");
self.get_json(&[routes::API_VERSION, routes::SERVICE_PROVIDERS], NO_PARAMS)
.await
}
}
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
@@ -14,7 +14,6 @@ pub mod ephemera_query_client;
pub mod group_query_client;
pub mod mixnet_query_client;
pub mod multisig_query_client;
pub mod sp_directory_query_client;
pub mod vesting_query_client;
// signing clients
@@ -24,7 +23,6 @@ pub mod ephemera_signing_client;
pub mod group_signing_client;
pub mod mixnet_signing_client;
pub mod multisig_signing_client;
pub mod sp_directory_signing_client;
pub mod vesting_signing_client;
// re-export query traits
@@ -36,7 +34,6 @@ pub use ephemera_query_client::{EphemeraQueryClient, PagedEphemeraQueryClient};
pub use group_query_client::{GroupQueryClient, PagedGroupQueryClient};
pub use mixnet_query_client::{MixnetQueryClient, PagedMixnetQueryClient};
pub use multisig_query_client::{MultisigQueryClient, PagedMultisigQueryClient};
pub use sp_directory_query_client::{PagedSpDirectoryQueryClient, SpDirectoryQueryClient};
pub use vesting_query_client::{PagedVestingQueryClient, VestingQueryClient};
// re-export signing traits
@@ -46,7 +43,6 @@ pub use ephemera_signing_client::EphemeraSigningClient;
pub use group_signing_client::GroupSigningClient;
pub use mixnet_signing_client::MixnetSigningClient;
pub use multisig_signing_client::MultisigSigningClient;
pub use sp_directory_signing_client::SpDirectorySigningClient;
pub use vesting_signing_client::VestingSigningClient;
// helper for providing blanket implementation for query clients
@@ -63,9 +59,6 @@ pub trait NymContractsProvider {
// ephemera-related
fn ephemera_contract_address(&self) -> Option<&AccountId>;
// SPs
fn service_provider_contract_address(&self) -> Option<&AccountId>;
}
#[derive(Debug, Clone)]
@@ -79,8 +72,6 @@ pub struct TypedNymContracts {
pub coconut_dkg_contract_address: Option<AccountId>,
pub ephemera_contract_address: Option<AccountId>,
pub service_provider_directory_contract_address: Option<AccountId>,
}
impl TryFrom<NymContracts> for TypedNymContracts {
@@ -116,10 +107,6 @@ impl TryFrom<NymContracts> for TypedNymContracts {
.ephemera_contract_address
.map(|addr| addr.parse())
.transpose()?,
service_provider_directory_contract_address: value
.service_provider_directory_contract_address
.map(|addr| addr.parse())
.transpose()?,
})
}
}
@@ -1,142 +0,0 @@
use crate::collect_paged;
use async_trait::async_trait;
use cosmrs::AccountId;
use nym_contracts_common::{signing::Nonce, ContractBuildInformation};
use nym_service_provider_directory_common::{
msg::QueryMsg as SpQueryMsg,
response::{
ConfigResponse, PagedServicesListResponse, ServiceInfoResponse, ServicesListResponse,
},
NymAddress, Service, ServiceId,
};
use serde::Deserialize;
use crate::nyxd::contract_traits::NymContractsProvider;
use crate::nyxd::{error::NyxdError, CosmWasmClient};
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
pub trait SpDirectoryQueryClient {
async fn query_service_provider_contract<T>(&self, query: SpQueryMsg) -> Result<T, NyxdError>
where
for<'a> T: Deserialize<'a>;
async fn get_service_config(&self) -> Result<ConfigResponse, NyxdError> {
self.query_service_provider_contract(SpQueryMsg::Config {})
.await
}
async fn get_service_info(
&self,
service_id: ServiceId,
) -> Result<ServiceInfoResponse, NyxdError> {
self.query_service_provider_contract(SpQueryMsg::ServiceId { service_id })
.await
}
async fn get_services_paged(
&self,
start_after: Option<ServiceId>,
limit: Option<u32>,
) -> Result<PagedServicesListResponse, NyxdError> {
self.query_service_provider_contract(SpQueryMsg::All { limit, start_after })
.await
}
async fn get_services_by_announcer(
&self,
announcer: AccountId,
) -> Result<ServicesListResponse, NyxdError> {
self.query_service_provider_contract(SpQueryMsg::ByAnnouncer {
announcer: announcer.to_string(),
})
.await
}
async fn get_services_by_nym_address(
&self,
nym_address: NymAddress,
) -> Result<ServicesListResponse, NyxdError> {
self.query_service_provider_contract(SpQueryMsg::ByNymAddress { nym_address })
.await
}
async fn get_sp_contract_version(&self) -> Result<ContractBuildInformation, NyxdError> {
self.query_service_provider_contract(SpQueryMsg::GetContractVersion {})
.await
}
async fn get_sp_contract_cw2_version(&self) -> Result<cw2::ContractVersion, NyxdError> {
self.query_service_provider_contract(SpQueryMsg::GetCW2ContractVersion {})
.await
}
async fn get_service_signing_nonce(&self, address: &AccountId) -> Result<Nonce, NyxdError> {
self.query_service_provider_contract(SpQueryMsg::SigningNonce {
address: address.to_string(),
})
.await
}
}
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
pub trait PagedSpDirectoryQueryClient: SpDirectoryQueryClient {
async fn get_all_services(&self) -> Result<Vec<Service>, NyxdError> {
collect_paged!(self, get_services_paged, services)
}
}
#[async_trait]
impl<T> PagedSpDirectoryQueryClient for T where T: SpDirectoryQueryClient {}
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
impl<C> SpDirectoryQueryClient for C
where
C: CosmWasmClient + NymContractsProvider + Send + Sync,
{
async fn query_service_provider_contract<T>(&self, query: SpQueryMsg) -> Result<T, NyxdError>
where
for<'a> T: Deserialize<'a>,
{
let sp_directory_contract_address =
&self.service_provider_contract_address().ok_or_else(|| {
NyxdError::unavailable_contract_address("service provider directory contract")
})?;
self.query_contract_smart(sp_directory_contract_address, &query)
.await
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::nyxd::contract_traits::tests::IgnoreValue;
// it's enough that this compiles and clippy is happy about it
#[allow(dead_code)]
fn all_query_variants_are_covered<C: SpDirectoryQueryClient + Send + Sync>(
client: C,
msg: SpQueryMsg,
) {
match msg {
SpQueryMsg::ServiceId { service_id } => client.get_service_info(service_id).ignore(),
SpQueryMsg::ByAnnouncer { announcer } => client
.get_services_by_announcer(announcer.parse().unwrap())
.ignore(),
SpQueryMsg::ByNymAddress { nym_address } => {
client.get_services_by_nym_address(nym_address).ignore()
}
SpQueryMsg::All { limit, start_after } => {
client.get_services_paged(start_after, limit).ignore()
}
SpQueryMsg::SigningNonce { address } => client
.get_service_signing_nonce(&address.parse().unwrap())
.ignore(),
SpQueryMsg::Config {} => client.get_service_config().ignore(),
SpQueryMsg::GetContractVersion {} => client.get_sp_contract_version().ignore(),
SpQueryMsg::GetCW2ContractVersion {} => client.get_sp_contract_cw2_version().ignore(),
};
}
}
@@ -1,148 +0,0 @@
// Copyright 2023 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
use crate::nyxd::contract_traits::NymContractsProvider;
use crate::nyxd::{
coin::Coin, cosmwasm_client::types::ExecuteResult, error::NyxdError, Fee, SigningCosmWasmClient,
};
use crate::signing::signer::OfflineSigner;
use async_trait::async_trait;
use nym_contracts_common::signing::MessageSignature;
use nym_service_provider_directory_common::{
msg::ExecuteMsg as SpExecuteMsg, NymAddress, ServiceDetails, ServiceId,
};
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
pub trait SpDirectorySigningClient {
async fn execute_service_provider_directory_contract(
&self,
fee: Option<Fee>,
msg: SpExecuteMsg,
funds: Vec<Coin>,
) -> Result<ExecuteResult, NyxdError>;
async fn announce_service_provider(
&self,
service: ServiceDetails,
owner_signature: MessageSignature,
deposit: Coin,
fee: Option<Fee>,
) -> Result<ExecuteResult, NyxdError> {
self.execute_service_provider_directory_contract(
fee,
SpExecuteMsg::Announce {
service,
owner_signature,
},
vec![deposit],
)
.await
}
async fn delete_service_provider_by_id(
&self,
service_id: ServiceId,
fee: Option<Fee>,
) -> Result<ExecuteResult, NyxdError> {
self.execute_service_provider_directory_contract(
fee,
SpExecuteMsg::DeleteId { service_id },
vec![],
)
.await
}
async fn delete_service_provider_by_nym_address(
&self,
nym_address: NymAddress,
fee: Option<Fee>,
) -> Result<ExecuteResult, NyxdError> {
self.execute_service_provider_directory_contract(
fee,
SpExecuteMsg::DeleteNymAddress { nym_address },
vec![],
)
.await
}
async fn update_deposit_required(
&self,
deposit_required: Coin,
fee: Option<Fee>,
) -> Result<ExecuteResult, NyxdError> {
self.execute_service_provider_directory_contract(
fee,
SpExecuteMsg::UpdateDepositRequired {
deposit_required: deposit_required.into(),
},
vec![],
)
.await
}
}
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
impl<C> SpDirectorySigningClient for C
where
C: SigningCosmWasmClient + NymContractsProvider + Sync,
NyxdError: From<<Self as OfflineSigner>::Error>,
{
async fn execute_service_provider_directory_contract(
&self,
fee: Option<Fee>,
msg: SpExecuteMsg,
funds: Vec<Coin>,
) -> Result<ExecuteResult, NyxdError> {
let sp_directory_contract_address =
&self.service_provider_contract_address().ok_or_else(|| {
NyxdError::unavailable_contract_address("service provider directory contract")
})?;
let fee = fee.unwrap_or(Fee::Auto(Some(self.simulated_gas_multiplier())));
let memo = msg.default_memo();
let signer_address = &self.signer_addresses()?[0];
self.execute(
signer_address,
sp_directory_contract_address,
&msg,
fee,
memo,
funds,
)
.await
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::nyxd::contract_traits::tests::{mock_coin, IgnoreValue};
// it's enough that this compiles and clippy is happy about it
#[allow(dead_code)]
fn all_execute_variants_are_covered<C: SpDirectorySigningClient + Send + Sync>(
client: C,
msg: SpExecuteMsg,
) {
match msg {
SpExecuteMsg::Announce {
service,
owner_signature,
} => client
.announce_service_provider(service, owner_signature, mock_coin(), None)
.ignore(),
SpExecuteMsg::DeleteId { service_id } => client
.delete_service_provider_by_id(service_id, None)
.ignore(),
SpExecuteMsg::DeleteNymAddress { nym_address } => client
.delete_service_provider_by_nym_address(nym_address, None)
.ignore(),
SpExecuteMsg::UpdateDepositRequired { deposit_required } => client
.update_deposit_required(deposit_required.into(), None)
.ignore(),
};
}
}
@@ -246,12 +246,6 @@ impl<C, S> NyxdClient<C, S> {
self.config.contracts.multisig_contract_address = Some(address);
}
pub fn set_service_provider_contract_address(&mut self, address: AccountId) {
self.config
.contracts
.service_provider_directory_contract_address = Some(address);
}
pub fn set_simulated_gas_multiplier(&mut self, multiplier: f32) {
self.config.simulated_gas_multiplier = multiplier;
}
@@ -288,13 +282,6 @@ impl<C, S> NymContractsProvider for NyxdClient<C, S> {
fn ephemera_contract_address(&self) -> Option<&AccountId> {
self.config.contracts.ephemera_contract_address.as_ref()
}
fn service_provider_contract_address(&self) -> Option<&AccountId> {
self.config
.contracts
.service_provider_directory_contract_address
.as_ref()
}
}
// queries
-1
View File
@@ -46,7 +46,6 @@ nym-vesting-contract-common = { path = "../cosmwasm-smart-contracts/vesting-cont
nym-coconut-bandwidth-contract-common = { path = "../cosmwasm-smart-contracts/coconut-bandwidth-contract" }
nym-coconut-dkg-common = { path = "../cosmwasm-smart-contracts/coconut-dkg" }
nym-multisig-contract-common = { path = "../cosmwasm-smart-contracts/multisig-contract" }
nym-service-provider-directory-common = { path = "../cosmwasm-smart-contracts/service-provider-directory" }
nym-sphinx = { path = "../../common/nymsphinx" }
nym-client-core = { path = "../../common/client-core" }
nym-config = { path = "../../common/config" }
@@ -6,8 +6,6 @@ use clap::{Args, Subcommand};
pub mod gateway;
pub mod identity_key;
pub mod mixnode;
pub mod name;
pub mod service;
#[derive(Debug, Args)]
#[clap(args_conflicts_with_subcommands = true, subcommand_required = true)]
@@ -23,10 +21,6 @@ pub enum MixnetOperatorsCommands {
Mixnode(mixnode::MixnetOperatorsMixnode),
/// Manage your gateway
Gateway(gateway::MixnetOperatorsGateway),
/// Manage your service
ServiceProvider(service::MixnetOperatorsService),
/// Manage your registered name
Name(name::MixnetOperatorsName),
/// Sign messages using your private identity key
IdentityKey(identity_key::MixnetOperatorsIdentityKey),
}
@@ -1,25 +0,0 @@
use clap::Parser;
use log::{error, info};
use nym_name_service_common::NameId;
use nym_validator_client::nyxd::{contract_traits::NameServiceSigningClient, error::NyxdError};
use tap::TapFallible;
use crate::context::SigningClient;
#[derive(Debug, Parser)]
pub struct Args {
#[clap(long)]
pub id: NameId,
}
pub async fn delete(args: Args, client: SigningClient) -> Result<(), NyxdError> {
info!("Deleting registered name alias with id {}", args.id);
let res = client
.delete_name_by_id(args.id, None)
.await
.tap_err(|err| error!("Failed to delete name: {err:#?}"))?;
info!("Deleted: {res:?}");
Ok(())
}
@@ -1,22 +0,0 @@
use clap::{Args, Subcommand};
pub mod delete;
pub mod register;
pub mod register_sign_payload;
#[derive(Debug, Args)]
#[clap(args_conflicts_with_subcommands = true, subcommand_required = true)]
pub struct MixnetOperatorsName {
#[clap(subcommand)]
pub command: MixnetOperatorsNameCommands,
}
#[derive(Debug, Subcommand)]
pub enum MixnetOperatorsNameCommands {
/// Register a name alias for a nym address
Register(register::Args),
/// Delete name alias for a nym address
Delete(delete::Args),
/// Create base58-encoded payload required for producing valiid register signature.
CreateNameRegisterPayload(register_sign_payload::Args),
}
@@ -1,53 +0,0 @@
use clap::Parser;
use log::{error, info};
use nym_contracts_common::signing::MessageSignature;
use nym_name_service_common::{Address, Coin, NameDetails, NymName};
use nym_sphinx::addressing::clients::Recipient;
use nym_validator_client::nyxd::{contract_traits::NameServiceSigningClient, error::NyxdError};
use tap::TapFallible;
use crate::context::SigningClient;
#[derive(Debug, Parser)]
pub struct Args {
/// Name alias
#[clap(long)]
pub name: NymName,
/// Nym address that the alias is pointing to
#[clap(long)]
pub nym_address: Recipient,
#[clap(long)]
pub signature: MessageSignature,
/// Deposit to be made to the service provider directory, in curent DENOMINATION (e.g. 'unym')
#[clap(long)]
pub deposit: u128,
}
pub async fn register(args: Args, client: SigningClient) -> Result<(), NyxdError> {
info!(
"Registering name alias '{}' for nym address '{}'",
args.name, args.nym_address
);
let address = Address::new(&args.nym_address.to_string()).expect("invalid address");
let identity_key = address.client_id().to_string();
let name = NameDetails {
name: args.name,
address,
identity_key,
};
let denom = client.current_chain_details().mix_denom.base.as_str();
let deposit = Coin::new(args.deposit, denom);
let res = client
.register_name(name, args.signature, deposit.into(), None)
.await
.tap_err(|err| error!("Failed to register name: {err:#?}"))?;
info!("Registered name: {res:?}");
Ok(())
}
@@ -1,65 +0,0 @@
// Copyright 2023 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
use crate::{
context::SigningClient,
utils::{account_id_to_cw_addr, DataWrapper},
};
use clap::Parser;
use cosmwasm_std::Coin;
use nym_bin_common::output_format::OutputFormat;
use nym_name_service_common::{
signing_types::construct_name_register_sign_payload, Address, NymName,
};
use nym_sphinx::addressing::clients::Recipient;
use nym_validator_client::nyxd::{contract_traits::NameServiceQueryClient, error::NyxdError};
#[derive(Debug, Parser)]
pub struct Args {
// The name to register.
#[arg(long)]
pub name: NymName,
/// The nym address the name should point to.
#[arg(long)]
pub nym_address: Recipient,
#[arg(long)]
pub amount: u128,
#[arg(short, long, default_value_t = OutputFormat::default())]
output: OutputFormat,
}
pub async fn create_payload(args: Args, client: SigningClient) -> Result<(), NyxdError> {
let address = Address::new(&args.nym_address.to_string()).expect("invalid address");
let identity_key = address.client_id().to_string();
let name = nym_name_service_common::NameDetails {
name: args.name,
address,
identity_key,
};
let denom = client.current_chain_details().mix_denom.base.as_str();
let deposit = Coin::new(args.amount, denom);
let nonce = match client.get_name_signing_nonce(&client.address()).await {
Ok(nonce) => nonce,
Err(err) => {
eprint!(
"failed to query for the signing nonce of {}: {err}",
client.address()
);
return Err(err);
}
};
let address = account_id_to_cw_addr(&client.address());
let payload = construct_name_register_sign_payload(nonce, address, deposit, name);
let wrapper = DataWrapper::new(payload.to_base58_string().unwrap());
println!("{}", args.output.format(&wrapper));
Ok(())
}
@@ -1,45 +0,0 @@
use clap::Parser;
use log::info;
use nym_contracts_common::signing::MessageSignature;
use nym_service_provider_directory_common::{Coin, NymAddress, ServiceDetails, ServiceType};
use nym_validator_client::nyxd::contract_traits::SpDirectorySigningClient;
use crate::context::SigningClient;
#[derive(Debug, Parser)]
pub struct Args {
#[clap(long)]
pub nym_address: String,
#[clap(long)]
pub signature: MessageSignature,
/// Deposit to be made to the service provider directory, in curent DENOMINATION (e.g. 'unym')
#[clap(long)]
pub deposit: u128,
#[clap(long)]
pub identity_key: String,
}
pub async fn announce(args: Args, client: SigningClient) {
info!("Annoucing service provider");
let nym_address = NymAddress::Address(args.nym_address);
let service_type = ServiceType::NetworkRequester;
let service = ServiceDetails {
nym_address,
service_type,
identity_key: args.identity_key,
};
let denom = client.current_chain_details().mix_denom.base.as_str();
let deposit = Coin::new(args.deposit, denom);
let res = client
.announce_service_provider(service, args.signature, deposit.into(), None)
.await
.expect("Failed to announce service provider");
info!("Announced service provider: {res:?}");
}
@@ -1,61 +0,0 @@
// Copyright 2023 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
use crate::{
context::SigningClient,
utils::{account_id_to_cw_addr, DataWrapper},
};
use clap::Parser;
use cosmwasm_std::Coin;
use nym_bin_common::output_format::OutputFormat;
use nym_service_provider_directory_common::{
signing_types::construct_service_provider_announce_sign_payload, NymAddress,
ServiceType::NetworkRequester,
};
use nym_sphinx::addressing::clients::Recipient;
use nym_validator_client::nyxd::contract_traits::SpDirectoryQueryClient;
#[derive(Debug, Parser)]
pub struct Args {
#[clap(long)]
pub nym_address: Recipient,
#[clap(long)]
pub amount: u128,
#[clap(long)]
pub identity_key: String,
#[clap(short, long, default_value_t = OutputFormat::default())]
output: OutputFormat,
}
pub async fn create_payload(args: Args, client: SigningClient) {
let service = nym_service_provider_directory_common::ServiceDetails {
nym_address: NymAddress::new(&args.nym_address.to_string()),
service_type: NetworkRequester,
identity_key: args.identity_key,
};
let denom = client.current_chain_details().mix_denom.base.as_str();
let deposit = Coin::new(args.amount, denom);
let nonce = match client.get_service_signing_nonce(&client.address()).await {
Ok(nonce) => nonce,
Err(err) => {
eprint!(
"failed to query for the signing nonce of {}: {err}",
client.address()
);
return;
}
};
let address = account_id_to_cw_addr(&client.address());
let payload =
construct_service_provider_announce_sign_payload(nonce, address, deposit, service);
let wrapper = DataWrapper::new(payload.to_base58_string().unwrap());
println!("{}", args.output.format(&wrapper))
}
@@ -1,23 +0,0 @@
use clap::Parser;
use log::info;
use nym_service_provider_directory_common::ServiceId;
use nym_validator_client::nyxd::contract_traits::SpDirectorySigningClient;
use crate::context::SigningClient;
#[derive(Debug, Parser)]
pub struct Args {
#[clap(long)]
pub id: ServiceId,
}
pub async fn delete(args: Args, client: SigningClient) {
info!("Deleting service provider with id {}", args.id);
let res = client
.delete_service_provider_by_id(args.id, None)
.await
.expect("Failed to delete service provider");
info!("Deleted: {res:?}");
}
@@ -1,23 +0,0 @@
use clap::{Args, Subcommand};
pub mod announce;
pub mod announce_sign_payload;
pub mod delete;
#[derive(Debug, Args)]
#[clap(args_conflicts_with_subcommands = true, subcommand_required = true)]
pub struct MixnetOperatorsService {
#[clap(subcommand)]
pub command: MixnetOperatorsServiceCommands,
}
#[allow(clippy::large_enum_variant)]
#[derive(Debug, Subcommand)]
pub enum MixnetOperatorsServiceCommands {
/// Announce service provider to the world
Announce(announce::Args),
/// Delete entry for service provider from the directory
Delete(delete::Args),
/// Create base58-encoded payload required for producing valid announce signature.
CreateServiceAnnounceSignPayload(announce_sign_payload::Args),
}
@@ -5,8 +5,6 @@ use clap::{Args, Subcommand};
pub mod query_all_gateways;
pub mod query_all_mixnodes;
pub mod query_all_names;
pub mod query_all_service_providers;
#[derive(Debug, Args)]
#[clap(args_conflicts_with_subcommands = true, subcommand_required = true)]
@@ -21,8 +19,4 @@ pub enum MixnetQueryCommands {
Mixnodes(query_all_mixnodes::Args),
/// Query gateways
Gateways(query_all_gateways::Args),
/// Query announced service-providers
ServiceProviders(query_all_service_providers::Args),
/// Query registed names
Names(query_all_names::Args),
}
@@ -1,53 +0,0 @@
// Copyright 2023 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
use crate::context::QueryClientWithNyxd;
use crate::utils::show_error;
use clap::Parser;
use comfy_table::Table;
use nym_validator_client::client::NymApiClientExt;
use nym_validator_client::nym_api::error::NymAPIError;
#[derive(Debug, Parser)]
pub struct Args {
#[clap(value_parser)]
#[clap(help = "Optionally, the registered name to display")]
pub name: Option<String>,
}
pub async fn query(args: Args, client: &QueryClientWithNyxd) {
log::trace!("Querying all registered names");
match client.nym_api.get_registered_names().await {
Ok(res) => {
if let Some(name) = args.name {
let name = res.names.iter().find(|name_entry| {
name_entry.name.name.to_string().eq_ignore_ascii_case(&name)
});
println!(
"{}",
::serde_json::to_string_pretty(&name).expect("json formatting error")
);
} else {
let mut table = Table::new();
table.set_header(vec!["Name Id", "Owner", "Nym Address", "Name"]);
for name_entry in res.names {
table.add_row(vec![
name_entry.id.to_string(),
name_entry.owner.to_string(),
name_entry.name.address.to_string(),
name_entry.name.name.to_string(),
]);
}
println!("The registered names in the directory are:");
println!("{table}");
}
}
Err(NymAPIError::NotFound) => {
println!("nym-api reports no name endpoint available");
}
Err(e) => show_error(e),
}
}
@@ -1,55 +0,0 @@
// Copyright 2023 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
use crate::context::QueryClientWithNyxd;
use crate::utils::show_error;
use clap::Parser;
use comfy_table::Table;
use nym_validator_client::client::NymApiClientExt;
use nym_validator_client::nym_api::error::NymAPIError;
#[derive(Debug, Parser)]
pub struct Args {
#[clap(value_parser)]
#[clap(help = "Optionally, the service provider to display")]
pub nym_address: Option<String>,
}
pub async fn query(args: Args, client: &QueryClientWithNyxd) {
match client.nym_api.get_service_providers().await {
Ok(res) => {
if let Some(nym_address) = args.nym_address {
let service = res.services.iter().find(|service| {
service
.service
.nym_address
.to_string()
.eq_ignore_ascii_case(&nym_address)
});
println!(
"{}",
::serde_json::to_string_pretty(&service).expect("json formatting error")
);
} else {
let mut table = Table::new();
table.set_header(vec!["Service Id", "Announcer", "Type", "Nym Address"]);
for service in res.services {
table.add_row(vec![
service.service_id.to_string(),
service.announcer.to_string(),
service.service.service_type.to_string(),
service.service.nym_address.to_string(),
]);
}
println!("The service providers in the directory are:");
println!("{table}");
}
}
Err(NymAPIError::NotFound) => {
println!("nym-api reports no service provider endpoint available");
}
Err(e) => show_error(e),
}
}
-1
View File
@@ -94,7 +94,6 @@ nym-mixnet-contract-common = { path = "../common/cosmwasm-smart-contracts/mixnet
nym-vesting-contract-common = { path = "../common/cosmwasm-smart-contracts/vesting-contract" }
nym-contracts-common = { path = "../common/cosmwasm-smart-contracts/contracts-common" }
nym-multisig-contract-common = { path = "../common/cosmwasm-smart-contracts/multisig-contract" }
nym-service-provider-directory-common = { path = "../common/cosmwasm-smart-contracts/service-provider-directory" }
nym-coconut = { path = "../common/nymcoconut", features = ["key-zeroize"] }
nym-sphinx = { path = "../common/nymsphinx" }
nym-pemstore = { path = "../common/pemstore" }
-4
View File
@@ -7,7 +7,6 @@ use nym_mixnet_contract_common::{
families::FamilyHead, GatewayBond, IdentityKey, Interval, MixId, MixNodeDetails,
RewardingParams,
};
use nym_service_provider_directory_common::Service;
use nym_validator_client::nyxd::AccountId;
use std::collections::{HashMap, HashSet};
@@ -26,8 +25,6 @@ pub(crate) struct ValidatorCacheData {
pub(crate) mix_to_family: Cache<Vec<(IdentityKey, FamilyHead)>>,
pub(crate) service_providers: Cache<Vec<Service>>,
pub(crate) contracts_info: Cache<CachedContractsInfo>,
}
@@ -43,7 +40,6 @@ impl ValidatorCacheData {
current_interval: Cache::default(),
current_reward_params: Cache::default(),
mix_to_family: Cache::default(),
service_providers: Cache::default(),
contracts_info: Cache::default(),
}
}
-16
View File
@@ -9,7 +9,6 @@ use nym_mixnet_contract_common::{
families::FamilyHead, GatewayBond, IdentityKey, Interval, MixId, MixNodeBond, MixNodeDetails,
RewardingParams,
};
use nym_service_provider_directory_common::Service;
use rocket::fairing::AdHoc;
use std::{
collections::HashSet,
@@ -55,7 +54,6 @@ impl NymContractCache {
rewarding_params: RewardingParams,
current_interval: Interval,
mix_to_family: Vec<(IdentityKey, FamilyHead)>,
services: Option<Vec<Service>>,
nym_contracts_info: CachedContractsInfo,
) {
match time::timeout(Duration::from_millis(100), self.inner.write()).await {
@@ -71,10 +69,6 @@ impl NymContractCache {
.current_interval
.unchecked_update(Some(current_interval));
cache.mix_to_family.unchecked_update(mix_to_family);
// Just return empty lists when these are not available
cache
.service_providers
.unchecked_update(services.unwrap_or_default());
cache.contracts_info.unchecked_update(nym_contracts_info)
}
Err(err) => {
@@ -307,16 +301,6 @@ impl NymContractCache {
self.mixnode_details(mix_id).await.1
}
pub(crate) async fn services(&self) -> Cache<Vec<Service>> {
match time::timeout(Duration::from_millis(100), self.inner.read()).await {
Ok(cache) => cache.service_providers.clone_cache(),
Err(err) => {
error!("{err}");
Cache::new(Vec::new())
}
}
}
pub fn initialised(&self) -> bool {
self.initialised.load(Ordering::Relaxed)
}
+3 -30
View File
@@ -10,8 +10,7 @@ use futures::future::join_all;
use nym_mixnet_contract_common::{MixId, MixNodeDetails, RewardedSetNodeStatus};
use nym_task::TaskClient;
use nym_validator_client::nyxd::contract_traits::{
MixnetQueryClient, NymContractsProvider, PagedSpDirectoryQueryClient, SpDirectoryQueryClient,
VestingQueryClient,
MixnetQueryClient, NymContractsProvider, VestingQueryClient,
};
use nym_validator_client::nyxd::CosmWasmClient;
use std::{collections::HashMap, sync::atomic::Ordering, time::Duration};
@@ -55,7 +54,6 @@ impl NymContractCacheRefresher {
let mixnet = query_guard!(client_guard, mixnet_contract_address());
let vesting = query_guard!(client_guard, vesting_contract_address());
let service_provider = query_guard!(client_guard, service_provider_contract_address());
let coconut_bandwidth = query_guard!(client_guard, coconut_bandwidth_contract_address());
let coconut_dkg = query_guard!(client_guard, dkg_contract_address());
let group = query_guard!(client_guard, group_contract_address());
@@ -64,7 +62,6 @@ impl NymContractCacheRefresher {
// get cw2 versions
let mixnet_cw2_future = query_guard!(client_guard, get_mixnet_contract_cw2_version());
let vesting_cw2_future = query_guard!(client_guard, get_vesting_contract_cw2_version());
let service_provider_cw2_future = query_guard!(client_guard, get_sp_contract_cw2_version());
// group and multisig contract save that information in their storage but don't expose it via queries
// so a temporary workaround...
@@ -93,38 +90,17 @@ impl NymContractCacheRefresher {
None
};
let mut cw2_info = join_all(vec![
mixnet_cw2_future,
vesting_cw2_future,
service_provider_cw2_future,
])
.await;
let mut cw2_info = join_all(vec![mixnet_cw2_future, vesting_cw2_future]).await;
// get detailed build info
let mixnet_detailed_future = query_guard!(client_guard, get_mixnet_contract_version());
let vesting_detailed_future = query_guard!(client_guard, get_vesting_contract_version());
let service_provider_detailed_future =
query_guard!(client_guard, get_sp_contract_version());
let mut build_info = join_all(vec![
mixnet_detailed_future,
vesting_detailed_future,
service_provider_detailed_future,
])
.await;
let mut build_info = join_all(vec![mixnet_detailed_future, vesting_detailed_future]).await;
// the below unwraps are fine as we definitely have the specified number of entries
// Note to whoever updates this code in the future: `pop` removes **LAST** element,
// so make sure you call them in correct order, depending on what's specified in the `join_all`
updated.insert(
"nym-service-provider-directory-contract".to_string(),
CachedContractInfo::new(
service_provider,
cw2_info.pop().unwrap().ok(),
build_info.pop().unwrap().ok(),
),
);
updated.insert(
"nym-vesting-contract".to_string(),
CachedContractInfo::new(
@@ -176,8 +152,6 @@ impl NymContractCacheRefresher {
let (rewarded_set, active_set) =
Self::collect_rewarded_and_active_set_details(&mixnodes, &rewarded_set_map);
// The service providers and names are optional
let services = self.nyxd_client.get_all_services().await.ok();
let contract_info = self.get_nym_contracts_info().await?;
info!(
@@ -195,7 +169,6 @@ impl NymContractCacheRefresher {
rewarding_params,
current_interval,
mix_to_family,
services,
contract_info,
)
.await;
-1
View File
@@ -27,7 +27,6 @@ pub(crate) fn nym_contract_cache_routes(settings: &OpenApiSettings) -> (Vec<Rout
routes::get_blacklisted_gateways,
routes::get_interval_reward_params,
routes::get_current_epoch,
routes::get_services,
]
}
-8
View File
@@ -13,7 +13,6 @@ use nym_mixnet_contract_common::{
mixnode::MixNodeDetails, reward_params::RewardingParams, GatewayBond, Interval, MixId,
};
use nym_service_provider_directory_common::response::ServicesListResponse;
use rocket::{serde::json::Json, State};
use rocket_okapi::openapi;
use std::collections::HashSet;
@@ -126,10 +125,3 @@ pub async fn get_interval_reward_params(
pub async fn get_current_epoch(cache: &State<NymContractCache>) -> Json<Option<Interval>> {
Json(*cache.current_interval().await)
}
#[openapi(tag = "contract-cache")]
#[get("/services")]
pub async fn get_services(cache: &State<NymContractCache>) -> Json<ServicesListResponse> {
let services = cache.services().await.clone();
Json(services.as_slice().into())
}
+1 -15
View File
@@ -30,7 +30,6 @@ use nym_mixnet_contract_common::{
CurrentIntervalResponse, EpochStatus, ExecuteMsg, GatewayBond, IdentityKey, LayerAssignment,
MixId, RewardedSetNodeStatus,
};
use nym_service_provider_directory_common::msg::QueryMsg as SpQueryMsg;
use nym_validator_client::nyxd::contract_traits::PagedDkgQueryClient;
use nym_validator_client::nyxd::error::NyxdError;
use nym_validator_client::nyxd::{
@@ -38,7 +37,7 @@ use nym_validator_client::nyxd::{
CoconutBandwidthQueryClient, DkgQueryClient, DkgSigningClient, GroupQueryClient,
MixnetQueryClient, MixnetSigningClient, MultisigQueryClient, MultisigSigningClient,
NymContractsProvider, PagedMixnetQueryClient, PagedMultisigQueryClient,
PagedVestingQueryClient, SpDirectoryQueryClient,
PagedVestingQueryClient,
},
cosmwasm_client::types::ExecuteResult,
CosmWasmClient, Fee,
@@ -600,16 +599,3 @@ impl DkgQueryClient for Client {
nyxd_query!(self, query_dkg_contract(query).await)
}
}
#[async_trait]
impl SpDirectoryQueryClient for Client {
async fn query_service_provider_contract<T>(
&self,
query: SpQueryMsg,
) -> std::result::Result<T, NyxdError>
where
for<'a> T: Deserialize<'a>,
{
nyxd_query!(self, query_service_provider_contract(query).await)
}
}
@@ -7,8 +7,6 @@ use nym_network_defaults::NymNetworkDetails;
pub(crate) mod gateways;
pub(crate) mod identity_key;
pub(crate) mod mixnodes;
pub(crate) mod name;
pub(crate) mod services;
pub(crate) async fn execute(
global_args: ClientArgs,
@@ -22,8 +20,8 @@ pub(crate) async fn execute(
nym_cli_commands::validator::mixnet::operators::MixnetOperatorsCommands::Mixnode(
mixnode,
) => mixnodes::execute(global_args, mixnode, network_details).await,
nym_cli_commands::validator::mixnet::operators::MixnetOperatorsCommands::ServiceProvider(service) => services::execute(global_args, service, network_details).await,
nym_cli_commands::validator::mixnet::operators::MixnetOperatorsCommands::Name(name) => name::execute(global_args, name, network_details).await,
nym_cli_commands::validator::mixnet::operators::MixnetOperatorsCommands::IdentityKey(identity_key) => identity_key::execute(global_args, identity_key, network_details).await,
nym_cli_commands::validator::mixnet::operators::MixnetOperatorsCommands::IdentityKey(
identity_key,
) => identity_key::execute(global_args, identity_key, network_details).await,
}
}
@@ -1,36 +0,0 @@
use nym_cli_commands::context::{create_signing_client, ClientArgs};
use nym_network_defaults::NymNetworkDetails;
pub(crate) async fn execute(
global_args: ClientArgs,
name: nym_cli_commands::validator::mixnet::operators::name::MixnetOperatorsName,
network_details: &NymNetworkDetails,
) -> anyhow::Result<()> {
let res = match name.command {
nym_cli_commands::validator::mixnet::operators::name::MixnetOperatorsNameCommands::Register(register) => {
let res = nym_cli_commands::validator::mixnet::operators::name::register::register(register, create_signing_client(global_args, network_details)?).await;
match res {
Ok(_) => println!("Successfully registered the name"),
Err(_) => println!("Failed to register name")
};
res
},
nym_cli_commands::validator::mixnet::operators::name::MixnetOperatorsNameCommands::Delete(delete) => {
let res = nym_cli_commands::validator::mixnet::operators::name::delete::delete(delete, create_signing_client(global_args, network_details)?).await;
match res {
Ok(_) => println!("Successfully deleted the name"),
Err(_) => println!("Failed to delete name")
};
res
},
nym_cli_commands::validator::mixnet::operators::name::MixnetOperatorsNameCommands::CreateNameRegisterPayload(args) => {
let res = nym_cli_commands::validator::mixnet::operators::name::register_sign_payload::create_payload(args, create_signing_client(global_args, network_details)?).await;
match res {
Ok(_) => (),
Err(_) => println!("Failed to create payload")
};
res
}
};
Ok(res?)
}
@@ -1,15 +0,0 @@
use nym_cli_commands::context::{create_signing_client, ClientArgs};
use nym_network_defaults::NymNetworkDetails;
pub(crate) async fn execute(
global_args: ClientArgs,
service: nym_cli_commands::validator::mixnet::operators::service::MixnetOperatorsService,
network_details: &NymNetworkDetails,
) -> anyhow::Result<()> {
match service.command {
nym_cli_commands::validator::mixnet::operators::service::MixnetOperatorsServiceCommands::Announce(announce) => nym_cli_commands::validator::mixnet::operators::service::announce::announce(announce, create_signing_client(global_args, network_details)?).await,
nym_cli_commands::validator::mixnet::operators::service::MixnetOperatorsServiceCommands::Delete(delete) => nym_cli_commands::validator::mixnet::operators::service::delete::delete(delete, create_signing_client(global_args, network_details)?).await,
nym_cli_commands::validator::mixnet::operators::service::MixnetOperatorsServiceCommands::CreateServiceAnnounceSignPayload(args) => nym_cli_commands::validator::mixnet::operators::service::announce_sign_payload::create_payload(args, create_signing_client(global_args, network_details)?).await,
}
Ok(())
}
@@ -23,20 +23,6 @@ pub(crate) async fn execute(
)
.await
}
nym_cli_commands::validator::mixnet::query::MixnetQueryCommands::ServiceProviders(args) => {
nym_cli_commands::validator::mixnet::query::query_all_service_providers::query(
args,
&create_query_client_with_nym_api(network_details)?,
)
.await
}
nym_cli_commands::validator::mixnet::query::MixnetQueryCommands::Names(args) => {
nym_cli_commands::validator::mixnet::query::query_all_names::query(
args,
&create_query_client_with_nym_api(network_details)?,
)
.await
}
}
Ok(())
}