1#![warn(clippy::missing_docs_in_private_items)]
2
3use derive_more::Deref;
4use raiden_macros::IntoEvent;
5use raiden_primitives::types::{
6 Address,
7 AddressMetadata,
8 BlockExpiration,
9 BlockHash,
10 BlockNumber,
11 CanonicalIdentifier,
12 MessageIdentifier,
13 Nonce,
14 PaymentIdentifier,
15 QueueIdentifier,
16 RevealTimeout,
17 Secret,
18 SecretHash,
19 Signature,
20 TokenAddress,
21 TokenAmount,
22 TokenNetworkAddress,
23 TokenNetworkRegistryAddress,
24 U256,
25};
26use serde::{
27 Deserialize,
28 Serialize,
29};
30
31use super::{
32 BalanceProofState,
33 LockedTransferState,
34 PFSUpdate,
35};
36
37#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)]
39#[serde(tag = "type")]
40pub enum Event {
41 ContractSendChannelClose(ContractSendChannelClose),
42 ContractSendChannelCoopSettle(ContractSendChannelCoopSettle),
43 ContractSendChannelWithdraw(ContractSendChannelWithdraw),
44 ContractSendChannelSettle(ContractSendChannelSettle),
45 ContractSendChannelUpdateTransfer(ContractSendChannelUpdateTransfer),
46 ContractSendChannelBatchUnlock(ContractSendChannelBatchUnlock),
47 ContractSendSecretReveal(ContractSendSecretReveal),
48 PaymentReceivedSuccess(PaymentReceivedSuccess),
49 PaymentSentSuccess(PaymentSentSuccess),
50 SendWithdrawExpired(SendWithdrawExpired),
51 SendWithdrawRequest(SendWithdrawRequest),
52 SendWithdrawConfirmation(SendWithdrawConfirmation),
53 SendLockedTransfer(SendLockedTransfer),
54 SendLockExpired(SendLockExpired),
55 SendSecretRequest(SendSecretRequest),
56 SendSecretReveal(SendSecretReveal),
57 SendUnlock(SendUnlock),
58 SendPFSUpdate(PFSUpdate),
59 SendMSUpdate(BalanceProofState),
60 SendProcessed(SendProcessed),
61 UnlockSuccess(UnlockSuccess),
62 UnlockClaimSuccess(UnlockClaimSuccess),
63 UpdatedServicesAddresses(UpdatedServicesAddresses),
64 ExpireServicesAddresses(BlockNumber),
65 ErrorInvalidActionWithdraw(ErrorInvalidActionWithdraw),
66 ErrorInvalidActionCoopSettle(ErrorInvalidActionCoopSettle),
67 ErrorInvalidActionSetRevealTimeout(ErrorInvalidActionSetRevealTimeout),
68 ErrorInvalidSecretRequest(ErrorInvalidSecretRequest),
69 ErrorInvalidReceivedLockedTransfer(ErrorInvalidReceivedLockedTransfer),
70 ErrorInvalidReceivedLockExpired(ErrorInvalidReceivedLockExpired),
71 ErrorInvalidReceivedTransferRefund(ErrorInvalidReceivedTransferRefund),
72 ErrorInvalidReceivedUnlock(ErrorInvalidReceivedUnlock),
73 ErrorInvalidReceivedWithdrawRequest(ErrorInvalidReceivedWithdrawRequest),
74 ErrorInvalidReceivedWithdrawConfirmation(ErrorInvalidReceivedWithdrawConfirmation),
75 ErrorInvalidReceivedWithdrawExpired(ErrorInvalidReceivedWithdrawExpired),
76 ErrorPaymentSentFailed(ErrorPaymentSentFailed),
77 ErrorRouteFailed(ErrorRouteFailed),
78 ErrorUnlockClaimFailed(ErrorUnlockClaimFailed),
79 ErrorUnlockFailed(ErrorUnlockFailed),
80 ErrorUnexpectedReveal(ErrorUnexpectedReveal),
81 ClearMessages(QueueIdentifier),
82}
83
84impl Event {
85 pub fn type_name(&self) -> &'static str {
87 match self {
88 Event::ContractSendChannelClose(_) => "ContractSendChannelClose",
89 Event::ContractSendChannelCoopSettle(_) => "ContractSendChannelCoopSettle",
90 Event::ContractSendChannelWithdraw(_) => "ContractSendChannelWithdraw",
91 Event::ContractSendChannelSettle(_) => "ContractSendChannelSettle",
92 Event::ContractSendChannelUpdateTransfer(_) => "ContractSendChannelUpdateTransfer",
93 Event::ContractSendChannelBatchUnlock(_) => "ContractSendChannelBatchUnlock",
94 Event::ContractSendSecretReveal(_) => "ContractSendSecretReveal",
95 Event::PaymentReceivedSuccess(_) => "PaymentReceivedSuccess",
96 Event::PaymentSentSuccess(_) => "PaymentSentSuccess",
97 Event::SendWithdrawExpired(_) => "SendWithdrawExpired",
98 Event::SendWithdrawRequest(_) => "SendWithdrawRequest",
99 Event::SendWithdrawConfirmation(_) => "SendWithdrawConfirmation",
100 Event::SendLockedTransfer(_) => "SendLockedTransfer",
101 Event::SendLockExpired(_) => "SendLockExpired",
102 Event::SendSecretRequest(_) => "SendSecretRequest",
103 Event::SendSecretReveal(_) => "SendSecretReveal",
104 Event::SendUnlock(_) => "SendUnlock",
105 Event::SendPFSUpdate(_) => "SendPFSUpdate",
106 Event::SendMSUpdate(_) => "SendMSUpdate",
107 Event::SendProcessed(_) => "SendProcessed",
108 Event::UnlockSuccess(_) => "UnlockSuccess",
109 Event::UnlockClaimSuccess(_) => "UnlockClaimSuccess",
110 Event::UpdatedServicesAddresses(_) => "UpdatedServicesAddresses",
111 Event::ExpireServicesAddresses(_) => "ExpireServicesAddresses",
112 Event::ErrorInvalidActionWithdraw(_) => "ErrorInvalidActionWithdraw",
113 Event::ErrorInvalidActionCoopSettle(_) => "ErrorInvalidActionCoopSettle",
114 Event::ErrorInvalidActionSetRevealTimeout(_) => "ErrorInvalidActionSetRevealTimeout",
115 Event::ErrorInvalidSecretRequest(_) => "ErrorInvalidSecretRequest",
116 Event::ErrorInvalidReceivedLockedTransfer(_) => "ErrorInvalidReceivedLockedTransfer",
117 Event::ErrorInvalidReceivedLockExpired(_) => "ErrorInvalidReceivedLockExpired",
118 Event::ErrorInvalidReceivedTransferRefund(_) => "ErrorInvalidReceivedTransferRefund",
119 Event::ErrorInvalidReceivedUnlock(_) => "ErrorInvalidReceivedUnlock",
120 Event::ErrorInvalidReceivedWithdrawRequest(_) => "ErrorInvalidReceivedWithdrawRequest",
121 Event::ErrorInvalidReceivedWithdrawConfirmation(_) =>
122 "ErrorInvalidReceivedWithdrawConfirmation",
123 Event::ErrorInvalidReceivedWithdrawExpired(_) => "ErrorInvalidReceivedWithdrawExpired",
124 Event::ErrorPaymentSentFailed(_) => "ErrorPaymentSentFailed",
125 Event::ErrorRouteFailed(_) => "ErrorRouteFailed",
126 Event::ErrorUnlockClaimFailed(_) => "ErrorUnlockClaimFailed",
127 Event::ErrorUnlockFailed(_) => "ErrorUnlockFailed",
128 Event::ErrorUnexpectedReveal(_) => "ErrorUnexpectedReveal",
129 Event::ClearMessages(_) => "ClearMessages",
130 }
131 }
132}
133
134#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)]
136pub enum SendMessageEvent {
137 SendLockExpired(SendLockExpired),
138 SendLockedTransfer(SendLockedTransfer),
139 SendSecretReveal(SendSecretReveal),
140 SendSecretRequest(SendSecretRequest),
141 SendUnlock(SendUnlock),
142 SendWithdrawRequest(SendWithdrawRequest),
143 SendWithdrawConfirmation(SendWithdrawConfirmation),
144 SendWithdrawExpired(SendWithdrawExpired),
145 SendProcessed(SendProcessed),
146}
147
148impl TryFrom<Event> for SendMessageEvent {
149 type Error = ();
150
151 fn try_from(event: Event) -> Result<Self, Self::Error> {
152 Ok(match event {
153 Event::SendWithdrawExpired(inner) => SendMessageEvent::SendWithdrawExpired(inner),
154 Event::SendWithdrawRequest(inner) => SendMessageEvent::SendWithdrawRequest(inner),
155 Event::SendLockedTransfer(inner) => SendMessageEvent::SendLockedTransfer(inner),
156 Event::SendLockExpired(inner) => SendMessageEvent::SendLockExpired(inner),
157 Event::SendSecretRequest(inner) => SendMessageEvent::SendSecretRequest(inner),
158 Event::SendSecretReveal(inner) => SendMessageEvent::SendSecretReveal(inner),
159 Event::SendUnlock(inner) => SendMessageEvent::SendUnlock(inner),
160 Event::SendProcessed(inner) => SendMessageEvent::SendProcessed(inner),
161 _ => return Err(()),
162 })
163 }
164}
165
166#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)]
168pub enum ContractSendEvent {
169 ContractSendChannelClose(ContractSendChannelClose),
170 ContractSendChannelWithdraw(ContractSendChannelWithdraw),
171 ContractSendChannelSettle(ContractSendChannelSettle),
172 ContractSendChannelUpdateTransfer(ContractSendChannelUpdateTransfer),
173 ContractSendChannelBatchUnlock(ContractSendChannelBatchUnlock),
174 ContractSendSecretReveal(ContractSendSecretReveal),
175}
176
177impl TryFrom<Event> for ContractSendEvent {
178 type Error = ();
179
180 fn try_from(event: Event) -> Result<Self, Self::Error> {
181 Ok(match event {
182 Event::ContractSendChannelClose(inner) =>
183 ContractSendEvent::ContractSendChannelClose(inner),
184 Event::ContractSendChannelWithdraw(inner) =>
185 ContractSendEvent::ContractSendChannelWithdraw(inner),
186 Event::ContractSendChannelSettle(inner) =>
187 ContractSendEvent::ContractSendChannelSettle(inner),
188 Event::ContractSendChannelUpdateTransfer(inner) =>
189 ContractSendEvent::ContractSendChannelUpdateTransfer(inner),
190 Event::ContractSendChannelBatchUnlock(inner) =>
191 ContractSendEvent::ContractSendChannelBatchUnlock(inner),
192 Event::ContractSendSecretReveal(inner) =>
193 ContractSendEvent::ContractSendSecretReveal(inner),
194 _ => return Err(()),
195 })
196 }
197}
198
199#[derive(Clone, Debug, Eq, Serialize, Deserialize)]
201#[cfg_attr(not(test), derive(PartialEq))]
202pub struct SendMessageEventInner {
203 pub recipient: Address,
204 pub recipient_metadata: Option<AddressMetadata>,
205 pub canonical_identifier: CanonicalIdentifier,
206 pub message_identifier: MessageIdentifier,
207}
208
209impl SendMessageEventInner {
210 pub fn queue_identifier(&self) -> QueueIdentifier {
211 QueueIdentifier {
212 recipient: self.recipient,
213 canonical_identifier: self.canonical_identifier.clone(),
214 }
215 }
216}
217
218#[cfg(test)]
219impl PartialEq for SendMessageEventInner {
220 fn eq(&self, other: &Self) -> bool {
221 self.recipient == other.recipient &&
222 self.recipient_metadata == other.recipient_metadata &&
223 self.canonical_identifier == other.canonical_identifier
224 }
225}
226
227#[derive(Deref, Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
229pub struct SendWithdrawRequest {
230 #[deref]
231 #[serde(flatten)]
232 pub inner: SendMessageEventInner,
233 pub total_withdraw: TokenAmount,
234 pub participant: Address,
235 pub expiration: BlockExpiration,
236 pub nonce: Nonce,
237 pub coop_settle: bool,
238}
239
240#[derive(Deref, Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
242pub struct SendWithdrawConfirmation {
243 #[deref]
244 pub inner: SendMessageEventInner,
245 pub participant: Address,
246 pub total_withdraw: TokenAmount,
247 pub nonce: Nonce,
248 pub expiration: BlockExpiration,
249}
250
251#[derive(Deref, Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
253pub struct SendWithdrawExpired {
254 #[deref]
255 pub inner: SendMessageEventInner,
256 pub participant: Address,
257 pub total_withdraw: TokenAmount,
258 pub nonce: Nonce,
259 pub expiration: BlockExpiration,
260}
261
262#[derive(Deref, Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
264pub struct SendLockedTransfer {
265 #[deref]
266 pub inner: SendMessageEventInner,
267 pub transfer: LockedTransferState,
268}
269
270#[derive(Deref, Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
273pub struct SendSecretRequest {
274 #[deref]
275 pub inner: SendMessageEventInner,
276 pub payment_identifier: PaymentIdentifier,
277 pub amount: TokenAmount,
278 pub expiration: BlockExpiration,
279 pub secrethash: SecretHash,
280}
281
282#[derive(Deref, Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
306pub struct SendSecretReveal {
307 #[deref]
308 pub inner: SendMessageEventInner,
309 pub secret: Secret,
310 pub secrethash: SecretHash,
311}
312
313#[derive(Deref, Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
315pub struct SendLockExpired {
316 #[deref]
317 pub inner: SendMessageEventInner,
318 pub balance_proof: BalanceProofState,
319 pub secrethash: SecretHash,
320}
321
322#[derive(Deref, Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
338pub struct SendUnlock {
339 #[deref]
340 pub inner: SendMessageEventInner,
341 pub payment_identifier: PaymentIdentifier,
342 pub token_address: TokenAddress,
343 pub balance_proof: BalanceProofState,
344 pub secret: Secret,
345 pub secrethash: SecretHash,
346}
347
348#[derive(Deref, Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
350pub struct SendProcessed {
351 #[deref]
352 pub inner: SendMessageEventInner,
353}
354
355#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
363pub struct PaymentReceivedSuccess {
364 pub token_network_registry_address: TokenNetworkRegistryAddress,
365 pub token_network_address: TokenNetworkAddress,
366 pub identifier: PaymentIdentifier,
367 pub amount: TokenAmount,
368 pub initiator: Address,
369}
370
371#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
389pub struct PaymentSentSuccess {
390 pub token_network_registry_address: TokenNetworkRegistryAddress,
391 pub token_network_address: TokenNetworkAddress,
392 pub identifier: PaymentIdentifier,
393 pub amount: TokenAmount,
394 pub target: Address,
395 pub secret: Secret,
396 pub route: Vec<Address>,
397}
398
399#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
401pub struct UnlockSuccess {
402 pub identifier: PaymentIdentifier,
403 pub secrethash: SecretHash,
404}
405
406#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
408pub struct UnlockClaimSuccess {
409 pub identifier: PaymentIdentifier,
410 pub secrethash: SecretHash,
411}
412
413#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)]
415pub struct ContractSendEventInner {
416 pub triggered_by_blockhash: BlockHash,
417}
418
419#[derive(Deref, Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
423pub struct ContractSendChannelClose {
424 #[deref]
425 pub inner: ContractSendEventInner,
426 pub canonical_identifier: CanonicalIdentifier,
427 pub balance_proof: Option<BalanceProofState>,
428}
429
430#[derive(Deref, Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
432pub struct ContractSendChannelCoopSettle {
433 #[deref]
434 pub inner: ContractSendEventInner,
435 pub canonical_identifier: CanonicalIdentifier,
436 pub our_total_withdraw: TokenAmount,
437 pub partner_total_withdraw: TokenAmount,
438 pub expiration: BlockExpiration,
439 pub signature_our_withdraw: Signature,
440 pub signature_partner_withdraw: Signature,
441}
442
443#[derive(Deref, Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
445pub struct ContractSendChannelWithdraw {
446 #[deref]
447 pub inner: ContractSendEventInner,
448 pub canonical_identifier: CanonicalIdentifier,
449 pub total_withdraw: TokenAmount,
450 pub expiration: BlockExpiration,
451 pub partner_signature: Signature,
452}
453
454#[derive(Deref, Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
456pub struct ContractSendChannelSettle {
457 #[deref]
458 pub inner: ContractSendEventInner,
459 pub canonical_identifier: CanonicalIdentifier,
460}
461
462#[derive(Deref, Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
464pub struct ContractSendChannelUpdateTransfer {
465 #[deref]
466 pub inner: ContractSendEventInner,
467 pub expiration: BlockExpiration,
468 pub balance_proof: BalanceProofState,
469}
470
471#[derive(Deref, Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
485pub struct ContractSendChannelBatchUnlock {
486 #[deref]
487 pub inner: ContractSendEventInner,
488 pub canonical_identifier: CanonicalIdentifier,
489 pub sender: Address,
490}
491
492#[derive(Deref, Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
494pub struct ContractSendSecretReveal {
495 #[deref]
496 pub inner: ContractSendEventInner,
497 pub expiration: BlockExpiration,
498 pub secret: Secret,
499}
500
501#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
503pub struct ErrorInvalidActionWithdraw {
504 pub attemped_withdraw: TokenAmount,
505 pub reason: String,
506}
507
508#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
510pub struct ErrorInvalidReceivedWithdrawRequest {
511 pub attemped_withdraw: TokenAmount,
512 pub reason: String,
513}
514
515#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
517pub struct ErrorInvalidReceivedWithdrawConfirmation {
518 pub attemped_withdraw: TokenAmount,
519 pub reason: String,
520}
521
522#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
524pub struct ErrorInvalidReceivedWithdrawExpired {
525 pub attemped_withdraw: TokenAmount,
526 pub reason: String,
527}
528
529#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
531pub struct ErrorInvalidActionSetRevealTimeout {
532 pub reveal_timeout: RevealTimeout,
533 pub reason: String,
534}
535
536#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
542pub struct ErrorPaymentSentFailed {
543 pub token_network_registry_address: TokenNetworkRegistryAddress,
544 pub token_network_address: TokenNetworkAddress,
545 pub identifier: PaymentIdentifier,
546 pub target: Address,
547 pub reason: String,
548}
549
550#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
552pub struct ErrorUnlockFailed {
553 pub identifier: PaymentIdentifier,
554 pub secrethash: SecretHash,
555 pub reason: String,
556}
557
558#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
568pub struct ErrorRouteFailed {
569 pub secrethash: SecretHash,
570 pub route: Vec<Address>,
571 pub token_network_address: TokenNetworkAddress,
572}
573
574#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
576pub struct ErrorInvalidActionCoopSettle {
577 pub attempted_withdraw: TokenAmount,
578 pub reason: String,
579}
580
581#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
583pub struct ErrorInvalidSecretRequest {
584 pub payment_identifier: PaymentIdentifier,
585 pub intended_amount: TokenAmount,
586 pub actual_amount: TokenAmount,
587}
588
589#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
591pub struct ErrorInvalidReceivedLockedTransfer {
592 pub payment_identifier: PaymentIdentifier,
593 pub reason: String,
594}
595
596#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
598pub struct ErrorInvalidReceivedLockExpired {
599 pub secrethash: SecretHash,
600 pub reason: String,
601}
602
603#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
605pub struct ErrorInvalidReceivedTransferRefund {
606 pub payment_identifier: PaymentIdentifier,
607 pub reason: String,
608}
609
610#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
612pub struct ErrorInvalidReceivedUnlock {
613 pub secrethash: SecretHash,
614 pub reason: String,
615}
616
617#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
619pub struct ErrorUnlockClaimFailed {
620 pub identifier: PaymentIdentifier,
621 pub secrethash: SecretHash,
622 pub reason: String,
623}
624
625#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
627pub struct ErrorUnexpectedReveal {
628 pub secrethash: SecretHash,
629 pub reason: String,
630}
631
632#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
634pub struct UpdatedServicesAddresses {
635 pub service_address: Address,
636 pub validity: U256,
637}