raiden_state_machine/types/
mod.rs

1#![warn(clippy::missing_docs_in_private_items)]
2
3/// Event types.
4mod event;
5/// State types
6mod state;
7/// State change types
8mod state_change;
9
10use raiden_primitives::{
11	deserializers::u256_from_str,
12	serializers::u256_to_str,
13	types::{
14		BlockNumber,
15		PaymentIdentifier,
16		Secret,
17		TokenAmount,
18	},
19};
20use rand_chacha::{
21	rand_core::{
22		RngCore,
23		SeedableRng,
24	},
25	ChaChaRng,
26};
27use serde::{
28	Deserialize,
29	Serialize,
30};
31
32pub use self::{
33	event::*,
34	state::*,
35	state_change::*,
36};
37
38/// The channel's pseudo random number generator.
39#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
40pub struct Random(ChaChaRng);
41
42impl Random {
43	pub fn new() -> Self {
44		Self(ChaChaRng::seed_from_u64(0))
45	}
46
47	#[allow(clippy::should_implement_trait)]
48	pub fn next(&mut self) -> u64 {
49		self.0.next_u64()
50	}
51}
52
53impl Default for Random {
54	fn default() -> Self {
55		Self::new()
56	}
57}
58
59/// Transaction result state.
60#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)]
61pub enum TransactionResult {
62	Success,
63	Failure,
64}
65
66/// The transaction execution status.
67#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)]
68pub struct TransactionExecutionStatus {
69	pub started_block_number: Option<BlockNumber>,
70	pub finished_block_number: Option<BlockNumber>,
71	pub result: Option<TransactionResult>,
72}
73
74/// Type to hold a decrypted secret with metadata.
75#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)]
76pub struct DecryptedSecret {
77	pub secret: Secret,
78	#[serde(deserialize_with = "u256_from_str", serialize_with = "u256_to_str")]
79	pub amount: TokenAmount,
80	pub payment_identifier: PaymentIdentifier,
81}