api/command for encoding actor params

This commit is contained in:
Łukasz Magiera
2021-08-20 17:32:57 +02:00
parent 5bdc1862d9
commit 12875a9664
9 changed files with 188 additions and 1 deletions
+20
View File
@@ -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, &paramType); 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.