2021-03-12 02:21:18 +00:00
|
|
|
package rpcstmgr
|
2020-09-29 15:25:45 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2020-10-09 11:41:09 +00:00
|
|
|
"golang.org/x/xerrors"
|
2020-09-29 15:25:45 +00:00
|
|
|
|
|
|
|
"github.com/filecoin-project/go-address"
|
2020-10-09 11:41:09 +00:00
|
|
|
"github.com/filecoin-project/lotus/api"
|
2021-01-29 20:01:00 +00:00
|
|
|
"github.com/filecoin-project/lotus/blockstore"
|
2020-10-09 11:41:09 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/actors/adt"
|
|
|
|
"github.com/filecoin-project/lotus/chain/actors/builtin/paych"
|
2020-09-29 15:25:45 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/stmgr"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
2020-10-09 11:41:09 +00:00
|
|
|
cbor "github.com/ipfs/go-ipld-cbor"
|
2020-09-29 15:25:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type RPCStateManager struct {
|
2020-10-09 11:41:09 +00:00
|
|
|
gapi api.GatewayAPI
|
|
|
|
cstore *cbor.BasicIpldStore
|
2020-09-29 15:25:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewRPCStateManager(api api.GatewayAPI) *RPCStateManager {
|
2021-01-29 20:01:00 +00:00
|
|
|
cstore := cbor.NewCborStore(blockstore.NewAPIBlockstore(api))
|
2020-10-09 11:41:09 +00:00
|
|
|
return &RPCStateManager{gapi: api, cstore: cstore}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *RPCStateManager) GetPaychState(ctx context.Context, addr address.Address, ts *types.TipSet) (*types.Actor, paych.State, error) {
|
|
|
|
act, err := s.gapi.StateGetActor(ctx, addr, ts.Key())
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
actState, err := paych.Load(adt.WrapStore(ctx, s.cstore), act)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
return act, actState, nil
|
|
|
|
|
2020-09-29 15:25:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *RPCStateManager) LoadActorTsk(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*types.Actor, error) {
|
|
|
|
return s.gapi.StateGetActor(ctx, addr, tsk)
|
|
|
|
}
|
|
|
|
|
2020-09-30 14:36:16 +00:00
|
|
|
func (s *RPCStateManager) LookupID(ctx context.Context, addr address.Address, ts *types.TipSet) (address.Address, error) {
|
|
|
|
return s.gapi.StateLookupID(ctx, addr, ts.Key())
|
|
|
|
}
|
|
|
|
|
2020-09-29 15:25:45 +00:00
|
|
|
func (s *RPCStateManager) ResolveToKeyAddress(ctx context.Context, addr address.Address, ts *types.TipSet) (address.Address, error) {
|
|
|
|
return s.gapi.StateAccountKey(ctx, addr, ts.Key())
|
|
|
|
}
|
|
|
|
|
2020-10-09 11:41:09 +00:00
|
|
|
func (s *RPCStateManager) Call(ctx context.Context, msg *types.Message, ts *types.TipSet) (*api.InvocResult, error) {
|
|
|
|
return nil, xerrors.Errorf("RPCStateManager does not implement StateManager.Call")
|
|
|
|
}
|
|
|
|
|
2020-09-29 15:25:45 +00:00
|
|
|
var _ stmgr.StateManagerAPI = (*RPCStateManager)(nil)
|