fil_actor_multisig_state/v13/
types.rs

1// Copyright 2019-2022 ChainSafe Systems
2// SPDX-License-Identifier: Apache-2.0, MIT
3
4use std::fmt::Display;
5
6use fvm_ipld_encoding::tuple::*;
7use fvm_ipld_encoding::{RawBytes, strict_bytes};
8use fvm_shared4::MethodNum;
9use fvm_shared4::address::Address;
10use fvm_shared4::clock::ChainEpoch;
11use fvm_shared4::econ::TokenAmount;
12use fvm_shared4::error::ExitCode;
13use serde::{Deserialize, Serialize};
14
15use fil_actors_shared::v13::MapKey;
16
17/// SignersMax is the maximum number of signers allowed in a multisig. If more
18/// are required, please use a combining tree of multisigs.
19pub const SIGNERS_MAX: usize = 256;
20
21/// Transaction ID type
22#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, Hash, Eq, PartialEq, PartialOrd)]
23#[serde(transparent)]
24pub struct TxnID(pub i64);
25
26impl MapKey for TxnID {
27    fn from_bytes(b: &[u8]) -> Result<Self, String> {
28        i64::from_bytes(b).map(TxnID)
29    }
30
31    fn to_bytes(&self) -> Result<Vec<u8>, String> {
32        self.0.to_bytes()
33    }
34}
35
36impl Display for TxnID {
37    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
38        write!(f, "{}", self.0)
39    }
40}
41
42/// Transaction type used in multisig actor
43#[derive(Clone, PartialEq, Eq, Debug, Serialize_tuple, Deserialize_tuple)]
44pub struct Transaction {
45    pub to: Address,
46    pub value: TokenAmount,
47    pub method: MethodNum,
48    pub params: RawBytes,
49
50    pub approved: Vec<Address>,
51}
52
53/// Data for a BLAKE2B-256 to be attached to methods referencing proposals via TXIDs.
54/// Ensures the existence of a cryptographic reference to the original proposal. Useful
55/// for offline signers and for protection when reorgs change a multisig TXID.
56///
57/// Requester - The requesting multisig wallet member.
58/// All other fields - From the "Transaction" struct.
59#[derive(Serialize_tuple, Debug)]
60pub struct ProposalHashData<'a> {
61    pub requester: Option<&'a Address>,
62    pub to: &'a Address,
63    pub value: &'a TokenAmount,
64    pub method: &'a MethodNum,
65    pub params: &'a RawBytes,
66}
67
68/// Constructor parameters for multisig actor.
69#[derive(Serialize_tuple, Deserialize_tuple)]
70pub struct ConstructorParams {
71    pub signers: Vec<Address>,
72    pub num_approvals_threshold: u64,
73    pub unlock_duration: ChainEpoch,
74    // * Added in v2
75    pub start_epoch: ChainEpoch,
76}
77
78/// Propose method call parameters.
79#[derive(Serialize_tuple, Deserialize_tuple)]
80pub struct ProposeParams {
81    pub to: Address,
82    pub value: TokenAmount,
83    pub method: MethodNum,
84    pub params: RawBytes,
85}
86
87/// Propose method call return.
88#[derive(Serialize_tuple, Deserialize_tuple)]
89pub struct ProposeReturn {
90    /// TxnID is the ID of the proposed transaction.
91    pub txn_id: TxnID,
92    /// Applied indicates if the transaction was applied as opposed to proposed but not applied
93    /// due to lack of approvals.
94    pub applied: bool,
95    /// Code is the exitcode of the transaction, if Applied is false this field should be ignored.
96    pub code: ExitCode,
97    /// Ret is the return value of the transaction, if Applied is false this field should
98    /// be ignored.
99    pub ret: RawBytes,
100}
101
102/// Parameters for approve and cancel multisig functions.
103#[derive(Clone, PartialEq, Eq, Debug, Serialize_tuple, Deserialize_tuple)]
104pub struct TxnIDParams {
105    pub id: TxnID,
106    /// Optional hash of proposal to ensure an operation can only apply to a
107    /// specific proposal.
108    #[serde(with = "strict_bytes")]
109    pub proposal_hash: Vec<u8>,
110}
111
112/// Parameters for approve and cancel multisig functions.
113#[derive(Serialize_tuple, Deserialize_tuple)]
114pub struct ApproveReturn {
115    /// Applied indicates if the transaction was applied as opposed to proposed but not applied
116    /// due to lack of approvals
117    pub applied: bool,
118    /// Code is the exitcode of the transaction, if Applied is false this field should be ignored.
119    pub code: ExitCode,
120    /// Ret is the return value of the transaction, if Applied is false this field should
121    /// be ignored.
122    pub ret: RawBytes,
123}
124
125/// Add signer params.
126#[derive(Serialize_tuple, Deserialize_tuple)]
127pub struct AddSignerParams {
128    pub signer: Address,
129    pub increase: bool,
130}
131
132/// Remove signer params.
133#[derive(Serialize_tuple, Deserialize_tuple)]
134pub struct RemoveSignerParams {
135    pub signer: Address,
136    pub decrease: bool,
137}
138
139/// Swap signer multisig method params
140#[derive(Serialize_tuple, Deserialize_tuple)]
141pub struct SwapSignerParams {
142    pub from: Address,
143    pub to: Address,
144}
145
146/// Propose method call parameters
147#[derive(Serialize_tuple, Deserialize_tuple)]
148pub struct ChangeNumApprovalsThresholdParams {
149    pub new_threshold: u64,
150}
151
152/// Lock balance call params.
153#[derive(Serialize_tuple, Deserialize_tuple)]
154pub struct LockBalanceParams {
155    pub start_epoch: ChainEpoch,
156    pub unlock_duration: ChainEpoch,
157    pub amount: TokenAmount,
158}