raiden_state_machine/types/
event.rs

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/// An enum containing all possible event variants.
38#[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	/// Returns a string of the inner event's type name.
86	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/// An enum of the SendEvent variants.
135#[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/// An enum of the ContractSendEvent variants.
167#[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/// Common message attributes.
200#[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/// Event used by node to request a withdraw from channel partner.
228#[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/// Event used by node to confirm a withdraw for a channel's partner.
241#[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/// Event used by node to expire a withdraw request.
252#[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/// A locked transfer that must be sent to `recipient`.
263#[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/// Event used by a target node to request the secret from the initiator
271/// (`recipient`).
272#[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/// Sends a SecretReveal to another node.
283///
284/// This event is used once the secret is known locally and an action must be
285/// performed on the recipient:
286///
287/// - For receivers in the payee role, it informs the node that the lock has been released and the
288///   token can be claimed, either on-chain or off-chain.
289/// - For receivers in the payer role, it tells the payer that the payee knows the secret and wants
290///   to claim the lock off-chain, so the payer may unlock the lock and send an up-to-date balance
291///   proof to the payee, avoiding on-chain payments which would require the channel to be closed.
292///
293/// For any mediated transfer:
294/// - The initiator will only perform the payer role.
295/// - The target will only perform the payee role.
296/// - The mediators will have `n` channels at the payee role and `n` at the payer role, where `n` is
297///   equal to `1 + number_of_refunds`.
298///
299/// Note:
300///   The payee must only update its local balance once the payer sends an
301///   up-to-date balance-proof message. This is a requirement for keeping the
302///   nodes synchronized. The reveal secret message flows from the recipient
303///   to the sender, so when the secret is learned it is not yet time to
304///   update the balance.
305#[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/// Sends a LockExpired to another node.
314#[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/// Event to send a balance-proof to the counter-party, used after a lock
323/// is unlocked locally allowing the counter-party to claim it.
324///
325/// Used by payers: The initiator and mediator nodes.
326///
327/// Note:
328/// This event has a dual role, it serves as a synchronization and as
329/// balance-proof for the netting channel smart contract.
330///
331/// Nodes need to keep the last known locksroot synchronized. This is
332/// required by the receiving end of a transfer in order to properly
333/// validate. The rule is "only the party that owns the current payment
334/// channel may change it" (remember that a netting channel is composed of
335/// two uni-directional channels), as a consequence the locksroot is only
336/// updated by the recipient once a balance proof message is received.
337#[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/// Send a Processed to another node.
349#[derive(Deref, Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
350pub struct SendProcessed {
351	#[deref]
352	pub inner: SendMessageEventInner,
353}
354
355/// Event emitted when a payee has received a payment.
356///
357/// Note:
358///     A payee knows if a lock claim has failed, but this is not sufficient
359///     information to deduce when a transfer has failed, because the initiator may
360///     try again at a different time and/or with different routes, for this reason
361///     there is no correspoding `EventTransferReceivedFailed`.
362#[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/// Event emitted by the initiator when a transfer is considered successful.
372///
373/// A transfer is considered successful when the initiator's payee hop sends the
374/// reveal secret message, assuming that each hop in the mediator chain has
375/// also learned the secret and unlocked its token off-chain or on-chain.
376///
377/// This definition of successful is used to avoid the following corner case:
378///
379/// - The reveal secret message is sent, since the network is unreliable and we assume byzantine
380///   behavior the message is considered delivered without an acknowledgement.
381/// - The transfer is considered successful because of the above.
382/// - The reveal secret message was not delivered because of actual network problems.
383/// - The lock expires and an EventUnlockFailed follows, contradicting the EventPaymentSentSuccess.
384///
385/// Note:
386///     Mediators cannot use this event, since an off-chain unlock may be locally
387///     successful but there is no knowledge about the global transfer.
388#[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/// Event emitted when a lock unlock succeded.
400#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
401pub struct UnlockSuccess {
402	pub identifier: PaymentIdentifier,
403	pub secrethash: SecretHash,
404}
405
406/// Event emitted when a lock claim succeded.
407#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
408pub struct UnlockClaimSuccess {
409	pub identifier: PaymentIdentifier,
410	pub secrethash: SecretHash,
411}
412
413/// Common attributes of events which represent on-chain transactions.
414#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)]
415pub struct ContractSendEventInner {
416	pub triggered_by_blockhash: BlockHash,
417}
418
419/// Event emitted to close the netting channel.
420/// This event is used when a node needs to prepare the channel to unlock
421/// on-chain.
422#[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/// Event emitted if node wants to cooperatively settle a channel.
431#[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/// Event emitted if node wants to withdraw from current channel balance.
444#[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/// Event emitted if the netting channel must be settled.
455#[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/// Event emitted if the netting channel balance proof must be updated.
463#[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/// Look for unlocks that we should do after settlement
472///
473/// This will only lead to an on-chain unlock if there are locks that can be
474/// unlocked to our benefit.
475///
476/// Usually, we would check if this is the case in the state machine and skip
477/// the creation of this event if no profitable locks are found. But if a
478/// channel was closed with another BP than the latest one, we need to look in
479/// the database for the locks that correspond to the on-chain data. Searching
480/// the database is not possible in the state machine, so we create this event
481/// in every case and do the check in the event handler.
482/// Since locks for both receiving and sending transfers can potentially return
483/// tokens to use, this event leads to 0-2 on-chain transactions.
484#[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/// Event emitted when the lock must be claimed on-chain.
493#[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/// Event emitted when an invalid withdraw is initiated.
502#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
503pub struct ErrorInvalidActionWithdraw {
504	pub attemped_withdraw: TokenAmount,
505	pub reason: String,
506}
507
508/// Event emitted when an invalid withdraw request is received.
509#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
510pub struct ErrorInvalidReceivedWithdrawRequest {
511	pub attemped_withdraw: TokenAmount,
512	pub reason: String,
513}
514
515/// Event emitted when an invalid withdraw confirmation is received.
516#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
517pub struct ErrorInvalidReceivedWithdrawConfirmation {
518	pub attemped_withdraw: TokenAmount,
519	pub reason: String,
520}
521
522/// Event emitted when an invalid withdraw expired event is received.
523#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
524pub struct ErrorInvalidReceivedWithdrawExpired {
525	pub attemped_withdraw: TokenAmount,
526	pub reason: String,
527}
528
529/// Event emitted when an invalid withdraw is initiated.
530#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
531pub struct ErrorInvalidActionSetRevealTimeout {
532	pub reveal_timeout: RevealTimeout,
533	pub reason: String,
534}
535
536/// Event emitted by the payer when a transfer has failed.
537///
538/// Note:
539///     Mediators cannot use this event since they don't know when a transfer
540///     has failed, they may infer about lock successes and failures.
541#[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/// Event emitted when a lock unlock failed.
551#[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/// Event emitted when a route failed.
559/// As a payment can try different routes to reach the intended target
560/// some of the routes can fail. This event is emitted when a route failed.
561/// This means that multiple EventRouteFailed for a given payment and it's
562/// therefore different to EventPaymentSentFailed.
563/// A route can fail for two reasons:
564/// - A refund transfer reaches the initiator (it's not important if this refund transfer is
565///   unlocked or not)
566/// - A lock expires
567#[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/// Event emitted when an invalid coop-settle is initiated.
575#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
576pub struct ErrorInvalidActionCoopSettle {
577	pub attempted_withdraw: TokenAmount,
578	pub reason: String,
579}
580
581/// Event emitted when an invalid SecretRequest is received.
582#[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/// Event emitted when an invalid locked transfer is received.
590#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
591pub struct ErrorInvalidReceivedLockedTransfer {
592	pub payment_identifier: PaymentIdentifier,
593	pub reason: String,
594}
595
596/// Event emitted when an invalid lock expired message is received.
597#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
598pub struct ErrorInvalidReceivedLockExpired {
599	pub secrethash: SecretHash,
600	pub reason: String,
601}
602
603/// Event emitted when an invalid refund transfer is received.
604#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
605pub struct ErrorInvalidReceivedTransferRefund {
606	pub payment_identifier: PaymentIdentifier,
607	pub reason: String,
608}
609
610/// Event emitted when an invalid unlock message is received.
611#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
612pub struct ErrorInvalidReceivedUnlock {
613	pub secrethash: SecretHash,
614	pub reason: String,
615}
616
617/// Event emitted when a lock claim failed.
618#[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/// Event emitted when an unexpected secret reveal message is received.
626#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
627pub struct ErrorUnexpectedReveal {
628	pub secrethash: SecretHash,
629	pub reason: String,
630}
631
632/// Transition used when adding a new service address.
633#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, IntoEvent)]
634pub struct UpdatedServicesAddresses {
635	pub service_address: Address,
636	pub validity: U256,
637}