diff --git a/api/api_full.go b/api/api_full.go index bb1eb15954..f66933d234 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -344,6 +344,8 @@ type FullNode interface { StateReadState(ctx context.Context, actor address.Address, tsk types.TipSetKey) (*ActorState, error) // StateListMessages looks back and returns all messages with a matching to or from address, stopping at the given height. StateListMessages(ctx context.Context, match *MessageMatch, tsk types.TipSetKey, toht abi.ChainEpoch) ([]cid.Cid, error) + // StateDecodeParams attempts to decode the params field of a specified msg based on the methodNum and recipient actor. + StateDecodeParams(ctx context.Context, msg cid.Cid, tsk types.TipSetKey) (interface{}, error) // StateNetworkName returns the name of the network the node is synced to StateNetworkName(context.Context) (dtypes.NetworkName, error) diff --git a/api/apistruct/struct.go b/api/apistruct/struct.go index 3a4ae75a8f..bce97f402b 100644 --- a/api/apistruct/struct.go +++ b/api/apistruct/struct.go @@ -215,6 +215,7 @@ type FullNodeStruct struct { StateGetReceipt func(context.Context, cid.Cid, types.TipSetKey) (*types.MessageReceipt, error) `perm:"read"` StateMinerSectorCount func(context.Context, address.Address, types.TipSetKey) (api.MinerSectors, error) `perm:"read"` StateListMessages func(ctx context.Context, match *api.MessageMatch, tsk types.TipSetKey, toht abi.ChainEpoch) ([]cid.Cid, error) `perm:"read"` + StateDecodeParams func(ctx context.Context, msg cid.Cid, tsk types.TipSetKey) (interface{}, error) `perm:"read"` StateCompute func(context.Context, abi.ChainEpoch, []*types.Message, types.TipSetKey) (*api.ComputeStateOutput, error) `perm:"read"` StateVerifierStatus func(context.Context, address.Address, types.TipSetKey) (*abi.StoragePower, error) `perm:"read"` StateVerifiedClientStatus func(context.Context, address.Address, types.TipSetKey) (*abi.StoragePower, error) `perm:"read"` @@ -1014,6 +1015,10 @@ func (c *FullNodeStruct) StateListMessages(ctx context.Context, match *api.Messa return c.Internal.StateListMessages(ctx, match, tsk, toht) } +func (c *FullNodeStruct) StateDecodeParams(ctx context.Context, msg cid.Cid, tsk types.TipSetKey) (interface{}, error) { + return c.Internal.StateDecodeParams(ctx, msg, tsk) +} + func (c *FullNodeStruct) StateCompute(ctx context.Context, height abi.ChainEpoch, msgs []*types.Message, tsk types.TipSetKey) (*api.ComputeStateOutput, error) { return c.Internal.StateCompute(ctx, height, msgs, tsk) } diff --git a/documentation/en/api-methods.md b/documentation/en/api-methods.md index 4e18d85c91..e4270321bc 100644 --- a/documentation/en/api-methods.md +++ b/documentation/en/api-methods.md @@ -140,6 +140,7 @@ * [StateCirculatingSupply](#StateCirculatingSupply) * [StateCompute](#StateCompute) * [StateDealProviderCollateralBounds](#StateDealProviderCollateralBounds) + * [StateDecodeParams](#StateDecodeParams) * [StateGetActor](#StateGetActor) * [StateGetReceipt](#StateGetReceipt) * [StateListActors](#StateListActors) @@ -3387,6 +3388,31 @@ Response: } ``` +### StateDecodeParams +StateDecodeParams attempts to decode the params field of a specified msg based on the methodNum and recipient actor. + + +Perms: read + +Inputs: +```json +[ + { + "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" + }, + [ + { + "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" + }, + { + "/": "bafy2bzacebp3shtrn43k7g3unredz7fxn4gj533d3o43tqn2p2ipxxhrvchve" + } + ] +] +``` + +Response: `{}` + ### StateGetActor StateGetActor returns the indicated actor's nonce and balance. diff --git a/node/impl/full/state.go b/node/impl/full/state.go index 9a6c772ae3..f81943286a 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -491,6 +491,29 @@ func (a *StateAPI) StateReadState(ctx context.Context, actor address.Address, ts }, nil } +func (a *StateAPI) StateDecodeParams(ctx context.Context, msgCid cid.Cid, tsk types.TipSetKey) (interface{}, error) { + ts, err := a.Chain.GetTipSetFromKey(tsk) + if err != nil { + return nil, xerrors.Errorf("loading tipset %s: %w", tsk, err) + } + state, err := a.stateForTs(ctx, ts) + if err != nil { + return nil, xerrors.Errorf("getting state for tipset: %w", err) + } + + msg, err := a.Chain.GetMessage(msgCid) + if err != nil { + return nil, xerrors.Errorf("loading message: %w", err) + } + + act, err := state.GetActor(msg.To) + if err != nil { + return nil, xerrors.Errorf("getting actor: %w", err) + } + + return vm.DumpParams(act.Code, msg.Method, msg.Params) +} + // This is on StateAPI because miner.Miner requires this, and MinerAPI requires miner.Miner func (a *StateAPI) MinerGetBaseInfo(ctx context.Context, maddr address.Address, epoch abi.ChainEpoch, tsk types.TipSetKey) (*api.MiningBaseInfo, error) { return stmgr.MinerGetBaseInfo(ctx, a.StateManager, a.Beacon, tsk, epoch, maddr, a.ProofVerifier)