raiden_primitives/
types.rs

1#![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
17/// Chain identifier module.
18mod chain_id;
19pub use chain_id::*;
20
21/// Custom numeric data types.
22mod numeric;
23pub use numeric::*;
24
25use crate::{
26	deserializers::u256_from_str,
27	serializers::u256_to_str,
28	traits::Checksum,
29};
30
31/// Alias type for BalanceProofData
32pub type BalanceProofData = (Locksroot, Nonce, TokenAmount, LockedAmount);
33
34// Alias type for Balance Hash
35pub type BalanceHash = H256;
36
37/// Alias type for block expiration.
38pub type BlockExpiration = U64;
39
40/// Alias type for block number.
41pub type BlockNumber = U64;
42
43/// Alias type for block hash.
44pub type BlockHash = H256;
45
46/// Alias type for block timeout.
47pub type BlockTimeout = U64;
48
49/// Alias type for channel identifier.
50pub type ChannelIdentifier = U256;
51
52/// Alias type for encoded lock.
53pub type EncodedLock = Bytes;
54
55/// Alias type for fee amount.
56pub type FeeAmount = U256;
57
58/// Alias type for gas limit.
59pub type GasLimit = U256;
60
61/// Alias type for gas price.
62pub type GasPrice = U256;
63
64/// Alias price for locked amount.
65pub type LockedAmount = U256;
66
67/// Alias type for lock timeout.
68pub type LockTimeout = U64;
69
70/// Alias type for locksroot.
71pub type Locksroot = H256;
72
73/// Alias type for message identifier.
74pub type MessageIdentifier = u64;
75
76/// Alias type for message hash.
77pub type MessageHash = H256;
78
79/// Alias type for nonce.
80pub type Nonce = U256;
81
82/// Alias type for OneToN address.
83pub type OneToNAddress = Address;
84
85/// Alias type for payment identifier.
86pub type PaymentIdentifier = U64;
87
88/// Alias type for proportional fee amount.
89pub type ProportionalFeeAmount = U256;
90
91/// Alias type for reveal timeout.
92pub type RevealTimeout = U64;
93
94/// Alias type for retry timeout.
95pub type RetryTimeout = u64;
96
97/// Alias type for secret.
98pub type Secret = Bytes;
99
100/// Alias type for secret hash.
101pub type SecretHash = H256;
102
103/// ALias type for secret registry address.
104pub type SecretRegistryAddress = Address;
105
106/// Alias type for signature.
107pub type Signature = Bytes;
108
109/// Alias type for settle timeout.
110pub type SettleTimeout = U64;
111
112/// Alias type for token address.
113pub type TokenAddress = Address;
114
115/// Alias type for token network registry address.
116pub type TokenNetworkRegistryAddress = Address;
117
118/// Alias type for token network address.
119pub type TokenNetworkAddress = Address;
120
121/// Alias type for token amount.
122pub type TokenAmount = U256;
123
124/// Alias type for transaction hash.
125pub type TransactionHash = H256;
126
127/// The channel's canonical identifier.
128#[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/// Message queue identifier.
148#[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/// Message type identifier.
165#[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/// Networking address metadata
183#[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/// Contains a list of deployed contract addresses vital for the operation of the node.
191#[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}