api/command for encoding actor params
This commit is contained in:
@@ -3,8 +3,10 @@ package full
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
|
||||
"github.com/filecoin-project/go-state-types/cbor"
|
||||
cid "github.com/ipfs/go-cid"
|
||||
"go.uber.org/fx"
|
||||
"golang.org/x/xerrors"
|
||||
@@ -497,6 +499,24 @@ func (a *StateAPI) StateDecodeParams(ctx context.Context, toAddr address.Address
|
||||
return paramType, nil
|
||||
}
|
||||
|
||||
func (a *StateAPI) StateEncodeParams(ctx context.Context, toActCode cid.Cid, method abi.MethodNum, params json.RawMessage) ([]byte, error) {
|
||||
paramType, err := stmgr.GetParamType(toActCode, method)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("getting params type: %w", err)
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(params, ¶mType); err != nil {
|
||||
return nil, xerrors.Errorf("json unmarshal: %w", err)
|
||||
}
|
||||
|
||||
var cbb bytes.Buffer
|
||||
if err := paramType.(cbor.Marshaler).MarshalCBOR(&cbb); err != nil {
|
||||
return nil, xerrors.Errorf("cbor marshal: %w", err)
|
||||
}
|
||||
|
||||
return cbb.Bytes(), nil
|
||||
}
|
||||
|
||||
// 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) {
|
||||
// XXX: Gets the state by computing the tipset state, instead of looking at the parent.
|
||||
|
||||
Reference in New Issue
Block a user