Skip to content

Commit

Permalink
Merge branch 'main' into prepare-release-v9.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sudo-shashank authored Jan 5, 2024
2 parents a141799 + bf66659 commit 66ef0ed
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 15 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions actors/multisig/src/v12/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 5 additions & 5 deletions actors/multisig/src/v12/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions fil_actor_interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
74 changes: 69 additions & 5 deletions fil_actor_interface/src/builtin/multisig/mod.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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<Address>,
}

pub fn is_v8_multisig_cid(cid: &Cid) -> bool {
Expand Down Expand Up @@ -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<BS: Blockstore>(&self, store: &BS) -> anyhow::Result<Vec<Transaction>> {
let mut res = Vec::new();
match self {
State::V8(st) => {
let txns = fil_actors_shared::v8::make_map_with_root::<
BS,
fil_actor_multisig_state::v8::Transaction,
>(&st.pending_txs, store)?;
crate::parse_pending_transactions!(res, txns);
Ok(res)
}
State::V9(st) => {
let txns = fil_actors_shared::v9::make_map_with_root::<
BS,
fil_actor_multisig_state::v9::Transaction,
>(&st.pending_txs, store)?;
crate::parse_pending_transactions!(res, txns);
Ok(res)
}
State::V10(st) => {
let txns = fil_actors_shared::v10::make_map_with_root::<
BS,
fil_actor_multisig_state::v10::Transaction,
>(&st.pending_txs, store)?;
crate::parse_pending_transactions_v3!(res, txns);
Ok(res)
}
State::V11(st) => {
let txns = fil_actors_shared::v11::make_map_with_root::<
BS,
fil_actor_multisig_state::v11::Transaction,
>(&st.pending_txs, store)?;
crate::parse_pending_transactions_v3!(res, txns);
Ok(res)
}
State::V12(st) => {
let txns = fil_actor_multisig_state::v12::PendingTxnMap::load(
store,
&st.pending_txs,
fil_actor_multisig_state::v12::PENDING_TXN_CONFIG,
"pending txns",
)
.expect("Could not load pending transactions");
crate::parse_pending_transactions_v4!(res, txns);
Ok(res)
}
}
}
}
1 change: 1 addition & 0 deletions fil_actor_interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
mod builtin;
mod convert;
mod io;
mod macros;
mod r#mod;

pub use self::builtin::*;
Expand Down
90 changes: 90 additions & 0 deletions fil_actor_interface/src/macros.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Copyright 2019-2022 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

/// This macro iterates over each transaction, decodes the transaction key using variable-length integer encoding,
/// and constructs a Transaction object with the decoded data.
///
/// Parameters:
/// - `$res`: A mutable reference to a collection where the parsed transactions will be stored.
/// - `$txns`: A collection of transaction data to be parsed.
#[macro_export]
macro_rules! parse_pending_transactions {
($res:ident, $txns:expr) => {
$txns.for_each(|tx_key, txn| {
match integer_encoding::VarInt::decode_var(&tx_key) {
Some((tx_id, _)) => {
$res.push(Transaction {
id: tx_id,
to: txn.to,
value: txn.value.clone(),
method: txn.method,
params: txn.params.clone(),
approved: txn.approved.clone(),
});
}
None => anyhow::bail!("Error decoding varint"),
}
Ok(())
})?;
};
}

/// This macro iterates over each transaction, decodes the transaction key, and constructs a Transaction object
/// with additional processing for address and token formats using `from_address_v3_to_v2` and `from_token_v3_to_v2`.
///
/// Parameters:
/// - `$res`: A mutable reference to a collection where the parsed transactions will be stored.
/// - `$txns`: A collection of transaction data to be parsed.
#[macro_export]
macro_rules! parse_pending_transactions_v3 {
($res:ident, $txns:expr) => {
$txns.for_each(|tx_key, txn| {
match integer_encoding::VarInt::decode_var(&tx_key) {
Some((tx_id, _)) => {
$res.push(Transaction {
id: tx_id,
to: from_address_v3_to_v2(txn.to),
value: from_token_v3_to_v2(txn.value.clone()),
method: txn.method,
params: txn.params.clone(),
approved: txn
.approved
.iter()
.map(|&addr| from_address_v3_to_v2(addr))
.collect(),
});
}
None => anyhow::bail!("Error decoding varint"),
}
Ok(())
})?;
};
}

/// This macro iterates over each transaction, assumes that transaction id's are directly available and not encoded.
/// It constructs Transaction objects with transformations for address and token data from version 4 to version 2
/// using `from_address_v4_to_v2` and `from_token_v4_to_v2`.
///
/// Parameters:
/// - `$res`: A mutable reference to a collection where the parsed transactions will be stored.
/// - `$txns`: A collection of transaction data to be parsed.
#[macro_export]
macro_rules! parse_pending_transactions_v4 {
($res:ident, $txns:expr) => {
$txns.for_each(|tx_id, txn| {
$res.push(Transaction {
id: tx_id.0,
to: from_address_v4_to_v2(txn.to),
value: from_token_v4_to_v2(txn.value.clone()),
method: txn.method,
params: txn.params.clone(),
approved: txn
.approved
.iter()
.map(|&addr| from_address_v4_to_v2(addr))
.collect(),
});
Ok(())
})?;
};
}

0 comments on commit 66ef0ed

Please sign in to comment.