-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathevents.rs
More file actions
134 lines (122 loc) · 4.61 KB
/
Copy pathevents.rs
File metadata and controls
134 lines (122 loc) · 4.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
use std::fmt::Display;
use serde::{Deserialize, Serialize};
use twmq::job::RequeuePosition;
use crate::{
eoa::{
store::{SubmittedTransaction, TransactionData},
worker::{ConfirmedTransactionWithRichReceipt, EoaExecutorWorkerError},
},
webhook::envelope::{
BareWebhookNotificationEnvelope, SerializableFailData, SerializableNackData,
SerializableSuccessData, StageEvent,
},
};
pub struct EoaExecutorEvent {
pub transaction_data: TransactionData,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EoaSendAttemptNackData {
pub nonce: u64,
pub error: EoaExecutorWorkerError,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum EoaExecutorStage {
SendAttempt,
TransactionReplaced,
TransactionConfirmed,
}
impl Display for EoaExecutorStage {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
EoaExecutorStage::SendAttempt => write!(f, "send_attempt"),
EoaExecutorStage::TransactionReplaced => write!(f, "transaction_replaced"),
EoaExecutorStage::TransactionConfirmed => write!(f, "transaction_confirmed"),
}
}
}
const EXECUTOR_NAME: &str = "eoa";
impl EoaExecutorEvent {
pub fn send_attempt_success_envelope(
&self,
submitted_transaction: SubmittedTransaction,
) -> BareWebhookNotificationEnvelope<SerializableSuccessData<SubmittedTransaction>> {
BareWebhookNotificationEnvelope {
transaction_id: self.transaction_data.transaction_id.clone(),
executor_name: EXECUTOR_NAME.to_string(),
stage_name: EoaExecutorStage::SendAttempt.to_string(),
event_type: StageEvent::Success,
payload: SerializableSuccessData {
result: submitted_transaction.clone(),
},
}
}
pub fn send_attempt_nack_envelope(
&self,
nonce: u64,
error: EoaExecutorWorkerError,
attempt_number: u32,
) -> BareWebhookNotificationEnvelope<SerializableNackData<EoaSendAttemptNackData>> {
BareWebhookNotificationEnvelope {
transaction_id: self.transaction_data.transaction_id.clone(),
executor_name: EXECUTOR_NAME.to_string(),
stage_name: EoaExecutorStage::SendAttempt.to_string(),
event_type: StageEvent::Nack,
payload: SerializableNackData {
error: EoaSendAttemptNackData {
nonce,
error: error.clone(),
},
delay_ms: None,
position: RequeuePosition::Last,
attempt_number,
max_attempts: None,
next_retry_at: None,
},
}
}
pub fn transaction_replaced_envelope(
&self,
replaced_transaction: SubmittedTransaction,
) -> BareWebhookNotificationEnvelope<SerializableSuccessData<SubmittedTransaction>> {
BareWebhookNotificationEnvelope {
transaction_id: self.transaction_data.transaction_id.clone(),
executor_name: EXECUTOR_NAME.to_string(),
stage_name: EoaExecutorStage::TransactionReplaced.to_string(),
event_type: StageEvent::Success,
payload: SerializableSuccessData {
result: replaced_transaction.clone(),
},
}
}
pub fn transaction_confirmed_envelope(
&self,
confirmed_transaction: ConfirmedTransactionWithRichReceipt,
) -> BareWebhookNotificationEnvelope<SerializableSuccessData<ConfirmedTransactionWithRichReceipt>>
{
BareWebhookNotificationEnvelope {
transaction_id: self.transaction_data.transaction_id.clone(),
executor_name: EXECUTOR_NAME.to_string(),
stage_name: EoaExecutorStage::TransactionConfirmed.to_string(),
event_type: StageEvent::Success,
payload: SerializableSuccessData {
result: confirmed_transaction.clone(),
},
}
}
pub fn transaction_failed_envelope(
&self,
error: EoaExecutorWorkerError,
final_attempt_number: u32,
) -> BareWebhookNotificationEnvelope<SerializableFailData<EoaExecutorWorkerError>> {
BareWebhookNotificationEnvelope {
transaction_id: self.transaction_data.transaction_id.clone(),
executor_name: EXECUTOR_NAME.to_string(),
stage_name: EoaExecutorStage::SendAttempt.to_string(),
event_type: StageEvent::Failure,
payload: SerializableFailData {
error: error.clone(),
final_attempt_number,
},
}
}
}