raiden_primitives/
types.rs1#![warn(clippy::missing_docs_in_private_items)]
2
3use derive_more::Display;
4use serde::{
5 Deserialize,
6 Serialize,
7};
8pub use web3::types::{
9 Address,
10 BlockId,
11 Bytes,
12 H160,
13 H256,
14 U256,
15};
16
17mod chain_id;
19pub use chain_id::*;
20
21mod numeric;
23pub use numeric::*;
24
25use crate::{
26 deserializers::u256_from_str,
27 serializers::u256_to_str,
28 traits::Checksum,
29};
30
31pub type BalanceProofData = (Locksroot, Nonce, TokenAmount, LockedAmount);
33
34pub type BalanceHash = H256;
36
37pub type BlockExpiration = U64;
39
40pub type BlockNumber = U64;
42
43pub type BlockHash = H256;
45
46pub type BlockTimeout = U64;
48
49pub type ChannelIdentifier = U256;
51
52pub type EncodedLock = Bytes;
54
55pub type FeeAmount = U256;
57
58pub type GasLimit = U256;
60
61pub type GasPrice = U256;
63
64pub type LockedAmount = U256;
66
67pub type LockTimeout = U64;
69
70pub type Locksroot = H256;
72
73pub type MessageIdentifier = u64;
75
76pub type MessageHash = H256;
78
79pub type Nonce = U256;
81
82pub type OneToNAddress = Address;
84
85pub type PaymentIdentifier = U64;
87
88pub type ProportionalFeeAmount = U256;
90
91pub type RevealTimeout = U64;
93
94pub type RetryTimeout = u64;
96
97pub type Secret = Bytes;
99
100pub type SecretHash = H256;
102
103pub type SecretRegistryAddress = Address;
105
106pub type Signature = Bytes;
108
109pub type SettleTimeout = U64;
111
112pub type TokenAddress = Address;
114
115pub type TokenNetworkRegistryAddress = Address;
117
118pub type TokenNetworkAddress = Address;
120
121pub type TokenAmount = U256;
123
124pub type TransactionHash = H256;
126
127#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
129pub struct CanonicalIdentifier {
130 pub chain_identifier: ChainID,
131 pub token_network_address: TokenNetworkAddress,
132 #[serde(deserialize_with = "u256_from_str", serialize_with = "u256_to_str")]
133 pub channel_identifier: ChannelIdentifier,
134}
135
136impl ToString for CanonicalIdentifier {
137 fn to_string(&self) -> String {
138 format!(
139 "ChainID: {}, TokenNetworkAddress: {}, ChannelID: {}",
140 self.chain_identifier,
141 self.token_network_address.checksum(),
142 self.channel_identifier
143 )
144 }
145}
146
147#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
149pub struct QueueIdentifier {
150 pub recipient: Address,
151 pub canonical_identifier: CanonicalIdentifier,
152}
153
154impl ToString for QueueIdentifier {
155 fn to_string(&self) -> String {
156 format!(
157 "Recipient: {}, {}",
158 self.recipient.checksum(),
159 self.canonical_identifier.to_string()
160 )
161 }
162}
163
164#[repr(u8)]
166#[derive(Clone, Display, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
167pub enum MessageTypeId {
168 BalanceProof = 1,
169 BalanceProofUpdate = 2,
170 Withdraw = 3,
171 CooperativeSettle = 4,
172 IOU = 5,
173 MSReward = 6,
174}
175
176impl From<MessageTypeId> for [u8; 1] {
177 fn from(val: MessageTypeId) -> Self {
178 (val as u8).to_be_bytes()
179 }
180}
181
182#[derive(Clone, Debug, Default, Serialize, Deserialize, Eq, PartialEq)]
184pub struct AddressMetadata {
185 pub user_id: String,
186 pub displayname: String,
187 pub capabilities: String,
188}
189
190#[derive(Clone, Serialize)]
192pub struct DefaultAddresses {
193 pub contracts_version: String,
194 #[serde(rename = "token_network_registry_address")]
195 pub token_network_registry: Address,
196 #[serde(rename = "secret_registry_address")]
197 pub secret_registry: Address,
198 #[serde(rename = "one_to_n_address")]
199 pub one_to_n: Address,
200 #[serde(rename = "service_registry_address")]
201 pub service_registry: Address,
202 #[serde(rename = "user_deposit_address")]
203 pub user_deposit: Address,
204 #[serde(rename = "monitoring_service_address")]
205 pub monitoring_service: Address,
206}