You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

api.rs 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. use crate::crypto::prelude::*;
  2. use borsh::{BorshDeserialize, BorshSerialize};
  3. use near_account_id::AccountId;
  4. use serde::{Deserialize, Serialize};
  5. use std::{collections::HashSet, time::Duration};
  6. #[derive(Clone, Debug, Serialize, Deserialize)]
  7. pub struct PublicKeys {
  8. pub timeout: Duration,
  9. pub participants: HashSet<AccountId>,
  10. }
  11. #[derive(Clone, Debug, Serialize, Deserialize)]
  12. pub struct ExchangeMessage {
  13. pub account_id: AccountId,
  14. pub message: Data,
  15. }
  16. #[derive(Clone, Debug, Serialize, Deserialize)]
  17. pub struct Data {
  18. pub moderator_pk: Ed25519PublicKey,
  19. pub data: Vec<u8>,
  20. }
  21. #[derive(Clone, Debug, Serialize, Deserialize)]
  22. pub struct ParticipantInfo {
  23. pub public_key: Ed25519PublicKey,
  24. pub account_id: AccountId,
  25. }
  26. #[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize)]
  27. pub struct Bandwidth {
  28. pub speed: u32,
  29. pub units: String,
  30. }
  31. #[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize)]
  32. pub struct NodeInfo {
  33. pub region: String,
  34. pub bandwidth: Bandwidth,
  35. pub account_id: AccountId,
  36. }
  37. #[cfg(test)]
  38. mod tests {
  39. use super::*;
  40. use std::str::FromStr;
  41. #[test]
  42. fn node_info_json() {
  43. let s1 = serde_json::to_value(&NodeInfo {
  44. account_id: AccountId::from_str("account.testnet").unwrap(),
  45. bandwidth: Bandwidth {
  46. speed: 100,
  47. units: "mbps".to_owned(),
  48. },
  49. region: "us".to_owned(),
  50. })
  51. .unwrap();
  52. let s2 = serde_json::json!({
  53. "account_id": "account.testnet",
  54. "region": "us",
  55. "bandwidth": {
  56. "speed": 100,
  57. "units": "mbps"
  58. }
  59. });
  60. assert_eq!(s1, s2);
  61. }
  62. }