diff --git a/common/cosmwasm-smart-contracts/service-provider-directory/Cargo.toml b/common/cosmwasm-smart-contracts/service-provider-directory/Cargo.toml deleted file mode 100644 index 341c985e34..0000000000 --- a/common/cosmwasm-smart-contracts/service-provider-directory/Cargo.toml +++ /dev/null @@ -1,19 +0,0 @@ -[package] -name = "nym-service-provider-directory-common" -version = "0.1.0" -edition = "2021" -license.workspace = true - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -cosmwasm-schema = { workspace = true } -cosmwasm-std = { workspace = true } -cw2 = { workspace = true, optional = true } -cw-controllers = { workspace = true } -cw-utils = { workspace = true } -nym-contracts-common = { path = "../contracts-common", version = "0.5.0" } -thiserror = { workspace = true } - -[features] -schema = ["cw2"] diff --git a/common/cosmwasm-smart-contracts/service-provider-directory/src/error.rs b/common/cosmwasm-smart-contracts/service-provider-directory/src/error.rs deleted file mode 100644 index 9d103be9c8..0000000000 --- a/common/cosmwasm-smart-contracts/service-provider-directory/src/error.rs +++ /dev/null @@ -1,68 +0,0 @@ -use cosmwasm_std::{Addr, StdError}; -use cw_controllers::AdminError; -use nym_contracts_common::signing::verifier::ApiVerifierError; -use thiserror::Error; - -use crate::{NymAddress, ServiceId}; - -#[derive(Error, Debug, PartialEq)] -pub enum SpContractError { - #[error("{0}")] - Std(#[from] StdError), - - #[error("{0}")] - AdminError(#[from] AdminError), - - #[error("service not found: {service_id}")] - NotFound { service_id: ServiceId }, - - #[error("{sender} is not announcer of service")] - Unauthorized { sender: Addr }, - - #[error("deposit required to announce service")] - DepositRequired { source: cw_utils::PaymentError }, - - #[error("insufficiant deposit: {funds}, required: {deposit_required}")] - InsufficientDeposit { - funds: cosmwasm_std::Uint128, - deposit_required: cosmwasm_std::Uint128, - }, - - #[error("deposit too large: {funds}, required: {deposit_required}")] - TooLargeDeposit { - funds: cosmwasm_std::Uint128, - deposit_required: cosmwasm_std::Uint128, - }, - - #[error("reached the max number of providers ({max_providers}) for announcer {announcer}")] - ReachedMaxProvidersForAdmin { max_providers: u32, announcer: Addr }, - - #[error("reached the max number of aliases ({max_aliases}) for nym address {0}", nym_address.to_string())] - ReachedMaxAliasesForNymAddress { - max_aliases: u32, - nym_address: NymAddress, - }, - - #[error("failed to parse {value} into a valid SemVer version: {error_message}")] - SemVerFailure { - value: String, - error_message: String, - }, - - #[error("Failed to recover ed25519 public key from its base58 representation - {0}")] - MalformedEd25519IdentityKey(String), - - #[error("Failed to recover ed25519 signature from its base58 representation - {0}")] - MalformedEd25519Signature(String), - - #[error("Provided ed25519 signature did not verify correctly")] - InvalidEd25519Signature, - - #[error("failed to verify message signature: {source}")] - SignatureVerificationFailure { - #[from] - source: ApiVerifierError, - }, -} - -pub type Result = std::result::Result; diff --git a/common/cosmwasm-smart-contracts/service-provider-directory/src/events.rs b/common/cosmwasm-smart-contracts/service-provider-directory/src/events.rs deleted file mode 100644 index 80ce9c3593..0000000000 --- a/common/cosmwasm-smart-contracts/service-provider-directory/src/events.rs +++ /dev/null @@ -1,58 +0,0 @@ -use cosmwasm_std::{Coin, Event}; - -use crate::{Service, ServiceId}; - -pub enum ServiceProviderEventType { - Announce, - DeleteId, - DeleteNymAddress, - UpdateDepositRequired, -} - -impl std::fmt::Display for ServiceProviderEventType { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - ServiceProviderEventType::Announce => write!(f, "announce"), - ServiceProviderEventType::DeleteId => write!(f, "delete_id"), - ServiceProviderEventType::DeleteNymAddress => write!(f, "delete_nym_address"), - ServiceProviderEventType::UpdateDepositRequired => write!(f, "update_deposit_required"), - } - } -} - -impl From for String { - fn from(event_type: ServiceProviderEventType) -> Self { - event_type.to_string() - } -} - -pub const ACTION: &str = "action"; - -pub const SERVICE_ID: &str = "service_id"; -pub const SERVICE_TYPE: &str = "service_type"; -pub const NYM_ADDRESS: &str = "nym_address"; -pub const OWNER: &str = "owner"; - -pub const DEPOSIT_REQUIRED: &str = "deposit_required"; - -pub fn new_announce_event(service_id: ServiceId, service: Service) -> Event { - Event::new(ServiceProviderEventType::Announce) - .add_attribute(ACTION, ServiceProviderEventType::Announce) - .add_attribute(SERVICE_ID, service_id.to_string()) - .add_attribute(SERVICE_TYPE, service.service.service_type.to_string()) - .add_attribute(NYM_ADDRESS, service.service.nym_address.to_string()) - .add_attribute(OWNER, service.announcer.to_string()) -} - -pub fn new_delete_id_event(service: Service) -> Event { - Event::new(ServiceProviderEventType::DeleteId) - .add_attribute(ACTION, ServiceProviderEventType::DeleteId) - .add_attribute(SERVICE_ID, service.service_id.to_string()) - .add_attribute(NYM_ADDRESS, service.service.nym_address.to_string()) -} - -pub fn new_update_deposit_required_event(deposit_required: Coin) -> Event { - Event::new(ServiceProviderEventType::UpdateDepositRequired) - .add_attribute(ACTION, ServiceProviderEventType::UpdateDepositRequired) - .add_attribute(DEPOSIT_REQUIRED, deposit_required.to_string()) -} diff --git a/common/cosmwasm-smart-contracts/service-provider-directory/src/lib.rs b/common/cosmwasm-smart-contracts/service-provider-directory/src/lib.rs deleted file mode 100644 index 71a702b7c1..0000000000 --- a/common/cosmwasm-smart-contracts/service-provider-directory/src/lib.rs +++ /dev/null @@ -1,11 +0,0 @@ -pub mod error; -pub mod events; -pub mod msg; -pub mod response; -pub mod signing_types; -pub mod types; - -// Re-export all types at the top-level -pub use types::*; - -pub use cosmwasm_std::{Addr, Coin, Decimal, Fraction}; diff --git a/common/cosmwasm-smart-contracts/service-provider-directory/src/msg.rs b/common/cosmwasm-smart-contracts/service-provider-directory/src/msg.rs deleted file mode 100644 index 0c7928e079..0000000000 --- a/common/cosmwasm-smart-contracts/service-provider-directory/src/msg.rs +++ /dev/null @@ -1,118 +0,0 @@ -// Copyright 2023 - Nym Technologies SA -// SPDX-License-Identifier: Apache-2.0 - -use crate::{NymAddress, ServiceDetails, ServiceId}; -use cosmwasm_schema::cw_serde; -use cosmwasm_std::Coin; -use nym_contracts_common::signing::MessageSignature; - -#[cfg(feature = "schema")] -use crate::{ - response::{ConfigResponse, PagedServicesListResponse, ServicesListResponse}, - types::Service, -}; -#[cfg(feature = "schema")] -use cosmwasm_schema::QueryResponses; -#[cfg(feature = "schema")] -use nym_contracts_common::{signing::Nonce, ContractBuildInformation}; - -#[cw_serde] -pub struct InstantiateMsg { - pub deposit_required: Coin, -} - -impl InstantiateMsg { - pub fn new(deposit_required: Coin) -> Self { - Self { deposit_required } - } -} - -#[cw_serde] -pub struct MigrateMsg {} - -#[cw_serde] -pub enum ExecuteMsg { - Announce { - service: ServiceDetails, - owner_signature: MessageSignature, - }, - DeleteId { - service_id: ServiceId, - }, - DeleteNymAddress { - nym_address: NymAddress, - }, - UpdateDepositRequired { - deposit_required: Coin, - }, -} - -impl ExecuteMsg { - pub fn delete_id(service_id: ServiceId) -> Self { - ExecuteMsg::DeleteId { service_id } - } - - pub fn default_memo(&self) -> String { - match self { - ExecuteMsg::Announce { - service, - owner_signature: _, - } => format!( - "announcing {} as type {}", - service.nym_address, service.service_type - ), - ExecuteMsg::DeleteId { service_id } => { - format!("deleting service with service id {service_id}") - } - ExecuteMsg::DeleteNymAddress { nym_address } => { - format!("deleting service with nym address {nym_address}") - } - ExecuteMsg::UpdateDepositRequired { deposit_required } => { - format!("updating the deposit required to {deposit_required}") - } - } - } -} - -#[cw_serde] -#[cfg_attr(feature = "schema", derive(QueryResponses))] -pub enum QueryMsg { - #[cfg_attr(feature = "schema", returns(Service))] - ServiceId { service_id: ServiceId }, - - #[cfg_attr(feature = "schema", returns(ServicesListResponse))] - ByAnnouncer { announcer: String }, - - #[cfg_attr(feature = "schema", returns(ServicesListResponse))] - ByNymAddress { nym_address: NymAddress }, - - #[cfg_attr(feature = "schema", returns(PagedServicesListResponse))] - All { - limit: Option, - start_after: Option, - }, - - #[cfg_attr(feature = "schema", returns(Nonce))] - SigningNonce { address: String }, - - #[cfg_attr(feature = "schema", returns(ConfigResponse))] - Config {}, - - /// Gets build information of this contract, such as the commit hash used for the build or rustc version. - #[cfg_attr(feature = "schema", returns(ContractBuildInformation))] - GetContractVersion {}, - - /// Gets the stored contract version information that's required by the CW2 spec interface for migrations. - #[serde(rename = "get_cw2_contract_version")] - #[cfg_attr(feature = "schema", returns(cw2::ContractVersion))] - GetCW2ContractVersion {}, -} - -impl QueryMsg { - pub fn all() -> QueryMsg { - QueryMsg::All { - limit: None, - start_after: None, - } - } -} diff --git a/common/cosmwasm-smart-contracts/service-provider-directory/src/response.rs b/common/cosmwasm-smart-contracts/service-provider-directory/src/response.rs deleted file mode 100644 index dd9392c2d9..0000000000 --- a/common/cosmwasm-smart-contracts/service-provider-directory/src/response.rs +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2023 - Nym Technologies SA -// SPDX-License-Identifier: Apache-2.0 - -use crate::{Service, ServiceId}; -use cosmwasm_schema::cw_serde; -use cosmwasm_std::Coin; - -#[cw_serde] -pub struct ServiceInfoResponse { - pub service_id: ServiceId, - pub service: Option, -} - -#[cw_serde] -pub struct ServicesListResponse { - pub services: Vec, -} - -impl ServicesListResponse { - pub fn new(services: Vec) -> ServicesListResponse { - ServicesListResponse { services } - } -} - -impl From<&[Service]> for ServicesListResponse { - fn from(services: &[Service]) -> Self { - Self { - services: services.to_vec(), - } - } -} - -#[cw_serde] -pub struct PagedServicesListResponse { - pub services: Vec, - pub per_page: usize, - - /// Field indicating paging information for the following queries if the caller wishes to get further entries. - pub start_next_after: Option, -} - -impl PagedServicesListResponse { - pub fn new( - services: Vec, - per_page: usize, - start_next_after: Option, - ) -> PagedServicesListResponse { - PagedServicesListResponse { - services, - per_page, - start_next_after, - } - } -} - -#[cw_serde] -pub struct ConfigResponse { - pub deposit_required: Coin, -} diff --git a/common/cosmwasm-smart-contracts/service-provider-directory/src/signing_types.rs b/common/cosmwasm-smart-contracts/service-provider-directory/src/signing_types.rs deleted file mode 100644 index fb9752d10a..0000000000 --- a/common/cosmwasm-smart-contracts/service-provider-directory/src/signing_types.rs +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2023 - Nym Technologies SA -// SPDX-License-Identifier: Apache-2.0 - -use crate::ServiceDetails; -use cosmwasm_schema::cw_serde; -use cosmwasm_std::{Addr, Coin}; -use nym_contracts_common::signing::{ - ContractMessageContent, MessageType, Nonce, SignableMessage, SigningPurpose, -}; - -pub type SignableServiceProviderAnnounceMsg = - SignableMessage>; - -#[cw_serde] -pub struct ServiceProviderAnnounce { - service: ServiceDetails, -} - -impl SigningPurpose for ServiceProviderAnnounce { - fn message_type() -> MessageType { - MessageType::new("service-provider-announce") - } -} - -pub fn construct_service_provider_announce_sign_payload( - nonce: Nonce, - sender: Addr, - deposit: Coin, - service: ServiceDetails, -) -> SignableServiceProviderAnnounceMsg { - let payload = ServiceProviderAnnounce { service }; - let proxy = None; - let content = ContractMessageContent::new(sender, proxy, vec![deposit], payload); - SignableMessage::new(nonce, content) -} diff --git a/common/cosmwasm-smart-contracts/service-provider-directory/src/types.rs b/common/cosmwasm-smart-contracts/service-provider-directory/src/types.rs deleted file mode 100644 index 845c05b768..0000000000 --- a/common/cosmwasm-smart-contracts/service-provider-directory/src/types.rs +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright 2023 - Nym Technologies SA -// SPDX-License-Identifier: Apache-2.0 - -use cosmwasm_schema::cw_serde; -use cosmwasm_std::{Addr, Coin}; -use nym_contracts_common::IdentityKey; -use std::fmt::{Display, Formatter}; - -/// The directory of services are indexed by [`ServiceId`]. -pub type ServiceId = u32; - -#[cw_serde] -pub struct Service { - /// Unique id assigned to the anounced service. - pub service_id: ServiceId, - /// The announced service. - pub service: ServiceDetails, - /// Address of the service owner. - pub announcer: Addr, - /// Block height at which the service was added. - pub block_height: u64, - /// The deposit used to announce the service. - pub deposit: Coin, -} - -#[cw_serde] -pub struct ServiceDetails { - /// The address of the service. - pub nym_address: NymAddress, - /// The service type. - pub service_type: ServiceType, - /// The identity key of the service. - pub identity_key: IdentityKey, -} - -/// The types of addresses supported. -#[cw_serde] -pub enum NymAddress { - /// String representation of a nym address, which is of the form - /// client_id.client_enc@gateway_id. - Address(String), - // String name that can looked up in the nym-name-service contract (once it exists) - //Name(String), -} - -impl NymAddress { - /// Create a new nym address. - pub fn new(address: &str) -> Self { - Self::Address(address.to_string()) - } - - pub fn as_str(&self) -> &str { - match self { - NymAddress::Address(address) => address, - //NymAddress::Name(name) => name, - } - } -} - -impl Display for NymAddress { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self.as_str()) - } -} - -/// The type of services provider supported -#[cw_serde] -pub enum ServiceType { - NetworkRequester, -} - -impl std::fmt::Display for ServiceType { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let service_type = match self { - ServiceType::NetworkRequester => "network_requester", - }; - write!(f, "{service_type}") - } -}