use crate::crypto::prelude::*; use borsh::{BorshDeserialize, BorshSerialize}; use near_account_id::AccountId; use serde::{Deserialize, Serialize}; use std::{collections::HashSet, time::Duration}; #[derive(Clone, Debug, Serialize, Deserialize)] pub struct PublicKeys { pub timeout: Duration, pub participants: HashSet, } #[derive(Clone, Debug, Serialize, Deserialize)] pub struct ExchangeMessage { pub account_id: AccountId, pub message: Data, } #[derive(Clone, Debug, Serialize, Deserialize)] pub struct Data { pub moderator_pk: Ed25519PublicKey, pub data: Vec, } #[derive(Clone, Debug, Serialize, Deserialize)] pub struct ParticipantInfo { pub public_key: Ed25519PublicKey, pub account_id: AccountId, } #[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize)] pub struct Bandwidth { pub speed: u32, pub units: String, } #[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize)] pub struct NodeInfo { pub region: String, pub bandwidth: Bandwidth, pub account_id: AccountId, } #[cfg(test)] mod tests { use super::*; use std::str::FromStr; #[test] fn node_info_json() { let s1 = serde_json::to_value(&NodeInfo { account_id: AccountId::from_str("account.testnet").unwrap(), bandwidth: Bandwidth { speed: 100, units: "mbps".to_owned(), }, region: "us".to_owned(), }) .unwrap(); let s2 = serde_json::json!({ "account_id": "account.testnet", "region": "us", "bandwidth": { "speed": 100, "units": "mbps" } }); assert_eq!(s1, s2); } }