2019-06-29 09:19:06 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2019-07-09 15:19:27 +00:00
|
|
|
"github.com/filecoin-project/go-lotus/chain"
|
|
|
|
|
|
|
|
"github.com/ipfs/go-cid"
|
2019-06-29 09:19:06 +00:00
|
|
|
"github.com/libp2p/go-libp2p-core/peer"
|
|
|
|
)
|
|
|
|
|
2019-07-02 13:05:43 +00:00
|
|
|
// Struct implements API passing calls to user-provided function values.
|
2019-06-29 09:19:06 +00:00
|
|
|
type Struct struct {
|
2019-07-01 20:00:22 +00:00
|
|
|
Internal struct {
|
|
|
|
ID func(context.Context) (peer.ID, error)
|
2019-06-29 09:19:06 +00:00
|
|
|
Version func(context.Context) (Version, error)
|
2019-07-08 19:07:16 +00:00
|
|
|
|
2019-07-09 15:19:27 +00:00
|
|
|
ChainSubmitBlock func(ctx context.Context, blk *chain.BlockMsg) error
|
|
|
|
ChainHead func(context.Context) ([]cid.Cid, error)
|
|
|
|
|
2019-07-08 21:01:15 +00:00
|
|
|
NetPeers func(context.Context) ([]peer.AddrInfo, error)
|
|
|
|
NetConnect func(context.Context, peer.AddrInfo) error
|
2019-07-09 13:35:32 +00:00
|
|
|
NetAddrsListen func(context.Context) (MultiaddrSlice, error)
|
2019-06-29 09:19:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-08 19:07:16 +00:00
|
|
|
func (c *Struct) NetPeers(ctx context.Context) ([]peer.AddrInfo, error) {
|
|
|
|
return c.Internal.NetPeers(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Struct) NetConnect(ctx context.Context, p peer.AddrInfo) error {
|
|
|
|
return c.Internal.NetConnect(ctx, p)
|
|
|
|
}
|
|
|
|
|
2019-07-09 13:35:32 +00:00
|
|
|
func (c *Struct) NetAddrsListen(ctx context.Context) (MultiaddrSlice, error) {
|
2019-07-08 21:01:15 +00:00
|
|
|
return c.Internal.NetAddrsListen(ctx)
|
|
|
|
}
|
|
|
|
|
2019-07-09 15:19:27 +00:00
|
|
|
func (c *Struct) ChainSubmitBlock(ctx context.Context, blk *chain.BlockMsg) error {
|
|
|
|
return c.Internal.ChainSubmitBlock(ctx, blk)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Struct) ChainHead(ctx context.Context) ([]cid.Cid, error) {
|
|
|
|
return c.Internal.ChainHead(ctx)
|
|
|
|
}
|
|
|
|
|
2019-07-02 13:05:43 +00:00
|
|
|
// ID implements API.ID
|
2019-06-29 09:19:06 +00:00
|
|
|
func (c *Struct) ID(ctx context.Context) (peer.ID, error) {
|
|
|
|
return c.Internal.ID(ctx)
|
|
|
|
}
|
|
|
|
|
2019-07-02 13:05:43 +00:00
|
|
|
// Version implements API.Version
|
2019-06-29 09:19:06 +00:00
|
|
|
func (c *Struct) Version(ctx context.Context) (Version, error) {
|
|
|
|
return c.Internal.Version(ctx)
|
|
|
|
}
|
|
|
|
|
2019-07-01 20:00:22 +00:00
|
|
|
var _ API = &Struct{}
|