diff --git a/common/cosmwasm-smart-contracts/contracts-common/Cargo.toml b/common/cosmwasm-smart-contracts/contracts-common/Cargo.toml index fa8a511222..f137d19d66 100644 --- a/common/cosmwasm-smart-contracts/contracts-common/Cargo.toml +++ b/common/cosmwasm-smart-contracts/contracts-common/Cargo.toml @@ -23,4 +23,4 @@ serde_json = { workspace = true } vergen = { workspace = true, features = ["build", "git", "gitcl", "rustc", "cargo"] } [features] -naive_float = [] \ No newline at end of file +naive_float = [] diff --git a/common/cosmwasm-smart-contracts/mixnet-contract/src/reward_params.rs b/common/cosmwasm-smart-contracts/mixnet-contract/src/reward_params.rs index 40e34b2888..751b51e3b1 100644 --- a/common/cosmwasm-smart-contracts/mixnet-contract/src/reward_params.rs +++ b/common/cosmwasm-smart-contracts/mixnet-contract/src/reward_params.rs @@ -6,6 +6,7 @@ use crate::nym_node::Role; use crate::{error::MixnetContractError, Percent}; use cosmwasm_schema::cw_serde; use cosmwasm_std::Decimal; +use utoipa::ToSchema; pub type Performance = Percent; pub type WorkFactor = Decimal; @@ -20,32 +21,37 @@ pub type WorkFactor = Decimal; ) )] #[cw_serde] -#[derive(Copy)] +#[derive(Copy, ToSchema)] pub struct IntervalRewardParams { /// Current value of the rewarding pool. /// It is expected to be constant throughout the interval. #[cfg_attr(feature = "generate-ts", ts(type = "string"))] + #[schema(value_type = String)] pub reward_pool: Decimal, /// Current value of the staking supply. /// It is expected to be constant throughout the interval. #[cfg_attr(feature = "generate-ts", ts(type = "string"))] + #[schema(value_type = String)] pub staking_supply: Decimal, /// Defines the percentage of stake needed to reach saturation for all of the nodes in the rewarded set. /// Also known as `beta`. #[cfg_attr(feature = "generate-ts", ts(type = "string"))] + #[schema(value_type = String)] pub staking_supply_scale_factor: Percent, // computed values /// Current value of the computed reward budget per epoch, per node. /// It is expected to be constant throughout the interval. #[cfg_attr(feature = "generate-ts", ts(type = "string"))] + #[schema(value_type = String)] pub epoch_reward_budget: Decimal, /// Current value of the stake saturation point. /// It is expected to be constant throughout the interval. #[cfg_attr(feature = "generate-ts", ts(type = "string"))] + #[schema(value_type = String)] pub stake_saturation_point: Decimal, // constants(-ish) @@ -54,6 +60,7 @@ pub struct IntervalRewardParams { /// It is not really expected to be changing very often. /// As a matter of fact, unless there's a very specific reason, it should remain constant. #[cfg_attr(feature = "generate-ts", ts(type = "string"))] + #[schema(value_type = String)] pub sybil_resistance: Percent, // default: 10 @@ -61,6 +68,7 @@ pub struct IntervalRewardParams { /// It is not really expected to be changing very often. /// As a matter of fact, unless there's a very specific reason, it should remain constant. #[cfg_attr(feature = "generate-ts", ts(type = "string"))] + #[schema(value_type = String)] pub active_set_work_factor: Decimal, // default: 2% @@ -70,6 +78,7 @@ pub struct IntervalRewardParams { /// It is not really expected to be changing very often. /// As a matter of fact, unless there's a very specific reason, it should remain constant. #[cfg_attr(feature = "generate-ts", ts(type = "string"))] + #[schema(value_type = String)] pub interval_pool_emission: Percent, } @@ -89,7 +98,7 @@ impl IntervalRewardParams { ) )] #[cw_serde] -#[derive(Copy)] +#[derive(Copy, ToSchema)] pub struct RewardingParams { /// Parameters that should remain unchanged throughout an interval. pub interval: IntervalRewardParams, @@ -253,7 +262,7 @@ impl RewardingParams { ) )] #[cw_serde] -#[derive(Copy)] +#[derive(Copy, ToSchema)] pub struct RewardedSetParams { /// The expected number of nodes assigned entry gateway role (i.e. [`Role::EntryGateway`]) pub entry_gateways: u32, diff --git a/common/exit-policy/src/policy/address_policy.rs b/common/exit-policy/src/policy/address_policy.rs index 621fd291e9..eaf5ad01dd 100644 --- a/common/exit-policy/src/policy/address_policy.rs +++ b/common/exit-policy/src/policy/address_policy.rs @@ -727,10 +727,10 @@ mod test { let policy = AddressPolicy::parse_from_torrc( r#" ExitPolicy reject 1.2.3.4/32:* -ExitPolicy reject 1.2.3.5:* +ExitPolicy reject 1.2.3.5:* ExitPolicy reject 1.2.3.6/16:* -ExitPolicy reject 1.2.3.6/16:123-456 -ExitPolicy accept *:53 +ExitPolicy reject 1.2.3.6/16:123-456 +ExitPolicy accept *:53 ExitPolicy accept6 *6:119 ExitPolicy accept *4:120 ExitPolicy reject6 [FC00::]/7:* diff --git a/common/ticketbooks-merkle/src/lib.rs b/common/ticketbooks-merkle/src/lib.rs index 96cc5b8f5e..051e669b85 100644 --- a/common/ticketbooks-merkle/src/lib.rs +++ b/common/ticketbooks-merkle/src/lib.rs @@ -20,10 +20,12 @@ use time::Date; pub type DepositId = u32; pub type DKGEpochId = u64; -#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, JsonSchema)] +#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, JsonSchema, ToSchema)] #[serde(rename_all = "camelCase")] pub struct IssuedTicketbook { + #[schema(value_type = u32)] pub deposit_id: DepositId, + #[schema(value_type = u32)] pub epoch_id: DKGEpochId, // 96 bytes serialised 'BlindedSignature' @@ -38,9 +40,11 @@ pub struct IssuedTicketbook { #[schemars(with = "String")] #[serde(with = "nym_serde_helpers::date")] + #[schema(value_type = String)] pub expiration_date: Date, #[schemars(with = "String")] + #[schema(value_type = String)] pub ticketbook_type: TicketType, } diff --git a/nym-api/nym-api-requests/src/ecash/models.rs b/nym-api/nym-api-requests/src/ecash/models.rs index a865e9b1c5..64c65753f2 100644 --- a/nym-api/nym-api-requests/src/ecash/models.rs +++ b/nym-api/nym-api-requests/src/ecash/models.rs @@ -27,10 +27,12 @@ use utoipa::ToSchema; pub struct VerifyEcashTicketBody { /// The cryptographic material required for spending the underlying credential. #[schemars(with = "PlaceholderJsonSchemaImpl")] + #[schema(value_type = String)] pub credential: CredentialSpendingData, /// Cosmos address of the sender of the credential #[schemars(with = "String")] + #[schema(value_type = String)] pub gateway_cosmos_addr: AccountId, } @@ -62,8 +64,16 @@ impl VerifyEcashCredentialBody { } } +/// Used exclusively as part of OpenAPI docs +#[derive(ToSchema)] +pub enum EcashTicketVerificationResult { + Ok(()), + EcashTicketVerificationRejection +} + #[derive(Debug, Serialize, Deserialize, JsonSchema, ToSchema)] pub struct EcashTicketVerificationResponse { + #[schema(value_type = EcashTicketVerificationResult)] pub verified: Result<(), EcashTicketVerificationRejection>, } @@ -81,12 +91,15 @@ pub enum EcashTicketVerificationRejection { InvalidSpentDate { #[schemars(with = "String")] #[serde(with = "crate::helpers::date_serde")] + #[schema(value_type = String)] today: Date, #[schemars(with = "String")] #[serde(with = "crate::helpers::date_serde")] + #[schema(value_type = String)] yesterday: Date, #[schemars(with = "String")] #[serde(with = "crate::helpers::date_serde")] + #[schema(value_type = String)] received: Date, }, @@ -120,13 +133,16 @@ pub struct BlindSignRequestBody { pub signature: identity::Signature, #[schemars(with = "PlaceholderJsonSchemaImpl")] + #[schema(value_type = G1ProjectiveSchema)] pub ecash_pubkey: PublicKeyUser, #[schemars(with = "String")] #[serde(with = "crate::helpers::date_serde")] + #[schema(value_type = String)] pub expiration_date: Date, #[schemars(with = "String")] + #[schema(value_type = String)] pub ticketbook_type: TicketType, } @@ -403,6 +419,7 @@ pub type DepositId = u32; #[derive(Clone, Serialize, Deserialize, Debug, JsonSchema, ToSchema, PartialEq, Eq)] #[serde(rename_all = "camelCase")] pub struct CommitedDeposit { + #[schema(value_type = u32)] pub deposit_id: DepositId, pub merkle_index: usize, } @@ -455,7 +472,9 @@ impl IssuedTicketbooksForResponse { pub struct IssuedTicketbooksChallengeRequest { #[schemars(with = "String")] #[serde(with = "crate::helpers::date_serde")] + #[schema(value_type = String)] pub expiration_date: Date, + #[schema(value_type = Vec)] pub deposits: Vec, } @@ -464,8 +483,10 @@ pub struct IssuedTicketbooksChallengeRequest { pub struct IssuedTicketbooksChallengeResponseBody { #[schemars(with = "String")] #[serde(with = "crate::helpers::date_serde")] + #[schema(value_type = String)] pub expiration_date: Date, + #[schema(value_type = BTreeMap)] pub partial_ticketbooks: BTreeMap, pub merkle_proof: IssuedTicketbooksFullMerkleProof, } @@ -499,7 +520,7 @@ impl IssuedTicketbooksChallengeResponseBody { } } -#[derive(Serialize, Deserialize, JsonSchema, ToSchema, Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, ToSchema)] #[serde(rename_all = "camelCase")] pub struct IssuedTicketbooksChallengeResponse { pub body: IssuedTicketbooksChallengeResponseBody, diff --git a/nym-api/nym-api-requests/src/models.rs b/nym-api/nym-api-requests/src/models.rs index 1c233236e2..9fad6e448f 100644 --- a/nym-api/nym-api-requests/src/models.rs +++ b/nym-api/nym-api-requests/src/models.rs @@ -143,7 +143,7 @@ pub struct NodePerformance { pub last_24h: Performance, } -#[derive(Serialize, Deserialize, Debug, Clone, Copy, Hash, JsonSchema)] +#[derive(Serialize, Deserialize, Debug, Clone, Copy, Hash, JsonSchema, ToSchema)] #[serde(rename_all = "camelCase")] #[cfg_attr(feature = "generate-ts", derive(ts_rs::TS))] #[cfg_attr( @@ -188,7 +188,7 @@ impl From for Role { // imo for now there's no point in exposing more than that, // nym-api shouldn't be calculating apy or stake saturation for you. // it should just return its own metrics (performance) and then you can do with it as you wish -#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, JsonSchema)] +#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, JsonSchema, ToSchema)] #[cfg_attr(feature = "generate-ts", derive(ts_rs::TS))] #[cfg_attr( feature = "generate-ts", @@ -200,13 +200,14 @@ impl From for Role { pub struct NodeAnnotation { #[cfg_attr(feature = "generate-ts", ts(type = "string"))] // legacy + #[schema(value_type = String)] pub last_24h_performance: Performance, pub current_role: Option, pub detailed_performance: DetailedNodePerformance, } -#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, JsonSchema)] +#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, JsonSchema, ToSchema)] #[cfg_attr(feature = "generate-ts", derive(ts_rs::TS))] #[cfg_attr( feature = "generate-ts", @@ -242,7 +243,7 @@ impl DetailedNodePerformance { } } -#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, JsonSchema)] +#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, JsonSchema, ToSchema)] #[cfg_attr(feature = "generate-ts", derive(ts_rs::TS))] #[cfg_attr( feature = "generate-ts", @@ -264,7 +265,7 @@ impl RoutingScore { } } -#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, JsonSchema)] +#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, JsonSchema, ToSchema)] #[cfg_attr(feature = "generate-ts", derive(ts_rs::TS))] #[cfg_attr( feature = "generate-ts", @@ -823,6 +824,7 @@ pub struct CirculatingSupplyResponse { #[derive(Clone, Debug, Serialize, Deserialize, schemars::JsonSchema, ToSchema)] pub struct HostInformation { + #[schema(value_type = Vec)] pub ip_address: Vec, pub hostname: Option, pub keys: HostKeys, @@ -842,15 +844,18 @@ impl From for HostInf pub struct HostKeys { #[serde(with = "bs58_ed25519_pubkey")] #[schemars(with = "String")] + #[schema(value_type = String)] pub ed25519: ed25519::PublicKey, #[serde(with = "bs58_x25519_pubkey")] #[schemars(with = "String")] + #[schema(value_type = String)] pub x25519: x25519::PublicKey, #[serde(default)] #[serde(with = "option_bs58_x25519_pubkey")] #[schemars(with = "Option")] + #[schema(value_type = String)] pub x25519_noise: Option, } @@ -894,6 +899,7 @@ pub struct OffsetDateTimeJsonSchemaWrapper( default = "unix_epoch", with = "crate::helpers::overengineered_offset_date_time_serde" )] + #[schema(value_type = String)] pub OffsetDateTime, ); @@ -1283,12 +1289,14 @@ pub struct NoiseDetails { pub struct NodeRefreshBody { #[serde(with = "bs58_ed25519_pubkey")] #[schemars(with = "String")] + #[schema(value_type = String)] pub node_identity: ed25519::PublicKey, // a poor man's nonce pub request_timestamp: i64, #[schemars(with = "PlaceholderJsonSchemaImpl")] + #[schema(value_type = String)] pub signature: ed25519::Signature, } diff --git a/nym-api/nym-api-requests/src/nym_nodes.rs b/nym-api/nym-api-requests/src/nym_nodes.rs index fcfd09c2be..432f87846d 100644 --- a/nym-api/nym-api-requests/src/nym_nodes.rs +++ b/nym-api/nym-api-requests/src/nym_nodes.rs @@ -35,7 +35,7 @@ impl CachedNodesResponse { } } -#[derive(Clone, Debug, Serialize, Deserialize, schemars::JsonSchema)] +#[derive(Clone, Debug, Serialize, Deserialize, schemars::JsonSchema, ToSchema)] pub struct PaginatedCachedNodesResponse { pub refreshed_at: OffsetDateTimeJsonSchemaWrapper, pub nodes: PaginatedResponse, diff --git a/nym-api/src/network/handlers.rs b/nym-api/src/network/handlers.rs index 7bb77bc3fc..e04e20b578 100644 --- a/nym-api/src/network/handlers.rs +++ b/nym-api/src/network/handlers.rs @@ -47,12 +47,20 @@ pub(crate) struct ContractVersionSchemaResponse { pub version: String, } +#[allow(dead_code)] // not dead, used in OpenAPI docs +#[derive(ToSchema)] +pub struct ContractInformationContractVersion { + pub(crate) address: Option, + pub(crate) details: Option, +} + + #[utoipa::path( tag = "network", get, path = "/v1/network/nym-contracts", responses( - (status = 200, body = HashMap>) + (status = 200, body = HashMap) ) )] async fn nym_contracts( @@ -73,12 +81,19 @@ async fn nym_contracts( .into() } +#[allow(dead_code)] // not dead, used in OpenAPI docs +#[derive(ToSchema)] +pub struct ContractInformationBuildInformation { + pub(crate) address: Option, + pub(crate) details: Option, +} + #[utoipa::path( tag = "network", get, path = "/v1/network/nym-contracts-detailed", responses( - (status = 200, body = HashMap>) + (status = 200, body = HashMap) ) )] async fn nym_contracts_detailed( diff --git a/nym-api/src/network/models.rs b/nym-api/src/network/models.rs index 66d0324c26..1819ce024d 100644 --- a/nym-api/src/network/models.rs +++ b/nym-api/src/network/models.rs @@ -4,8 +4,9 @@ use nym_config::defaults::NymNetworkDetails; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; +use utoipa::ToSchema; -#[derive(Clone, Serialize, Deserialize, JsonSchema, utoipa::ToSchema)] +#[derive(Clone, Serialize, Deserialize, JsonSchema, ToSchema)] pub struct NetworkDetails { pub(crate) connected_nyxd: String, pub(crate) network: NymNetworkDetails, @@ -20,7 +21,7 @@ impl NetworkDetails { } } -#[derive(Clone, Serialize, Deserialize, JsonSchema, utoipa::ToSchema)] +#[derive(Clone, Serialize, Deserialize, JsonSchema, ToSchema)] #[serde(rename_all = "snake_case")] pub struct ContractInformation { pub(crate) address: Option, diff --git a/nym-api/src/node_status_api/models.rs b/nym-api/src/node_status_api/models.rs index c7435eb732..8bbfbff485 100644 --- a/nym-api/src/node_status_api/models.rs +++ b/nym-api/src/node_status_api/models.rs @@ -319,6 +319,7 @@ pub(crate) type AxumResult = Result; #[derive(ToSchema, ToResponse)] #[schema(title = "ErrorResponse")] +#[schema(as = ErrorResponse)] pub(crate) struct AxumErrorResponse { message: RequestError, #[schema(value_type = u16)] diff --git a/nym-api/src/support/http/helpers.rs b/nym-api/src/support/http/helpers.rs index 4ea95d4cd2..92f6d5585a 100644 --- a/nym-api/src/support/http/helpers.rs +++ b/nym-api/src/support/http/helpers.rs @@ -14,6 +14,8 @@ pub struct PaginationRequest { } #[derive(Deserialize, IntoParams, ToSchema)] +#[schema(title = "NodeId")] +#[schema(as = NodeId)] #[into_params(parameter_in = Path)] pub(crate) struct NodeIdParam { #[schema(value_type = u32)] diff --git a/nym-api/src/support/http/openapi.rs b/nym-api/src/support/http/openapi.rs index e216912b71..f17f27553a 100644 --- a/nym-api/src/support/http/openapi.rs +++ b/nym-api/src/support/http/openapi.rs @@ -17,8 +17,8 @@ use utoipauto::utoipauto; #[utoipauto(paths = "./nym-api/src, ./nym-api/nym-api-requests/src from nym-api-requests, - ./common/nym_offline_compact_ecash/src from nym-compact-ecash, ./common/config/src from nym-config, + ./common/cosmwasm-smart-contracts/mixnet-contract/src from nym-mixnet-contract-common, ./common/ticketbooks-merkle/src from nym-ticketbooks-merkle, ./common/nym_offline_compact_ecash/src from nym_compact_ecash")] #[derive(OpenApi)]