mirror of
https://github.com/filecoin-project/lotus.git
synced 2025-08-24 09:22:17 +08:00

Implement the Lotus V2 APIs for : * `StateGetActor` - enhanced to accept tipset selector. * `StateGetID` - enhanced to accept tipset selector / renamed from `LookupID` in v1 for consistency. Tests are added to exercise the end-to-end API call through JSON rpc with the raw wire format of the JSON-RPC request. Additional factory functions are added for `TipSetLimit`, a new concept to specify a limit for tipsets either as absolute height or relative to some tipset selector. The future State message search APIs in v2 aim to use Limit in upcoming PRs. To unblock progress in making incremental progress at v2 apis I am removing the implementation of StateSimulate and StateCompute in light of discussions at #13028.
52 lines
1.6 KiB
Go
52 lines
1.6 KiB
Go
package full
|
|
|
|
import (
|
|
"context"
|
|
|
|
"go.uber.org/fx"
|
|
"golang.org/x/xerrors"
|
|
|
|
"github.com/filecoin-project/go-address"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
)
|
|
|
|
var _ StateModuleAPIv2 = (*StateModuleV2)(nil)
|
|
|
|
type StateModuleAPIv2 interface {
|
|
StateGetActor(context.Context, address.Address, types.TipSetSelector) (*types.Actor, error)
|
|
StateGetID(context.Context, address.Address, types.TipSetSelector) (*address.Address, error)
|
|
}
|
|
|
|
type StateModuleV2 struct {
|
|
State StateAPI
|
|
Chain ChainModuleV2
|
|
|
|
fx.In
|
|
}
|
|
|
|
// TODO: Discussion: do we want to optionally strict the type of selectors that
|
|
// can be supplied here to avoid foot-guns? For example, only accept TipSetKey
|
|
// using a soft condition check here to avoid potential foot-gun but also make it
|
|
// easy to expand in the future without breaking changes if users asked for it.
|
|
|
|
func (s *StateModuleV2) StateGetActor(ctx context.Context, addr address.Address, selector types.TipSetSelector) (*types.Actor, error) {
|
|
ts, err := s.Chain.ChainGetTipSet(ctx, selector)
|
|
if err != nil {
|
|
return nil, xerrors.Errorf("getting tipset: %w", err)
|
|
}
|
|
return s.State.StateGetActor(ctx, addr, ts.Key())
|
|
}
|
|
|
|
func (s *StateModuleV2) StateGetID(ctx context.Context, addr address.Address, selector types.TipSetSelector) (*address.Address, error) {
|
|
ts, err := s.Chain.ChainGetTipSet(ctx, selector)
|
|
if err != nil {
|
|
return nil, xerrors.Errorf("getting tipset: %w", err)
|
|
}
|
|
id, err := s.State.StateLookupID(ctx, addr, ts.Key())
|
|
if err != nil {
|
|
return nil, xerrors.Errorf("looking up ID: %w", err)
|
|
}
|
|
return &id, nil
|
|
}
|