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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
use super::{
AuthorisationKind, CmdError, MiscAuthKind, MoneyAuthKind, QueryResponse, TransferError,
};
#[cfg(feature = "simulated-payouts")]
use crate::Transfer;
use crate::{DebitAgreementProof, Error, PublicKey, SignedTransfer, XorName};
use serde::{Deserialize, Serialize};
use std::fmt;
#[allow(clippy::large_enum_variant)]
#[derive(Hash, Eq, PartialEq, Clone, Serialize, Deserialize)]
pub enum TransferCmd {
#[cfg(feature = "simulated-payouts")]
SimulatePayout(Transfer),
ValidateTransfer(SignedTransfer),
RegisterTransfer(DebitAgreementProof),
}
#[allow(clippy::large_enum_variant)]
#[derive(Hash, Eq, PartialEq, Clone, Serialize, Deserialize)]
pub enum TransferQuery {
GetReplicaKeys(PublicKey),
GetBalance(PublicKey),
GetHistory {
at: PublicKey,
since_version: usize,
},
GetStoreCost {
requester: PublicKey,
bytes: u64,
},
}
impl TransferCmd {
pub fn error(&self, error: Error) -> CmdError {
use CmdError::*;
use TransferCmd::*;
use TransferError::*;
match *self {
ValidateTransfer(_) => Transfer(TransferValidation(error)),
RegisterTransfer(_) => Transfer(TransferRegistration(error)),
#[cfg(feature = "simulated-payouts")]
SimulatePayout(_) => Transfer(TransferRegistration(error)),
}
}
pub fn authorisation_kind(&self) -> AuthorisationKind {
use TransferCmd::*;
match self {
RegisterTransfer(_) => AuthorisationKind::None,
ValidateTransfer(_) => AuthorisationKind::Misc(MiscAuthKind::WriteAndTransfer),
#[cfg(feature = "simulated-payouts")]
SimulatePayout(_) => AuthorisationKind::None,
}
}
pub fn dst_address(&self) -> XorName {
use TransferCmd::*;
match self {
RegisterTransfer(ref proof) => XorName::from(proof.from()),
ValidateTransfer(ref signed_transfer) => XorName::from(signed_transfer.from()),
#[cfg(feature = "simulated-payouts")]
SimulatePayout(ref transfer) => XorName::from(transfer.from()),
}
}
}
impl fmt::Debug for TransferCmd {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
use TransferCmd::*;
write!(
formatter,
"TransferCmd::{}",
match *self {
RegisterTransfer { .. } => "RegisterTransfer",
ValidateTransfer { .. } => "ValidateTransfer",
#[cfg(feature = "simulated-payouts")]
SimulatePayout { .. } => "SimulatePayout",
}
)
}
}
impl TransferQuery {
pub fn error(&self, error: Error) -> QueryResponse {
use TransferQuery::*;
match *self {
GetReplicaKeys(_) => QueryResponse::GetReplicaKeys(Err(error)),
GetBalance(_) => QueryResponse::GetBalance(Err(error)),
GetHistory { .. } => QueryResponse::GetHistory(Err(error)),
GetStoreCost { .. } => QueryResponse::GetStoreCost(Err(error)),
}
}
pub fn authorisation_kind(&self) -> AuthorisationKind {
use TransferQuery::*;
match self {
GetBalance(_) => AuthorisationKind::Money(MoneyAuthKind::ReadBalance),
GetReplicaKeys(_) => AuthorisationKind::None,
GetHistory { .. } => AuthorisationKind::Money(MoneyAuthKind::ReadHistory),
GetStoreCost { .. } => AuthorisationKind::None,
}
}
pub fn dst_address(&self) -> XorName {
use TransferQuery::*;
match self {
GetBalance(at)
| GetReplicaKeys(at)
| GetHistory { at, .. }
| GetStoreCost { requester: at, .. } => XorName::from(*at),
}
}
}
impl fmt::Debug for TransferQuery {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
use TransferQuery::*;
write!(
formatter,
"TransferQuery::{}",
match *self {
GetBalance(_) => "GetBalance",
GetReplicaKeys(_) => "GetReplicaKeys",
GetHistory { .. } => "GetHistory",
GetStoreCost { .. } => "GetStoreCost",
}
)
}
}