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
#[macro_export]
macro_rules! impl_account_data {
(
$(#[$attr:meta])*
$(pub)? struct $sname:ident<Balance$(, $($gtype:tt)*)?>
for
$ring_instance:ident,
$kton_instance:ident
where
Balance = $btype:ty
$(, $($gtypebound:tt)*)?
{
$($(pub)? $fname:ident: $ftype:ty),*
}
) => {
use darwinia_balances::{BalanceInfo, FrozenBalance, Reasons};
$(#[$attr])*
#[derive(Clone, Default, PartialEq, Eq, Encode, Decode, RuntimeDebug, MaxEncodedLen, TypeInfo)]
pub struct $sname<Balance$(, $($gtype)*)?>
$(
where
$($gtypebound)*
)?
{
pub free: Balance,
pub reserved: Balance,
pub free_kton: Balance,
pub reserved_kton: Balance,
$(pub $fname: $ftype),*
}
impl BalanceInfo<$btype, $ring_instance> for AccountData<$btype> {
fn free(&self) -> $btype {
self.free
}
fn set_free(&mut self, new_free: $btype) {
self.free = new_free;
}
fn reserved(&self) -> $btype {
self.reserved
}
fn set_reserved(&mut self, new_reserved: $btype) {
self.reserved = new_reserved;
}
fn total(&self) -> $btype {
self.free.saturating_add(self.reserved)
}
}
impl BalanceInfo<$btype, $kton_instance> for AccountData<$btype> {
fn free(&self) -> $btype { self.free_kton }
fn set_free(&mut self, new_free_kton: $btype) { self.free_kton = new_free_kton; }
fn reserved(&self) -> $btype { self.reserved_kton }
fn set_reserved(&mut self, new_reserved_kton: $btype) { self.reserved_kton = new_reserved_kton; }
fn total(&self) -> $btype { self.free_kton.saturating_add(self.reserved_kton) }
}
};
}