Skip to content

Commit

Permalink
Add a StateDecodeParams method
Browse files Browse the repository at this point in the history
  • Loading branch information
arajasek committed Oct 30, 2020
1 parent c3d00b0 commit ef5d0ff
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
2 changes: 2 additions & 0 deletions api/api_full.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions api/apistruct/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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)
}
Expand Down
26 changes: 26 additions & 0 deletions documentation/en/api-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
* [StateCirculatingSupply](#StateCirculatingSupply)
* [StateCompute](#StateCompute)
* [StateDealProviderCollateralBounds](#StateDealProviderCollateralBounds)
* [StateDecodeParams](#StateDecodeParams)
* [StateGetActor](#StateGetActor)
* [StateGetReceipt](#StateGetReceipt)
* [StateListActors](#StateListActors)
Expand Down Expand Up @@ -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.

Expand Down
23 changes: 23 additions & 0 deletions node/impl/full/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ef5d0ff

Please sign in to comment.