Separate API for storageminer
This commit is contained in:
parent
d0cbf02d36
commit
eda03095b0
78
api/api.go
78
api/api.go
@ -3,13 +3,14 @@ package api
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"github.com/libp2p/go-libp2p-core/peer"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-lotus/chain"
|
"github.com/filecoin-project/go-lotus/chain"
|
||||||
"github.com/filecoin-project/go-lotus/chain/address"
|
"github.com/filecoin-project/go-lotus/chain/address"
|
||||||
"github.com/filecoin-project/go-lotus/chain/types"
|
"github.com/filecoin-project/go-lotus/chain/types"
|
||||||
|
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
"github.com/ipfs/go-filestore"
|
"github.com/ipfs/go-filestore"
|
||||||
"github.com/libp2p/go-libp2p-core/peer"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Version provides various build-time information
|
// Version provides various build-time information
|
||||||
@ -37,14 +38,30 @@ type MsgWait struct {
|
|||||||
Receipt types.MessageReceipt
|
Receipt types.MessageReceipt
|
||||||
}
|
}
|
||||||
|
|
||||||
// API is a low-level interface to the Filecoin network
|
type Common interface {
|
||||||
type API interface {
|
|
||||||
// Auth
|
// Auth
|
||||||
AuthVerify(ctx context.Context, token string) ([]string, error)
|
AuthVerify(ctx context.Context, token string) ([]string, error)
|
||||||
AuthNew(ctx context.Context, perms []string) ([]byte, error)
|
AuthNew(ctx context.Context, perms []string) ([]byte, error)
|
||||||
|
|
||||||
// chain
|
// network
|
||||||
|
|
||||||
|
NetPeers(context.Context) ([]peer.AddrInfo, error)
|
||||||
|
NetConnect(context.Context, peer.AddrInfo) error
|
||||||
|
NetAddrsListen(context.Context) (peer.AddrInfo, error)
|
||||||
|
|
||||||
|
// ID returns peerID of libp2p node backing this API
|
||||||
|
ID(context.Context) (peer.ID, error)
|
||||||
|
|
||||||
|
// Version provides information about API provider
|
||||||
|
Version(context.Context) (Version, error)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// FullNode API is a low-level interface to the Filecoin network full node
|
||||||
|
type FullNode interface {
|
||||||
|
Common
|
||||||
|
|
||||||
|
// chain
|
||||||
ChainHead(context.Context) (*chain.TipSet, error) // TODO: check serialization
|
ChainHead(context.Context) (*chain.TipSet, error) // TODO: check serialization
|
||||||
ChainSubmitBlock(ctx context.Context, blk *chain.BlockMsg) error // TODO: check serialization
|
ChainSubmitBlock(ctx context.Context, blk *chain.BlockMsg) error // TODO: check serialization
|
||||||
ChainGetRandomness(context.Context, *chain.TipSet) ([]byte, error)
|
ChainGetRandomness(context.Context, *chain.TipSet) ([]byte, error)
|
||||||
@ -54,35 +71,13 @@ type API interface {
|
|||||||
|
|
||||||
// messages
|
// messages
|
||||||
|
|
||||||
// // wait
|
|
||||||
// // send
|
|
||||||
// // status
|
|
||||||
// // mpool
|
|
||||||
// // // ls / show / rm
|
|
||||||
MpoolPending(context.Context, *chain.TipSet) ([]*chain.SignedMessage, error)
|
MpoolPending(context.Context, *chain.TipSet) ([]*chain.SignedMessage, error)
|
||||||
MpoolPush(context.Context, *chain.SignedMessage) error
|
MpoolPush(context.Context, *chain.SignedMessage) error
|
||||||
|
|
||||||
// dag
|
// FullNodeStruct
|
||||||
|
|
||||||
// // get block
|
|
||||||
// // (cli: show / info)
|
|
||||||
|
|
||||||
// network
|
|
||||||
|
|
||||||
NetPeers(context.Context) ([]peer.AddrInfo, error)
|
|
||||||
NetConnect(context.Context, peer.AddrInfo) error
|
|
||||||
NetAddrsListen(context.Context) (peer.AddrInfo, error)
|
|
||||||
// // ping
|
|
||||||
|
|
||||||
// Struct
|
|
||||||
|
|
||||||
// miner
|
// miner
|
||||||
|
|
||||||
// // create
|
|
||||||
// // owner
|
|
||||||
// // power
|
|
||||||
// // set-price
|
|
||||||
// // set-perrid
|
|
||||||
MinerStart(context.Context, address.Address) error
|
MinerStart(context.Context, address.Address) error
|
||||||
MinerCreateBlock(context.Context, address.Address, *chain.TipSet, []chain.Ticket, chain.ElectionProof, []*chain.SignedMessage) (*chain.BlockMsg, error)
|
MinerCreateBlock(context.Context, address.Address, *chain.TipSet, []chain.Ticket, chain.ElectionProof, []*chain.SignedMessage) (*chain.BlockMsg, error)
|
||||||
|
|
||||||
@ -99,22 +94,6 @@ type API interface {
|
|||||||
// Really not sure where this belongs. It could go on the wallet, or the message pool, or the chain...
|
// Really not sure where this belongs. It could go on the wallet, or the message pool, or the chain...
|
||||||
MpoolGetNonce(context.Context, address.Address) (uint64, error)
|
MpoolGetNonce(context.Context, address.Address) (uint64, error)
|
||||||
|
|
||||||
// // import
|
|
||||||
// // export
|
|
||||||
// // (on cli - cmd to list associations)
|
|
||||||
|
|
||||||
// dht
|
|
||||||
|
|
||||||
// // need ?
|
|
||||||
|
|
||||||
// paych
|
|
||||||
|
|
||||||
// // todo
|
|
||||||
|
|
||||||
// retrieval
|
|
||||||
|
|
||||||
// // retrieve piece
|
|
||||||
|
|
||||||
// Other
|
// Other
|
||||||
|
|
||||||
// ClientImport imports file under the specified path into filestore
|
// ClientImport imports file under the specified path into filestore
|
||||||
@ -127,10 +106,11 @@ type API interface {
|
|||||||
ClientListImports(ctx context.Context) ([]Import, error)
|
ClientListImports(ctx context.Context) ([]Import, error)
|
||||||
|
|
||||||
//ClientListAsks() []Ask
|
//ClientListAsks() []Ask
|
||||||
|
}
|
||||||
// ID returns peerID of libp2p node backing this API
|
|
||||||
ID(context.Context) (peer.ID, error)
|
// Full API is a low-level interface to the Filecoin network storage miner node
|
||||||
|
type StorageMiner interface {
|
||||||
// Version provides information about API provider
|
Common
|
||||||
Version(context.Context) (Version, error)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// NewRPC creates a new http jsonrpc client.
|
// NewRPC creates a new http jsonrpc client.
|
||||||
func NewRPC(addr string, requestHeader http.Header) (api.API, error) {
|
func NewRPC(addr string, requestHeader http.Header) (api.FullNode, error) {
|
||||||
var res api.Struct
|
var res api.FullNodeStruct
|
||||||
_, err := jsonrpc.NewClient(addr, "Filecoin", &res.Internal, requestHeader)
|
_, err := jsonrpc.NewClient(addr, "Filecoin", &res.Internal, requestHeader)
|
||||||
return &res, err
|
return &res, err
|
||||||
}
|
}
|
||||||
|
@ -27,8 +27,8 @@ func WithPerm(ctx context.Context, perms []string) context.Context {
|
|||||||
return context.WithValue(ctx, permCtxKey, perms)
|
return context.WithValue(ctx, permCtxKey, perms)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Permissioned(a API) API {
|
func Permissioned(a FullNode) FullNode {
|
||||||
var out Struct
|
var out FullNodeStruct
|
||||||
|
|
||||||
rint := reflect.ValueOf(&out.Internal).Elem()
|
rint := reflect.ValueOf(&out.Internal).Elem()
|
||||||
ra := reflect.ValueOf(a)
|
ra := reflect.ValueOf(a)
|
||||||
|
122
api/struct.go
122
api/struct.go
@ -14,15 +14,55 @@ import (
|
|||||||
// All permissions are listed in permissioned.go
|
// All permissions are listed in permissioned.go
|
||||||
var _ = AllPermissions
|
var _ = AllPermissions
|
||||||
|
|
||||||
// Struct implements API passing calls to user-provided function values.
|
type CommonStruct struct {
|
||||||
type Struct struct {
|
|
||||||
Internal struct{
|
Internal struct{
|
||||||
AuthVerify func(ctx context.Context, token string) ([]string, error) `perm:"read"`
|
AuthVerify func(ctx context.Context, token string) ([]string, error) `perm:"read"`
|
||||||
AuthNew func(ctx context.Context, perms []string) ([]byte, error) `perm:"admin"`
|
AuthNew func(ctx context.Context, perms []string) ([]byte, error) `perm:"admin"`
|
||||||
|
|
||||||
|
NetPeers func(context.Context) ([]peer.AddrInfo, error) `perm:"read"`
|
||||||
|
NetConnect func(context.Context, peer.AddrInfo) error `perm:"write"`
|
||||||
|
NetAddrsListen func(context.Context) (peer.AddrInfo, error) `perm:"read"`
|
||||||
|
|
||||||
ID func(context.Context) (peer.ID, error) `perm:"read"`
|
ID func(context.Context) (peer.ID, error) `perm:"read"`
|
||||||
Version func(context.Context) (Version, error) `perm:"read"`
|
Version func(context.Context) (Version, error) `perm:"read"`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *CommonStruct) AuthVerify(ctx context.Context, token string) ([]string, error) {
|
||||||
|
return c.Internal.AuthVerify(ctx, token)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *CommonStruct) AuthNew(ctx context.Context, perms []string) ([]byte, error) {
|
||||||
|
return c.Internal.AuthNew(ctx, perms)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *CommonStruct) NetPeers(ctx context.Context) ([]peer.AddrInfo, error) {
|
||||||
|
return c.Internal.NetPeers(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *CommonStruct) NetConnect(ctx context.Context, p peer.AddrInfo) error {
|
||||||
|
return c.Internal.NetConnect(ctx, p)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *CommonStruct) NetAddrsListen(ctx context.Context) (peer.AddrInfo, error) {
|
||||||
|
return c.Internal.NetAddrsListen(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ID implements API.ID
|
||||||
|
func (c *CommonStruct) ID(ctx context.Context) (peer.ID, error) {
|
||||||
|
return c.Internal.ID(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Version implements API.Version
|
||||||
|
func (c *CommonStruct) Version(ctx context.Context) (Version, error) {
|
||||||
|
return c.Internal.Version(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FullNodeStruct implements API passing calls to user-provided function values.
|
||||||
|
type FullNodeStruct struct {
|
||||||
|
CommonStruct
|
||||||
|
|
||||||
|
Internal struct {
|
||||||
ChainSubmitBlock func(ctx context.Context, blk *chain.BlockMsg) error `perm:"write"`
|
ChainSubmitBlock func(ctx context.Context, blk *chain.BlockMsg) error `perm:"write"`
|
||||||
ChainHead func(context.Context) (*chain.TipSet, error) `perm:"read"`
|
ChainHead func(context.Context) (*chain.TipSet, error) `perm:"read"`
|
||||||
ChainGetRandomness func(context.Context, *chain.TipSet) ([]byte, error) `perm:"read"`
|
ChainGetRandomness func(context.Context, *chain.TipSet) ([]byte, error) `perm:"read"`
|
||||||
@ -45,113 +85,89 @@ type Struct struct {
|
|||||||
|
|
||||||
ClientImport func(ctx context.Context, path string) (cid.Cid, error) `perm:"write"`
|
ClientImport func(ctx context.Context, path string) (cid.Cid, error) `perm:"write"`
|
||||||
ClientListImports func(ctx context.Context) ([]Import, error) `perm:"read"`
|
ClientListImports func(ctx context.Context) ([]Import, error) `perm:"read"`
|
||||||
|
|
||||||
NetPeers func(context.Context) ([]peer.AddrInfo, error) `perm:"read"`
|
|
||||||
NetConnect func(context.Context, peer.AddrInfo) error `perm:"write"`
|
|
||||||
NetAddrsListen func(context.Context) (peer.AddrInfo, error) `perm:"read"`
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Struct) AuthVerify(ctx context.Context, token string) ([]string, error) {
|
type StorageMinerStruct struct {
|
||||||
return c.Internal.AuthVerify(ctx, token)
|
CommonStruct
|
||||||
|
|
||||||
|
Internal struct{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Struct) AuthNew(ctx context.Context, perms []string) ([]byte, error) {
|
func (c *FullNodeStruct) ClientListImports(ctx context.Context) ([]Import, error) {
|
||||||
return c.Internal.AuthNew(ctx, perms)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Struct) ClientListImports(ctx context.Context) ([]Import, error) {
|
|
||||||
return c.Internal.ClientListImports(ctx)
|
return c.Internal.ClientListImports(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Struct) ClientImport(ctx context.Context, path string) (cid.Cid, error) {
|
func (c *FullNodeStruct) ClientImport(ctx context.Context, path string) (cid.Cid, error) {
|
||||||
return c.Internal.ClientImport(ctx, path)
|
return c.Internal.ClientImport(ctx, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Struct) MpoolPending(ctx context.Context, ts *chain.TipSet) ([]*chain.SignedMessage, error) {
|
func (c *FullNodeStruct) MpoolPending(ctx context.Context, ts *chain.TipSet) ([]*chain.SignedMessage, error) {
|
||||||
return c.Internal.MpoolPending(ctx, ts)
|
return c.Internal.MpoolPending(ctx, ts)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Struct) MpoolPush(ctx context.Context, smsg *chain.SignedMessage) error {
|
func (c *FullNodeStruct) MpoolPush(ctx context.Context, smsg *chain.SignedMessage) error {
|
||||||
return c.Internal.MpoolPush(ctx, smsg)
|
return c.Internal.MpoolPush(ctx, smsg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Struct) MinerStart(ctx context.Context, addr address.Address) error {
|
func (c *FullNodeStruct) MinerStart(ctx context.Context, addr address.Address) error {
|
||||||
return c.Internal.MinerStart(ctx, addr)
|
return c.Internal.MinerStart(ctx, addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Struct) MinerCreateBlock(ctx context.Context, addr address.Address, base *chain.TipSet, tickets []chain.Ticket, eproof chain.ElectionProof, msgs []*chain.SignedMessage) (*chain.BlockMsg, error) {
|
func (c *FullNodeStruct) MinerCreateBlock(ctx context.Context, addr address.Address, base *chain.TipSet, tickets []chain.Ticket, eproof chain.ElectionProof, msgs []*chain.SignedMessage) (*chain.BlockMsg, error) {
|
||||||
return c.Internal.MinerCreateBlock(ctx, addr, base, tickets, eproof, msgs)
|
return c.Internal.MinerCreateBlock(ctx, addr, base, tickets, eproof, msgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Struct) NetPeers(ctx context.Context) ([]peer.AddrInfo, error) {
|
func (c *FullNodeStruct) ChainSubmitBlock(ctx context.Context, blk *chain.BlockMsg) error {
|
||||||
return c.Internal.NetPeers(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Struct) NetConnect(ctx context.Context, p peer.AddrInfo) error {
|
|
||||||
return c.Internal.NetConnect(ctx, p)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Struct) NetAddrsListen(ctx context.Context) (peer.AddrInfo, error) {
|
|
||||||
return c.Internal.NetAddrsListen(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Struct) ChainSubmitBlock(ctx context.Context, blk *chain.BlockMsg) error {
|
|
||||||
return c.Internal.ChainSubmitBlock(ctx, blk)
|
return c.Internal.ChainSubmitBlock(ctx, blk)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Struct) ChainHead(ctx context.Context) (*chain.TipSet, error) {
|
func (c *FullNodeStruct) ChainHead(ctx context.Context) (*chain.TipSet, error) {
|
||||||
return c.Internal.ChainHead(ctx)
|
return c.Internal.ChainHead(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Struct) ChainGetRandomness(ctx context.Context, pts *chain.TipSet) ([]byte, error) {
|
func (c *FullNodeStruct) ChainGetRandomness(ctx context.Context, pts *chain.TipSet) ([]byte, error) {
|
||||||
return c.Internal.ChainGetRandomness(ctx, pts)
|
return c.Internal.ChainGetRandomness(ctx, pts)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Struct) ChainWaitMsg(ctx context.Context, msgc cid.Cid) (*MsgWait, error) {
|
func (c *FullNodeStruct) ChainWaitMsg(ctx context.Context, msgc cid.Cid) (*MsgWait, error) {
|
||||||
return c.Internal.ChainWaitMsg(ctx, msgc)
|
return c.Internal.ChainWaitMsg(ctx, msgc)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ID implements API.ID
|
func (c *FullNodeStruct) WalletNew(ctx context.Context, typ string) (address.Address, error) {
|
||||||
func (c *Struct) ID(ctx context.Context) (peer.ID, error) {
|
|
||||||
return c.Internal.ID(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Version implements API.Version
|
|
||||||
func (c *Struct) Version(ctx context.Context) (Version, error) {
|
|
||||||
return c.Internal.Version(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Struct) WalletNew(ctx context.Context, typ string) (address.Address, error) {
|
|
||||||
return c.Internal.WalletNew(ctx, typ)
|
return c.Internal.WalletNew(ctx, typ)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Struct) WalletList(ctx context.Context) ([]address.Address, error) {
|
func (c *FullNodeStruct) WalletList(ctx context.Context) ([]address.Address, error) {
|
||||||
return c.Internal.WalletList(ctx)
|
return c.Internal.WalletList(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Struct) WalletBalance(ctx context.Context, a address.Address) (types.BigInt, error) {
|
func (c *FullNodeStruct) WalletBalance(ctx context.Context, a address.Address) (types.BigInt, error) {
|
||||||
return c.Internal.WalletBalance(ctx, a)
|
return c.Internal.WalletBalance(ctx, a)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Struct) WalletSign(ctx context.Context, k address.Address, msg []byte) (*chain.Signature, error) {
|
func (c *FullNodeStruct) WalletSign(ctx context.Context, k address.Address, msg []byte) (*chain.Signature, error) {
|
||||||
return c.Internal.WalletSign(ctx, k, msg)
|
return c.Internal.WalletSign(ctx, k, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Struct) WalletDefaultAddress(ctx context.Context) (address.Address, error) {
|
func (c *FullNodeStruct) WalletDefaultAddress(ctx context.Context) (address.Address, error) {
|
||||||
return c.Internal.WalletDefaultAddress(ctx)
|
return c.Internal.WalletDefaultAddress(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Struct) MpoolGetNonce(ctx context.Context, addr address.Address) (uint64, error) {
|
func (c *FullNodeStruct) MpoolGetNonce(ctx context.Context, addr address.Address) (uint64, error) {
|
||||||
return c.Internal.MpoolGetNonce(ctx, addr)
|
return c.Internal.MpoolGetNonce(ctx, addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Struct) ChainGetBlock(ctx context.Context, b cid.Cid) (*chain.BlockHeader, error) {
|
func (c *FullNodeStruct) ChainGetBlock(ctx context.Context, b cid.Cid) (*chain.BlockHeader, error) {
|
||||||
return c.Internal.ChainGetBlock(ctx, b)
|
return c.Internal.ChainGetBlock(ctx, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Struct) ChainGetBlockMessages(ctx context.Context, b cid.Cid) ([]*chain.SignedMessage, error) {
|
func (c *FullNodeStruct) ChainGetBlockMessages(ctx context.Context, b cid.Cid) ([]*chain.SignedMessage, error) {
|
||||||
return c.Internal.ChainGetBlockMessages(ctx, b)
|
return c.Internal.ChainGetBlockMessages(ctx, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ API = &Struct{}
|
var _ Common = &CommonStruct{}
|
||||||
|
var _ FullNode = &FullNodeStruct{}
|
||||||
|
var _ StorageMiner = &StorageMinerStruct{}
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
|
|
||||||
// APIBuilder is a function which is invoked in test suite to provide
|
// APIBuilder is a function which is invoked in test suite to provide
|
||||||
// test nodes and networks
|
// test nodes and networks
|
||||||
type APIBuilder func(t *testing.T, n int) []api.API
|
type APIBuilder func(t *testing.T, n int) []api.FullNode
|
||||||
type testSuite struct {
|
type testSuite struct {
|
||||||
makeNodes APIBuilder
|
makeNodes APIBuilder
|
||||||
}
|
}
|
||||||
|
@ -23,9 +23,9 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// ApiConnector returns API instance
|
// ApiConnector returns API instance
|
||||||
type ApiConnector func() api.API
|
type ApiConnector func() api.FullNode
|
||||||
|
|
||||||
func GetAPI(ctx *cli.Context) (api.API, error) {
|
func GetAPI(ctx *cli.Context) (api.FullNode, error) {
|
||||||
r, err := repo.NewFS(ctx.String("repo"))
|
r, err := repo.NewFS(ctx.String("repo"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -34,7 +34,7 @@ var DaemonCmd = &cli.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var api api.API
|
var api api.FullNode
|
||||||
err = node.New(ctx,
|
err = node.New(ctx,
|
||||||
node.FullAPI(&api),
|
node.FullAPI(&api),
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"github.com/filecoin-project/go-lotus/lib/jsonrpc"
|
"github.com/filecoin-project/go-lotus/lib/jsonrpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
func serveRPC(api api.API, addr string) error {
|
func serveRPC(api api.FullNode, addr string) error {
|
||||||
rpcServer := jsonrpc.NewServer()
|
rpcServer := jsonrpc.NewServer()
|
||||||
rpcServer.Register("Filecoin", api)
|
rpcServer.Register("Filecoin", api)
|
||||||
http.Handle("/rpc/v0", rpcServer)
|
http.Handle("/rpc/v0", rpcServer)
|
||||||
|
@ -202,4 +202,4 @@ func (a *API) NetAddrsListen(context.Context) (peer.AddrInfo, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ api.API = &API{}
|
var _ api.FullNode = &API{}
|
||||||
|
@ -268,7 +268,7 @@ func Repo(r repo.Repo) Option {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func FullAPI(out *api.API) Option {
|
func FullAPI(out *api.FullNode) Option {
|
||||||
return func(s *Settings) error {
|
return func(s *Settings) error {
|
||||||
resAPI := &API{}
|
resAPI := &API{}
|
||||||
s.invokes[ExtractApiKey] = fx.Extract(resAPI)
|
s.invokes[ExtractApiKey] = fx.Extract(resAPI)
|
||||||
|
@ -16,11 +16,11 @@ import (
|
|||||||
mocknet "github.com/libp2p/go-libp2p/p2p/net/mock"
|
mocknet "github.com/libp2p/go-libp2p/p2p/net/mock"
|
||||||
)
|
)
|
||||||
|
|
||||||
func builder(t *testing.T, n int) []api.API {
|
func builder(t *testing.T, n int) []api.FullNode {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
mn := mocknet.New(ctx)
|
mn := mocknet.New(ctx)
|
||||||
|
|
||||||
out := make([]api.API, n)
|
out := make([]api.FullNode, n)
|
||||||
|
|
||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
var err error
|
var err error
|
||||||
@ -48,9 +48,9 @@ func TestAPI(t *testing.T) {
|
|||||||
|
|
||||||
var nextApi int
|
var nextApi int
|
||||||
|
|
||||||
func rpcBuilder(t *testing.T, n int) []api.API {
|
func rpcBuilder(t *testing.T, n int) []api.FullNode {
|
||||||
nodeApis := builder(t, n)
|
nodeApis := builder(t, n)
|
||||||
out := make([]api.API, n)
|
out := make([]api.FullNode, n)
|
||||||
|
|
||||||
for i, a := range nodeApis {
|
for i, a := range nodeApis {
|
||||||
rpcServer := jsonrpc.NewServer()
|
rpcServer := jsonrpc.NewServer()
|
||||||
|
Loading…
Reference in New Issue
Block a user