Skip to main content

nym_api_requests/models/
node_status.rs

1// Copyright 2025 - Nym Technologies SA <contact@nymtech.net>
2// SPDX-License-Identifier: Apache-2.0
3
4use crate::helpers::PlaceholderJsonSchemaImpl;
5use crate::models::{CoinSchema, DisplayRole};
6use crate::pagination::PaginatedResponse;
7use cosmwasm_std::{Coin, Decimal};
8use nym_contracts_common::{IdentityKey, NaiveFloat};
9use nym_crypto::asymmetric::ed25519;
10use nym_crypto::asymmetric::ed25519::serde_helpers::bs58_ed25519_pubkey;
11use nym_mixnet_contract_common::reward_params::Performance;
12use nym_mixnet_contract_common::NodeId;
13use schemars::JsonSchema;
14use serde::{Deserialize, Serialize};
15use std::time::Duration;
16use time::{Date, OffsetDateTime};
17use utoipa::ToSchema;
18
19pub use config_score::*;
20
21pub type StakeSaturation = Decimal;
22
23#[derive(Clone, Copy, Debug, Serialize, Deserialize, JsonSchema, ToSchema)]
24#[cfg_attr(feature = "generate-ts", derive(ts_rs::TS))]
25#[cfg_attr(
26    feature = "generate-ts",
27    ts(
28        export,
29        export_to = "ts-packages/types/src/types/rust/StakeSaturationResponse.ts"
30    )
31)]
32pub struct StakeSaturationResponse {
33    #[cfg_attr(feature = "generate-ts", ts(type = "string"))]
34    #[schema(value_type = String)]
35    pub saturation: StakeSaturation,
36
37    #[cfg_attr(feature = "generate-ts", ts(type = "string"))]
38    #[schema(value_type = String)]
39    pub uncapped_saturation: StakeSaturation,
40    pub as_at: i64,
41}
42
43pub mod config_score {
44    use nym_contracts_common::NaiveFloat;
45    use serde::{Deserialize, Serialize};
46    use std::cmp::Ordering;
47    use utoipa::ToSchema;
48
49    #[derive(Clone, Debug, Serialize, Deserialize, schemars::JsonSchema, ToSchema)]
50    pub struct ConfigScoreDataResponse {
51        pub parameters: ConfigScoreParams,
52        pub version_history: Vec<HistoricalNymNodeVersionEntry>,
53    }
54
55    #[derive(Clone, Debug, Serialize, Deserialize, schemars::JsonSchema, ToSchema, PartialEq)]
56    pub struct HistoricalNymNodeVersionEntry {
57        /// The unique, ordered, id of this particular entry
58        pub id: u32,
59
60        /// Data associated with this particular version
61        pub version_information: HistoricalNymNodeVersion,
62    }
63
64    impl PartialOrd for HistoricalNymNodeVersionEntry {
65        fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
66            // we only care about id for the purposes of ordering as they should have unique data
67            self.id.partial_cmp(&other.id)
68        }
69    }
70
71    impl From<nym_mixnet_contract_common::HistoricalNymNodeVersionEntry>
72        for HistoricalNymNodeVersionEntry
73    {
74        fn from(value: nym_mixnet_contract_common::HistoricalNymNodeVersionEntry) -> Self {
75            HistoricalNymNodeVersionEntry {
76                id: value.id,
77                version_information: value.version_information.into(),
78            }
79        }
80    }
81
82    #[derive(Clone, Debug, Serialize, Deserialize, schemars::JsonSchema, ToSchema, PartialEq)]
83    pub struct HistoricalNymNodeVersion {
84        /// Version of the nym node that is going to be used for determining the version score of a node.
85        /// note: value stored here is pre-validated `semver::Version`
86        pub semver: String,
87
88        /// Block height of when this version has been added to the contract
89        pub introduced_at_height: u64,
90        // for now ignore that field. it will give nothing useful to the users
91        //     pub difference_since_genesis: TotalVersionDifference,
92    }
93
94    impl From<nym_mixnet_contract_common::HistoricalNymNodeVersion> for HistoricalNymNodeVersion {
95        fn from(value: nym_mixnet_contract_common::HistoricalNymNodeVersion) -> Self {
96            HistoricalNymNodeVersion {
97                semver: value.semver,
98                introduced_at_height: value.introduced_at_height,
99            }
100        }
101    }
102
103    #[derive(Clone, Debug, Serialize, Deserialize, schemars::JsonSchema, ToSchema)]
104    pub struct ConfigScoreParams {
105        /// Defines weights for calculating numbers of versions behind the current release.
106        pub version_weights: OutdatedVersionWeights,
107
108        /// Defines the parameters of the formula for calculating the version score
109        pub version_score_formula_params: VersionScoreFormulaParams,
110    }
111
112    /// Defines weights for calculating numbers of versions behind the current release.
113    #[derive(Clone, Debug, Serialize, Deserialize, schemars::JsonSchema, ToSchema)]
114    pub struct OutdatedVersionWeights {
115        pub major: u32,
116        pub minor: u32,
117        pub patch: u32,
118        pub prerelease: u32,
119    }
120
121    /// Given the formula of version_score = penalty ^ (versions_behind_factor ^ penalty_scaling)
122    /// define the relevant parameters
123    #[derive(Clone, Debug, Serialize, Deserialize, schemars::JsonSchema, ToSchema)]
124    pub struct VersionScoreFormulaParams {
125        pub penalty: f64,
126        pub penalty_scaling: f64,
127    }
128
129    impl From<nym_mixnet_contract_common::ConfigScoreParams> for ConfigScoreParams {
130        fn from(value: nym_mixnet_contract_common::ConfigScoreParams) -> Self {
131            ConfigScoreParams {
132                version_weights: value.version_weights.into(),
133                version_score_formula_params: value.version_score_formula_params.into(),
134            }
135        }
136    }
137
138    impl From<nym_mixnet_contract_common::OutdatedVersionWeights> for OutdatedVersionWeights {
139        fn from(value: nym_mixnet_contract_common::OutdatedVersionWeights) -> Self {
140            OutdatedVersionWeights {
141                major: value.major,
142                minor: value.minor,
143                patch: value.patch,
144                prerelease: value.prerelease,
145            }
146        }
147    }
148
149    impl From<nym_mixnet_contract_common::VersionScoreFormulaParams> for VersionScoreFormulaParams {
150        fn from(value: nym_mixnet_contract_common::VersionScoreFormulaParams) -> Self {
151            VersionScoreFormulaParams {
152                penalty: value.penalty.naive_to_f64(),
153                penalty_scaling: value.penalty_scaling.naive_to_f64(),
154            }
155        }
156    }
157}
158
159#[derive(Clone, Debug, Serialize, Deserialize, schemars::JsonSchema, ToSchema)]
160pub struct NodeRefreshBody {
161    #[serde(with = "bs58_ed25519_pubkey")]
162    #[schemars(with = "String")]
163    #[schema(value_type = String)]
164    pub node_identity: ed25519::PublicKey,
165
166    // a poor man's nonce
167    pub request_timestamp: i64,
168
169    #[schemars(with = "PlaceholderJsonSchemaImpl")]
170    #[schema(value_type = String)]
171    pub signature: ed25519::Signature,
172}
173
174impl NodeRefreshBody {
175    pub fn plaintext(node_identity: ed25519::PublicKey, request_timestamp: i64) -> Vec<u8> {
176        node_identity
177            .to_bytes()
178            .into_iter()
179            .chain(request_timestamp.to_be_bytes())
180            .chain(b"describe-cache-refresh-request".iter().copied())
181            .collect()
182    }
183
184    pub fn new(private_key: &ed25519::PrivateKey) -> Self {
185        let node_identity = private_key.public_key();
186        let request_timestamp = OffsetDateTime::now_utc().unix_timestamp();
187        let signature = private_key.sign(Self::plaintext(node_identity, request_timestamp));
188        NodeRefreshBody {
189            node_identity,
190            request_timestamp,
191            signature,
192        }
193    }
194
195    pub fn verify_signature(&self) -> bool {
196        self.node_identity
197            .verify(
198                Self::plaintext(self.node_identity, self.request_timestamp),
199                &self.signature,
200            )
201            .is_ok()
202    }
203
204    pub fn is_stale(&self) -> bool {
205        let Ok(encoded) = OffsetDateTime::from_unix_timestamp(self.request_timestamp) else {
206            return true;
207        };
208        let now = OffsetDateTime::now_utc();
209
210        if encoded > now {
211            return true;
212        }
213
214        if (encoded + Duration::from_secs(30)) < now {
215            return true;
216        }
217
218        false
219    }
220}
221
222#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, ToSchema)]
223pub struct UptimeResponse {
224    #[schema(value_type = u32)]
225    pub mix_id: NodeId,
226    // The same as node_performance.last_24h. Legacy
227    pub avg_uptime: u8,
228    pub node_performance: NodePerformance,
229}
230
231#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, ToSchema)]
232pub struct GatewayUptimeResponse {
233    pub identity: String,
234    // The same as node_performance.last_24h. Legacy
235    pub avg_uptime: u8,
236    pub node_performance: NodePerformance,
237}
238
239type Uptime = u8;
240
241#[derive(Clone, Serialize, Deserialize, schemars::JsonSchema, ToSchema)]
242pub struct MixnodeStatusReportResponse {
243    pub mix_id: NodeId,
244    pub identity: IdentityKey,
245    pub owner: String,
246    #[schema(value_type = u8)]
247    pub most_recent: Uptime,
248    #[schema(value_type = u8)]
249    pub last_hour: Uptime,
250    #[schema(value_type = u8)]
251    pub last_day: Uptime,
252}
253
254#[derive(Clone, Serialize, Deserialize, schemars::JsonSchema, ToSchema)]
255pub struct GatewayStatusReportResponse {
256    pub identity: String,
257    pub owner: String,
258    #[schema(value_type = u8)]
259    pub most_recent: Uptime,
260    #[schema(value_type = u8)]
261    pub last_hour: Uptime,
262    #[schema(value_type = u8)]
263    pub last_day: Uptime,
264}
265
266#[derive(Serialize, Deserialize, schemars::JsonSchema, ToSchema)]
267#[cfg_attr(feature = "generate-ts", derive(ts_rs::TS))]
268#[cfg_attr(
269    feature = "generate-ts",
270    ts(
271        export,
272        export_to = "ts-packages/types/src/types/rust/PerformanceHistoryResponse.ts"
273    )
274)]
275pub struct PerformanceHistoryResponse {
276    #[schema(value_type = u32)]
277    pub node_id: NodeId,
278    pub history: PaginatedResponse<HistoricalPerformanceResponse>,
279}
280
281#[derive(Serialize, Deserialize, schemars::JsonSchema, ToSchema)]
282#[cfg_attr(feature = "generate-ts", derive(ts_rs::TS))]
283#[cfg_attr(
284    feature = "generate-ts",
285    ts(
286        export,
287        export_to = "ts-packages/types/src/types/rust/UptimeHistoryResponse.ts"
288    )
289)]
290pub struct UptimeHistoryResponse {
291    #[schema(value_type = u32)]
292    pub node_id: NodeId,
293    pub history: PaginatedResponse<HistoricalUptimeResponse>,
294}
295
296#[derive(Clone, Serialize, Deserialize, schemars::JsonSchema, ToSchema)]
297#[cfg_attr(feature = "generate-ts", derive(ts_rs::TS))]
298#[cfg_attr(
299    feature = "generate-ts",
300    ts(
301        export,
302        export_to = "ts-packages/types/src/types/rust/HistoricalUptimeResponse.ts"
303    )
304)]
305pub struct HistoricalUptimeResponse {
306    #[schema(value_type = String, example = "1970-01-01")]
307    #[schemars(with = "String")]
308    #[cfg_attr(feature = "generate-ts", ts(type = "string"))]
309    pub date: Date,
310
311    pub uptime: Uptime,
312}
313
314#[derive(Clone, Serialize, Deserialize, schemars::JsonSchema, ToSchema)]
315#[cfg_attr(feature = "generate-ts", derive(ts_rs::TS))]
316#[cfg_attr(
317    feature = "generate-ts",
318    ts(
319        export,
320        export_to = "ts-packages/types/src/types/rust/HistoricalPerformanceResponse.ts"
321    )
322)]
323pub struct HistoricalPerformanceResponse {
324    #[schema(value_type = String, example = "1970-01-01")]
325    #[schemars(with = "String")]
326    #[cfg_attr(feature = "generate-ts", ts(type = "string"))]
327    pub date: Date,
328
329    pub performance: f64,
330}
331
332#[derive(Clone, Serialize, Deserialize, schemars::JsonSchema, ToSchema)]
333pub struct OldHistoricalUptimeResponse {
334    pub date: String,
335    #[schema(value_type = u8)]
336    pub uptime: Uptime,
337}
338
339#[derive(Clone, Serialize, Deserialize, schemars::JsonSchema, ToSchema)]
340pub struct MixnodeUptimeHistoryResponse {
341    pub mix_id: NodeId,
342    pub identity: String,
343    pub history: Vec<OldHistoricalUptimeResponse>,
344}
345
346#[derive(Clone, Serialize, Deserialize, schemars::JsonSchema, ToSchema)]
347pub struct GatewayUptimeHistoryResponse {
348    pub identity: String,
349    pub history: Vec<OldHistoricalUptimeResponse>,
350}
351
352#[derive(
353    Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema, ToSchema, Default,
354)]
355#[cfg_attr(feature = "generate-ts", derive(ts_rs::TS))]
356#[cfg_attr(
357    feature = "generate-ts",
358    ts(
359        export,
360        export_to = "ts-packages/types/src/types/rust/MixnodeStatus.ts"
361    )
362)]
363#[serde(rename_all = "snake_case")]
364pub enum MixnodeStatus {
365    Active,   // in both the active set and the rewarded set
366    Standby,  // only in the rewarded set
367    Inactive, // in neither the rewarded set nor the active set, but is bonded
368    #[default]
369    NotFound, // doesn't even exist in the bonded set
370}
371impl MixnodeStatus {
372    pub fn is_active(&self) -> bool {
373        *self == MixnodeStatus::Active
374    }
375}
376
377#[derive(Clone, Copy, Debug, Serialize, Deserialize, JsonSchema, ToSchema)]
378#[cfg_attr(feature = "generate-ts", derive(ts_rs::TS))]
379#[cfg_attr(
380    feature = "generate-ts",
381    ts(
382        export,
383        export_to = "ts-packages/types/src/types/rust/MixnodeStatusResponse.ts"
384    )
385)]
386pub struct MixnodeStatusResponse {
387    pub status: MixnodeStatus,
388}
389
390#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema, ToSchema)]
391pub struct NodePerformance {
392    #[schema(value_type = String)]
393    pub most_recent: Performance,
394    #[schema(value_type = String)]
395    pub last_hour: Performance,
396    #[schema(value_type = String)]
397    pub last_24h: Performance,
398}
399
400// imo for now there's no point in exposing more than that,
401// nym-api shouldn't be calculating apy or stake saturation for you.
402// it should just return its own metrics (performance) and then you can do with it as you wish
403#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, JsonSchema, ToSchema)]
404#[cfg_attr(feature = "generate-ts", derive(ts_rs::TS))]
405#[cfg_attr(
406    feature = "generate-ts",
407    ts(
408        export,
409        export_to = "ts-packages/types/src/types/rust/NodeAnnotationV1.ts"
410    )
411)]
412pub struct NodeAnnotationV1 {
413    #[cfg_attr(feature = "generate-ts", ts(type = "string"))]
414    // legacy
415    #[schema(value_type = String)]
416    pub last_24h_performance: Performance,
417    pub current_role: Option<DisplayRole>,
418
419    pub detailed_performance: DetailedNodePerformanceV1,
420}
421
422#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, ToSchema)]
423#[cfg_attr(feature = "generate-ts", derive(ts_rs::TS))]
424#[cfg_attr(
425    feature = "generate-ts",
426    ts(
427        export,
428        export_to = "ts-packages/types/src/types/rust/ChainInteractionCapabilitiesDetailed.ts"
429    )
430)]
431pub struct ChainInteractionCapabilitiesDetailed {
432    #[schema(value_type = CoinSchema)]
433    #[cfg_attr(feature = "generate-ts", ts(type = "Coin"))]
434    pub on_chain_balance: Coin,
435
436    // later to be expanded with information on whether the grant would cover
437    // cosmwasm executemsg, but for now we assume any feegrant is sufficient
438    pub is_feegrant_grantee: bool,
439}
440
441#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema, ToSchema)]
442#[cfg_attr(feature = "generate-ts", derive(ts_rs::TS))]
443#[cfg_attr(
444    feature = "generate-ts",
445    ts(
446        export,
447        export_to = "ts-packages/types/src/types/rust/NodeAnnotationV2.ts"
448    )
449)]
450pub struct NodeAnnotationV2 {
451    pub current_role: Option<DisplayRole>,
452
453    pub chain_interaction_capabilities: Option<ChainInteractionCapabilitiesDetailed>,
454
455    pub detailed_performance: DetailedNodePerformanceV2,
456}
457
458impl From<NodeAnnotationV2> for NodeAnnotationV1 {
459    fn from(value: NodeAnnotationV2) -> Self {
460        // map it from 0-1 range into 0-100
461        let scaled_performance =
462            value.detailed_performance.performance_score.clamp(0.0, 1.0) * 100.;
463        #[allow(clippy::unwrap_used)]
464        let legacy_performance =
465            Performance::from_percentage_value(scaled_performance as u64).unwrap();
466
467        NodeAnnotationV1 {
468            last_24h_performance: legacy_performance,
469            current_role: value.current_role,
470            detailed_performance: DetailedNodePerformanceV1 {
471                performance_score: value.detailed_performance.performance_score,
472                routing_score: value.detailed_performance.routing_score,
473                config_score: value.detailed_performance.config_score.into(),
474            },
475        }
476    }
477}
478
479#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, JsonSchema, ToSchema)]
480#[cfg_attr(feature = "generate-ts", derive(ts_rs::TS))]
481#[cfg_attr(
482    feature = "generate-ts",
483    ts(
484        export,
485        export_to = "ts-packages/types/src/types/rust/DetailedNodePerformanceV1.ts"
486    )
487)]
488#[non_exhaustive]
489pub struct DetailedNodePerformanceV1 {
490    /// routing_score * config_score
491    pub performance_score: f64,
492
493    pub routing_score: RoutingScore,
494    pub config_score: ConfigScoreV1,
495}
496
497impl DetailedNodePerformanceV1 {
498    pub fn new(
499        performance_score: f64,
500        routing_score: RoutingScore,
501        config_score: ConfigScoreV1,
502    ) -> DetailedNodePerformanceV1 {
503        Self {
504            performance_score,
505            routing_score,
506            config_score,
507        }
508    }
509
510    pub fn to_rewarding_performance(&self) -> Performance {
511        Performance::naive_try_from_f64(self.performance_score).unwrap_or_default()
512    }
513}
514
515#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, JsonSchema, ToSchema)]
516#[cfg_attr(feature = "generate-ts", derive(ts_rs::TS))]
517#[cfg_attr(
518    feature = "generate-ts",
519    ts(
520        export,
521        export_to = "ts-packages/types/src/types/rust/DetailedNodePerformanceV2.ts"
522    )
523)]
524#[non_exhaustive]
525pub struct DetailedNodePerformanceV2 {
526    /// routing_score * config_score
527    /// or
528    /// routing_score * config_score * stress_testing_score, if enabled
529    pub performance_score: f64,
530
531    pub routing_score: RoutingScore,
532    pub config_score: ConfigScoreV2,
533    pub stress_testing_score: StressTestingScore,
534}
535
536impl DetailedNodePerformanceV2 {
537    pub fn new(
538        performance_score: f64,
539        routing_score: RoutingScore,
540        config_score: ConfigScoreV2,
541        stress_testing_score: StressTestingScore,
542    ) -> DetailedNodePerformanceV2 {
543        Self {
544            performance_score,
545            routing_score,
546            config_score,
547            stress_testing_score,
548        }
549    }
550
551    pub fn to_rewarding_performance(&self) -> Performance {
552        Performance::naive_try_from_f64(self.performance_score).unwrap_or_default()
553    }
554}
555
556#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, JsonSchema, ToSchema)]
557#[cfg_attr(feature = "generate-ts", derive(ts_rs::TS))]
558#[cfg_attr(
559    feature = "generate-ts",
560    ts(export, export_to = "ts-packages/types/src/types/rust/RoutingScore.ts")
561)]
562#[non_exhaustive]
563pub struct RoutingScore {
564    /// Total score after taking all the criteria into consideration
565    pub score: f64,
566}
567
568impl RoutingScore {
569    pub fn new(score: f64) -> RoutingScore {
570        Self { score }
571    }
572
573    pub const fn zero() -> RoutingScore {
574        RoutingScore { score: 0.0 }
575    }
576
577    pub fn legacy_performance(&self) -> Performance {
578        Performance::naive_try_from_f64(self.score).unwrap_or_default()
579    }
580}
581
582#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, JsonSchema, ToSchema)]
583#[cfg_attr(feature = "generate-ts", derive(ts_rs::TS))]
584#[cfg_attr(
585    feature = "generate-ts",
586    ts(
587        export,
588        export_to = "ts-packages/types/src/types/rust/StressTestingScore.ts"
589    )
590)]
591pub struct StressTestingScore {
592    pub score: f64,
593    /// Distinguishes a genuine zero score (node was tested and scored 0) from
594    /// "node was unreachable" (no successful sample was collected). Consumers may use
595    /// this to decide whether to penalise the node or treat the score as missing.
596    pub was_reachable: bool,
597}
598
599impl StressTestingScore {
600    pub fn unreachable() -> Self {
601        StressTestingScore {
602            score: 0.0,
603            was_reachable: false,
604        }
605    }
606}
607
608#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, JsonSchema, ToSchema)]
609#[cfg_attr(feature = "generate-ts", derive(ts_rs::TS))]
610#[cfg_attr(
611    feature = "generate-ts",
612    ts(
613        export,
614        export_to = "ts-packages/types/src/types/rust/ConfigScoreV2.ts"
615    )
616)]
617#[non_exhaustive]
618pub struct ConfigScoreV2 {
619    /// Total score after taking all the criteria into consideration
620    pub score: f64,
621
622    pub versions_behind: Option<u32>,
623    pub self_described_api_available: bool,
624    pub accepted_terms_and_conditions: bool,
625    pub runs_nym_node_binary: bool,
626
627    /// Describes the node is capable of sending chain/contract transactions
628    pub chain_interaction_capabilities: ChainInteractionCapabilities,
629}
630
631impl ConfigScoreV2 {
632    pub fn new(
633        score: f64,
634        versions_behind: u32,
635        accepted_terms_and_conditions: bool,
636        runs_nym_node_binary: bool,
637        chain_interaction_capabilities: ChainInteractionCapabilities,
638    ) -> ConfigScoreV2 {
639        Self {
640            score,
641            versions_behind: Some(versions_behind),
642            self_described_api_available: true,
643            accepted_terms_and_conditions,
644            runs_nym_node_binary,
645            chain_interaction_capabilities,
646        }
647    }
648
649    pub fn bad_semver() -> ConfigScoreV2 {
650        ConfigScoreV2 {
651            score: 0.0,
652            versions_behind: None,
653            self_described_api_available: true,
654            accepted_terms_and_conditions: false,
655            runs_nym_node_binary: false,
656            chain_interaction_capabilities: Default::default(),
657        }
658    }
659
660    pub fn unavailable() -> ConfigScoreV2 {
661        ConfigScoreV2 {
662            score: 0.0,
663            versions_behind: None,
664            self_described_api_available: false,
665            accepted_terms_and_conditions: false,
666            runs_nym_node_binary: false,
667            chain_interaction_capabilities: Default::default(),
668        }
669    }
670}
671
672#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, JsonSchema, ToSchema)]
673#[cfg_attr(feature = "generate-ts", derive(ts_rs::TS))]
674#[cfg_attr(
675    feature = "generate-ts",
676    ts(
677        export,
678        export_to = "ts-packages/types/src/types/rust/ChainInteractionCapabilities.ts"
679    )
680)]
681pub struct ChainInteractionCapabilities {
682    pub has_sufficient_tokens: bool,
683    pub is_fee_grant_grantee: bool,
684}
685
686impl ChainInteractionCapabilities {
687    pub fn new(has_sufficient_tokens: bool, is_fee_grant_grantee: bool) -> Self {
688        Self {
689            has_sufficient_tokens,
690            is_fee_grant_grantee,
691        }
692    }
693
694    pub fn can_send_transactions(&self) -> bool {
695        self.has_sufficient_tokens || self.is_fee_grant_grantee
696    }
697}
698
699impl From<ConfigScoreV2> for ConfigScoreV1 {
700    fn from(score_v2: ConfigScoreV2) -> ConfigScoreV1 {
701        ConfigScoreV1 {
702            score: score_v2.score,
703            versions_behind: score_v2.versions_behind,
704            self_described_api_available: score_v2.self_described_api_available,
705            accepted_terms_and_conditions: score_v2.accepted_terms_and_conditions,
706            runs_nym_node_binary: score_v2.runs_nym_node_binary,
707        }
708    }
709}
710
711#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, JsonSchema, ToSchema)]
712#[cfg_attr(feature = "generate-ts", derive(ts_rs::TS))]
713#[cfg_attr(
714    feature = "generate-ts",
715    ts(
716        export,
717        export_to = "ts-packages/types/src/types/rust/ConfigScoreV1.ts"
718    )
719)]
720#[non_exhaustive]
721pub struct ConfigScoreV1 {
722    /// Total score after taking all the criteria into consideration
723    pub score: f64,
724
725    pub versions_behind: Option<u32>,
726    pub self_described_api_available: bool,
727    pub accepted_terms_and_conditions: bool,
728    pub runs_nym_node_binary: bool,
729}
730
731#[derive(Clone, Copy, Debug, Serialize, Deserialize, JsonSchema, ToSchema)]
732#[cfg_attr(feature = "generate-ts", derive(ts_rs::TS))]
733#[cfg_attr(
734    feature = "generate-ts",
735    ts(
736        export,
737        export_to = "ts-packages/types/src/types/rust/AnnotationResponseV1.ts"
738    )
739)]
740pub struct AnnotationResponseV1 {
741    #[schema(value_type = u32)]
742    pub node_id: NodeId,
743    pub annotation: Option<NodeAnnotationV1>,
744}
745
746#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, ToSchema)]
747#[cfg_attr(feature = "generate-ts", derive(ts_rs::TS))]
748#[cfg_attr(
749    feature = "generate-ts",
750    ts(
751        export,
752        export_to = "ts-packages/types/src/types/rust/AnnotationResponseV2.ts"
753    )
754)]
755pub struct AnnotationResponseV2 {
756    #[schema(value_type = u32)]
757    pub node_id: NodeId,
758    pub annotation: Option<NodeAnnotationV2>,
759}
760
761#[derive(Clone, Copy, Debug, Serialize, Deserialize, JsonSchema, ToSchema)]
762#[cfg_attr(feature = "generate-ts", derive(ts_rs::TS))]
763#[cfg_attr(
764    feature = "generate-ts",
765    ts(
766        export,
767        export_to = "ts-packages/types/src/types/rust/NodePerformanceResponse.ts"
768    )
769)]
770pub struct NodePerformanceResponse {
771    #[schema(value_type = u32)]
772    pub node_id: NodeId,
773    pub performance: Option<f64>,
774}
775
776#[derive(Clone, Copy, Debug, Serialize, Deserialize, JsonSchema, ToSchema)]
777#[cfg_attr(feature = "generate-ts", derive(ts_rs::TS))]
778#[cfg_attr(
779    feature = "generate-ts",
780    ts(
781        export,
782        export_to = "ts-packages/types/src/types/rust/NodeDatePerformanceResponse.ts"
783    )
784)]
785pub struct NodeDatePerformanceResponse {
786    #[schema(value_type = u32)]
787    pub node_id: NodeId,
788    #[schema(value_type = String, example = "1970-01-01")]
789    #[schemars(with = "String")]
790    #[cfg_attr(feature = "generate-ts", ts(type = "string"))]
791    pub date: Date,
792    pub performance: Option<f64>,
793}