12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- 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<AccountId>,
- }
-
- #[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<u8>,
- }
-
- #[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);
- }
- }
|