Skip to content

feat(api): add support for all the actor state in read state API #5666

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ fil_actor_init_state = { version = "22.2" }
fil_actor_market_state = { version = "22.2" }
fil_actor_miner_state = { version = "22.2" }
fil_actor_multisig_state = { version = "22.2" }
fil_actor_paych_state = { version = "22.2" }
fil_actor_power_state = { version = "22.2" }
fil_actor_reward_state = { version = "22.2" }
fil_actor_system_state = { version = "22.2" }
Expand Down
65 changes: 65 additions & 0 deletions src/lotus_json/actor_states/init_state.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright 2019-2025 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT
use super::*;
use crate::shim::actors::init::State;
use ::cid::Cid;

#[derive(Debug, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "PascalCase")]
#[schemars(rename = "InitState")]
pub struct InitStateLotusJson {
#[schemars(with = "LotusJson<Cid>")]
#[serde(with = "crate::lotus_json")]
pub address_map: Cid,
#[serde(rename = "NextID")]
pub next_id: u64,
pub network_name: String,
}

macro_rules! impl_init_state_lotus_json {
($($version:ident),*) => {
impl HasLotusJson for State {
type LotusJson = InitStateLotusJson;

#[cfg(test)]
fn snapshots() -> Vec<(serde_json::Value, Self)> {
vec![(
json!({
"AddressMap": {"/":"baeaaaaa"},
"NextID": 1,
"NetworkName": "testnet"
}),
State::V16(fil_actor_init_state::v16::State {
address_map: Cid::default(),
next_id: 1,
network_name: "testnet".to_string(),
}),
)]
}

fn into_lotus_json(self) -> Self::LotusJson {
match self {
$(
State::$version(state) => InitStateLotusJson {
address_map: state.address_map,
next_id: state.next_id,
network_name: state.network_name,
},
)*
}
}

// Default to V16
fn from_lotus_json(lotus_json: Self::LotusJson) -> Self {
State::V16(fil_actor_init_state::v16::State {
address_map: lotus_json.address_map,
next_id: lotus_json.next_id,
network_name: lotus_json.network_name,
})
}
}
};
}

// implement HasLotusJson for system::State for all versions
impl_init_state_lotus_json!(V16, V15, V14, V13, V12, V11, V10, V9, V8, V0);
6 changes: 1 addition & 5 deletions src/lotus_json/actor_states/market_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub struct MarketStateLotusJson {
pub provider_sectors: Option<Cid>,
}

// Define macros for field handling
// Define macros for common field handling
macro_rules! common_market_state_fields {
($state:expr) => {{
MarketStateLotusJson {
Expand Down Expand Up @@ -165,9 +165,6 @@ macro_rules! implement_state_versions {
State::$version(state) => $handler!(state),
)+
)*
#[allow(unreachable_patterns)]
_ => panic!("Unhandled State variant in into_lotus_json"),

}
}

Expand All @@ -193,7 +190,6 @@ macro_rules! implement_state_versions {
};
}

// Invoke with very explicit syntax
implement_state_versions! {
v8_market_state_fields for [V8];
v9_to_v12_market_state_fields for [V9, V10, V11, V12];
Expand Down
7 changes: 6 additions & 1 deletion src/lotus_json/actor_states/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
use super::*;
mod account_state;
mod cron_state;
mod entry;
mod evm_state;
mod init_state;
mod market_state;
mod miner_state;
mod multisig_state;
mod payment_channel_state;
mod power_states;
mod reward_state;
mod system_state;
mod verified_reg_state;
mod vesting_funds;
103 changes: 103 additions & 0 deletions src/lotus_json/actor_states/multisig_state.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// Copyright 2019-2025 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

use super::*;
use crate::shim::actors::multisig::State;
use crate::shim::address::Address;
use crate::shim::clock::ChainEpoch;
use crate::shim::econ::TokenAmount;
use ::cid::Cid;
use fil_actor_multisig_state::v16::TxnID;

#[derive(Debug, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "PascalCase")]
#[schemars(rename = "MultisigState")]
pub struct MultisigStateLotusJson {
#[schemars(with = "LotusJson<Vec<Address>>")]
#[serde(with = "crate::lotus_json")]
pub signers: Vec<Address>,

pub num_approvals_threshold: u64,

#[serde(rename = "NextTxnID")]
pub next_tx_id: i64,

#[schemars(with = "LotusJson<TokenAmount>")]
#[serde(with = "crate::lotus_json")]
pub initial_balance: TokenAmount,

#[schemars(with = "LotusJson<ChainEpoch>")]
#[serde(with = "crate::lotus_json")]
pub start_epoch: ChainEpoch,

#[schemars(with = "LotusJson<ChainEpoch>")]
#[serde(with = "crate::lotus_json")]
pub unlock_duration: ChainEpoch,

#[schemars(with = "LotusJson<Cid>")]
#[serde(with = "crate::lotus_json", rename = "PendingTxns")]
pub pending_txs: Cid,
}

macro_rules! impl_multisig_state_lotus_json {
($($version:ident),*) => {
impl HasLotusJson for State {
type LotusJson = MultisigStateLotusJson;

#[cfg(test)]
fn snapshots() -> Vec<(serde_json::Value, Self)> {
vec![(
json!({
"signers": [],
"num_approvals_threshold": 0,
"next_tx_id": 0,
"initial_balance": "0",
"start_epoch": 0,
"unlock_duration": 0,
"pending_txs": "0",
}),
State::V16(fil_actor_multisig_state::v16::State {
signers: vec![],
num_approvals_threshold: 0,
next_tx_id: TxnID(0),
initial_balance: TokenAmount::from_atto(0).into(),
start_epoch: 0,
unlock_duration: 0,
pending_txs: Cid::default(),
})
)]
}

fn into_lotus_json(self) -> Self::LotusJson {
match self {
State::V16(state) => MultisigStateLotusJson {
signers: state.signers.into_iter().map(|addr| addr.into()).collect(),
num_approvals_threshold: state.num_approvals_threshold,
next_tx_id: state.next_tx_id.0,
initial_balance: state.initial_balance.into(),
start_epoch: state.start_epoch,
unlock_duration: state.unlock_duration,
pending_txs: state.pending_txs,
},

_ => unimplemented!(),
}
}

// Default to V16
fn from_lotus_json(lotus_json: Self::LotusJson) -> Self {
State::V16(fil_actor_multisig_state::v16::State{
signers: lotus_json.signers.into_iter().map(|addr| addr.into()).collect(),
num_approvals_threshold: lotus_json.num_approvals_threshold,
next_tx_id: TxnID(lotus_json.next_tx_id),
initial_balance: lotus_json.initial_balance.into(),
start_epoch: lotus_json.start_epoch,
unlock_duration: lotus_json.unlock_duration,
pending_txs: lotus_json.pending_txs,
})
}
}
};
}

impl_multisig_state_lotus_json!(V8, V9, V10, V11, V12, V13, V14, V15, V16);
80 changes: 80 additions & 0 deletions src/lotus_json/actor_states/payment_channel_state.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright 2019-2025 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

use super::*;
use crate::shim::actors::paymentchannel::State;
use crate::shim::address::Address;
use crate::shim::clock::ChainEpoch;
use crate::shim::econ::TokenAmount;
use ::cid::Cid;

#[derive(Debug, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "PascalCase")]
#[schemars(rename = "PaymentChannelState")]
pub struct PaymentChannelStateLotusJson {
#[schemars(with = "LotusJson<Address>")]
#[serde(with = "crate::lotus_json")]
pub from: Address,

#[schemars(with = "LotusJson<Address>")]
#[serde(with = "crate::lotus_json")]
pub to: Address,

#[schemars(with = "LotusJson<TokenAmount>")]
#[serde(with = "crate::lotus_json")]
pub to_send: TokenAmount,

#[schemars(with = "LotusJson<ChainEpoch>")]
#[serde(with = "crate::lotus_json")]
pub settling_at: ChainEpoch,

#[schemars(with = "LotusJson<ChainEpoch>")]
#[serde(with = "crate::lotus_json")]
pub min_settle_height: ChainEpoch,

#[schemars(with = "LotusJson<Cid>")]
#[serde(with = "crate::lotus_json")]
pub lane_states: Cid,
}

macro_rules! impl_paych_state_lotus_json {
($($version:ident),*) => {
impl HasLotusJson for State {
type LotusJson = PaymentChannelStateLotusJson;

#[cfg(test)]
fn snapshots() -> Vec<(serde_json::Value, Self)> {
todo!()
}

fn into_lotus_json(self) -> Self::LotusJson {
match self {
$(
State::$version(state) => PaymentChannelStateLotusJson {
from: state.from.into(),
to: state.to.into(),
to_send: state.to_send.into(),
settling_at: state.settling_at,
min_settle_height: state.min_settle_height,
lane_states: state.lane_states,
},
)*
}
}

// Default to V16
fn from_lotus_json(lotus_json: Self::LotusJson) -> Self {
State::V16(fil_actor_paych_state::v16::State {
from: lotus_json.from.into(),
to: lotus_json.to.into(),
to_send: lotus_json.to_send.into(),
settling_at: lotus_json.settling_at,
min_settle_height: lotus_json.min_settle_height,
lane_states: lotus_json.lane_states,
})
}
}
};
}

impl_paych_state_lotus_json!(V9, V10, V11, V12, V13, V14, V15, V16);
Loading
Loading