-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathbridge.rs
More file actions
97 lines (89 loc) · 3.2 KB
/
Copy pathbridge.rs
File metadata and controls
97 lines (89 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
use alloc::borrow::Cow;
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
use crate::models::{Model, NoFlags, XChainBridge, XRPAmount};
use super::{CommonFields, LedgerEntryType, LedgerObject};
#[skip_serializing_none]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "PascalCase")]
pub struct Bridge<'a> {
#[serde(flatten)]
pub common_fields: CommonFields<'a, NoFlags>,
pub account: Cow<'a, str>,
pub signature_reward: XRPAmount<'a>,
#[serde(rename = "XChainAccountClaimCount")]
pub xchain_account_claim_count: u64,
#[serde(rename = "XChainAccountCreateCount")]
pub xchain_account_create_count: u64,
pub xchain_bridge: XChainBridge<'a>,
#[serde(rename = "XChainClaimID")]
pub xchain_claim_id: Cow<'a, str>,
pub min_account_create_amount: Option<XRPAmount<'a>>,
}
impl Model for Bridge<'_> {}
impl LedgerObject<NoFlags> for Bridge<'_> {
fn get_ledger_entry_type(&self) -> super::LedgerEntryType {
self.common_fields.get_ledger_entry_type()
}
}
impl<'a> Bridge<'a> {
pub fn new(
index: Option<Cow<'a, str>>,
ledger_index: Option<Cow<'a, str>>,
account: Cow<'a, str>,
signature_reward: XRPAmount<'a>,
xchain_account_claim_count: u64,
xchain_account_create_count: u64,
xchain_bridge: XChainBridge<'a>,
xchain_claim_id: Cow<'a, str>,
min_account_create_amount: Option<XRPAmount<'a>>,
) -> Bridge<'a> {
Bridge {
common_fields: CommonFields {
flags: Default::default(),
ledger_entry_type: LedgerEntryType::Bridge,
index,
ledger_index,
},
account,
signature_reward,
xchain_account_claim_count,
xchain_account_create_count,
xchain_bridge,
xchain_claim_id,
min_account_create_amount,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::models::currency::XRP;
#[test]
fn test_bridge_serde_round_trip() {
let bridge = Bridge::new(
Some("AABBCC".into()),
Some("DDEEFF".into()),
"rPV4mZjsXfH2HvUSPLNmqz1J8d3Lpv7tpe".into(),
"100".into(),
7,
3,
XChainBridge {
locking_chain_door: "rMAXACCrp3Y8PpswXcg3bKggHX76V3F8M4".into(),
locking_chain_issue: XRP::new().into(),
issuing_chain_door: "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh".into(),
issuing_chain_issue: XRP::new().into(),
},
"13f".into(),
Some("100000".into()),
);
let serialized = serde_json::to_string(&bridge).unwrap();
let deserialized: Bridge = serde_json::from_str(&serialized).unwrap();
assert_eq!(bridge, deserialized);
assert!(serialized.contains("\"LedgerEntryType\":\"Bridge\""));
assert!(serialized.contains("\"XChainAccountClaimCount\":7"));
assert!(serialized.contains("\"XChainAccountCreateCount\":3"));
assert!(serialized.contains("\"XChainClaimID\":\"13f\""));
assert_eq!(bridge.get_ledger_entry_type(), LedgerEntryType::Bridge);
}
}