|
6 | 6 |
|
7 | 7 | use std::any::Any; |
8 | 8 |
|
9 | | -use ssz::{Decode as SszDecode, DecodeError, Encode as SszEncode}; |
10 | 9 | use ssz_derive::{Decode, Encode}; |
11 | 10 | use strata_asm_common::{InterprotoMsg, SubprotocolId}; |
12 | 11 | use strata_asm_txs_bridge_v1::BRIDGE_V1_SUBPROTOCOL_ID; |
13 | | -use strata_bridge_types::{OperatorSelection, WithdrawOutput}; |
| 12 | +use strata_bridge_types::{OperatorIdx, OperatorSelection, WithdrawOutput}; |
| 13 | +use strata_crypto::EvenPublicKey; |
14 | 14 |
|
15 | 15 | /// Incoming message types received from other subprotocols. |
16 | 16 | /// |
17 | 17 | /// This enum represents all possible message types that the bridge subprotocol can |
18 | 18 | /// receive from other subprotocols in the ASM. |
19 | | -#[derive(Clone, Debug, Eq, PartialEq)] |
| 19 | +#[derive(Clone, Debug, Eq, PartialEq, Encode, Decode)] |
| 20 | +#[ssz(enum_behaviour = "union")] |
20 | 21 | pub enum BridgeIncomingMsg { |
21 | 22 | /// Emitted after a checkpoint proof has been validated. Contains the withdrawal command |
22 | 23 | /// specifying the destination descriptor and amount to be withdrawn. |
23 | | - DispatchWithdrawal { |
24 | | - /// The withdrawal output (destination + amount). |
25 | | - output: WithdrawOutput, |
26 | | - /// User's operator selection for withdrawal assignment. |
27 | | - selected_operator: OperatorSelection, |
28 | | - }, |
29 | | -} |
| 24 | + DispatchWithdrawal(DispatchWithdrawalPayload), |
30 | 25 |
|
31 | | -#[derive(Debug, Encode, Decode)] |
32 | | -struct DispatchWithdrawalPayload { |
33 | | - output: WithdrawOutput, |
34 | | - selected_operator: OperatorSelection, |
| 26 | + /// Emitted by the admin subprotocol when the operator set is updated. |
| 27 | + /// Adds new operators by public key and removes existing operators by index. |
| 28 | + UpdateOperatorSet(UpdateOperatorSetPayload), |
35 | 29 | } |
36 | 30 |
|
37 | | -impl SszEncode for BridgeIncomingMsg { |
38 | | - fn is_ssz_fixed_len() -> bool { |
39 | | - false |
40 | | - } |
41 | | - |
42 | | - fn ssz_append(&self, buf: &mut Vec<u8>) { |
43 | | - match self { |
44 | | - Self::DispatchWithdrawal { |
45 | | - output, |
46 | | - selected_operator, |
47 | | - } => { |
48 | | - 0_u8.ssz_append(buf); |
49 | | - DispatchWithdrawalPayload { |
50 | | - output: output.clone(), |
51 | | - selected_operator: *selected_operator, |
52 | | - } |
53 | | - .ssz_append(buf); |
54 | | - } |
55 | | - } |
56 | | - } |
57 | | - |
58 | | - fn ssz_bytes_len(&self) -> usize { |
59 | | - match self { |
60 | | - Self::DispatchWithdrawal { |
61 | | - output, |
62 | | - selected_operator, |
63 | | - } => { |
64 | | - 1 + DispatchWithdrawalPayload { |
65 | | - output: output.clone(), |
66 | | - selected_operator: *selected_operator, |
67 | | - } |
68 | | - .ssz_bytes_len() |
69 | | - } |
70 | | - } |
71 | | - } |
| 31 | +/// Payload for [`BridgeIncomingMsg::DispatchWithdrawal`]. |
| 32 | +#[derive(Clone, Debug, Eq, PartialEq, Encode, Decode)] |
| 33 | +pub struct DispatchWithdrawalPayload { |
| 34 | + /// The withdrawal output (destination + amount). |
| 35 | + pub output: WithdrawOutput, |
| 36 | + /// User's operator selection for withdrawal assignment. |
| 37 | + pub selected_operator: OperatorSelection, |
72 | 38 | } |
73 | 39 |
|
74 | | -impl SszDecode for BridgeIncomingMsg { |
75 | | - fn is_ssz_fixed_len() -> bool { |
76 | | - false |
77 | | - } |
78 | | - |
79 | | - fn from_ssz_bytes(bytes: &[u8]) -> Result<Self, DecodeError> { |
80 | | - let (tag_bytes, payload_bytes) = bytes.split_first().ok_or_else(|| { |
81 | | - DecodeError::BytesInvalid("missing bridge message variant tag".into()) |
82 | | - })?; |
83 | | - |
84 | | - match *tag_bytes { |
85 | | - 0 => { |
86 | | - let payload = DispatchWithdrawalPayload::from_ssz_bytes(payload_bytes)?; |
87 | | - Ok(Self::DispatchWithdrawal { |
88 | | - output: payload.output, |
89 | | - selected_operator: payload.selected_operator, |
90 | | - }) |
91 | | - } |
92 | | - tag => Err(DecodeError::BytesInvalid(format!( |
93 | | - "unknown bridge message variant tag {tag}" |
94 | | - ))), |
95 | | - } |
96 | | - } |
| 40 | +/// Payload for [`BridgeIncomingMsg::UpdateOperatorSet`]. |
| 41 | +#[derive(Clone, Debug, Eq, PartialEq, Encode, Decode)] |
| 42 | +pub struct UpdateOperatorSetPayload { |
| 43 | + /// Operator public keys to add to the bridge multisig. |
| 44 | + pub add_members: Vec<EvenPublicKey>, |
| 45 | + /// Operator indices to remove from the bridge multisig. |
| 46 | + pub remove_members: Vec<OperatorIdx>, |
97 | 47 | } |
98 | 48 |
|
99 | 49 | impl InterprotoMsg for BridgeIncomingMsg { |
|
0 commit comments