From bf66659cda18a3f507e4ed793a5556b3f4384640 Mon Sep 17 00:00:00 2001 From: Shashank <99187193+sudo-shashank@users.noreply.github.com> Date: Fri, 5 Jan 2024 16:01:28 +0530 Subject: [PATCH] Add get pending transaction method for multisig (#235) --- Cargo.lock | 1 + actors/multisig/src/v12/state.rs | 10 +-- actors/multisig/src/v12/types.rs | 10 +-- fil_actor_interface/Cargo.toml | 1 + .../src/builtin/multisig/mod.rs | 74 +++++++++++++-- fil_actor_interface/src/lib.rs | 1 + fil_actor_interface/src/macros.rs | 90 +++++++++++++++++++ 7 files changed, 172 insertions(+), 15 deletions(-) create mode 100644 fil_actor_interface/src/macros.rs diff --git a/Cargo.lock b/Cargo.lock index 34bd60f6..bc87c01d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -764,6 +764,7 @@ dependencies = [ "fvm_shared 2.6.0", "fvm_shared 3.6.0", "fvm_shared 4.0.0", + "integer-encoding", "lazy_static", "multihash", "num", diff --git a/actors/multisig/src/v12/state.rs b/actors/multisig/src/v12/state.rs index f5d38a77..4421eaf9 100644 --- a/actors/multisig/src/v12/state.rs +++ b/actors/multisig/src/v12/state.rs @@ -5,11 +5,11 @@ use cid::Cid; use fil_actors_shared::v12::{ActorError, Config, Map2, DEFAULT_HAMT_CONFIG}; use fvm_ipld_blockstore::Blockstore; use fvm_ipld_encoding::tuple::*; -use fvm_shared::address::Address; -use fvm_shared::bigint::BigInt; -use fvm_shared::bigint::Integer; -use fvm_shared::clock::ChainEpoch; -use fvm_shared::econ::TokenAmount; +use fvm_shared4::address::Address; +use fvm_shared4::bigint::BigInt; +use fvm_shared4::bigint::Integer; +use fvm_shared4::clock::ChainEpoch; +use fvm_shared4::econ::TokenAmount; use indexmap::IndexMap; use num_traits::Zero; diff --git a/actors/multisig/src/v12/types.rs b/actors/multisig/src/v12/types.rs index 151dbbeb..c3689902 100644 --- a/actors/multisig/src/v12/types.rs +++ b/actors/multisig/src/v12/types.rs @@ -5,11 +5,11 @@ use std::fmt::Display; use fvm_ipld_encoding::tuple::*; use fvm_ipld_encoding::{strict_bytes, RawBytes}; -use fvm_shared::address::Address; -use fvm_shared::clock::ChainEpoch; -use fvm_shared::econ::TokenAmount; -use fvm_shared::error::ExitCode; -use fvm_shared::MethodNum; +use fvm_shared4::address::Address; +use fvm_shared4::clock::ChainEpoch; +use fvm_shared4::econ::TokenAmount; +use fvm_shared4::error::ExitCode; +use fvm_shared4::MethodNum; use serde::{Deserialize, Serialize}; use fil_actors_shared::v12::MapKey; diff --git a/fil_actor_interface/Cargo.toml b/fil_actor_interface/Cargo.toml index c467c07b..92edd51c 100644 --- a/fil_actor_interface/Cargo.toml +++ b/fil_actor_interface/Cargo.toml @@ -30,6 +30,7 @@ fvm_ipld_encoding.workspace = true fvm_shared = { workspace = true } fvm_shared3 = { workspace = true } fvm_shared4 = { workspace = true } +integer-encoding.workspace = true lazy_static.workspace = true multihash = { workspace = true, features = ["identity"] } num.workspace = true diff --git a/fil_actor_interface/src/builtin/multisig/mod.rs b/fil_actor_interface/src/builtin/multisig/mod.rs index 6434fee2..f4372787 100644 --- a/fil_actor_interface/src/builtin/multisig/mod.rs +++ b/fil_actor_interface/src/builtin/multisig/mod.rs @@ -1,12 +1,15 @@ // Copyright 2019-2023 ChainSafe Systems // SPDX-License-Identifier: Apache-2.0, MIT -use crate::convert::from_token_v3_to_v2; +use crate::convert::{ + from_address_v3_to_v2, from_address_v4_to_v2, from_token_v3_to_v2, from_token_v4_to_v2, +}; use anyhow::Context; use cid::Cid; use fvm_ipld_blockstore::Blockstore; -use fvm_shared::{clock::ChainEpoch, econ::TokenAmount}; -use serde::Serialize; +use fvm_ipld_encoding::RawBytes; +use fvm_shared::{address::Address, clock::ChainEpoch, econ::TokenAmount, MethodNum}; +use serde::{Deserialize, Serialize}; use crate::io::get_obj; @@ -21,7 +24,18 @@ pub enum State { V9(fil_actor_multisig_state::v9::State), V10(fil_actor_multisig_state::v10::State), V11(fil_actor_multisig_state::v11::State), - V12(fil_actor_multisig_state::v11::State), + V12(fil_actor_multisig_state::v12::State), +} + +/// Transaction type used in multisig actor +#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)] +pub struct Transaction { + pub id: i64, + pub to: Address, + pub value: TokenAmount, + pub method: MethodNum, + pub params: RawBytes, + pub approved: Vec
, } pub fn is_v8_multisig_cid(cid: &Cid) -> bool { @@ -84,7 +98,57 @@ impl State { State::V9(st) => st.amount_locked(height), State::V10(st) => from_token_v3_to_v2(st.amount_locked(height)), State::V11(st) => from_token_v3_to_v2(st.amount_locked(height)), - State::V12(st) => from_token_v3_to_v2(st.amount_locked(height)), + State::V12(st) => from_token_v4_to_v2(st.amount_locked(height)), }) } + + /// Returns pending transactions for the given multisig wallet + pub fn get_pending_txn