add mpool pending command

This commit is contained in:
whyrusleeping 2019-07-09 15:58:51 -07:00
parent 999b7d568c
commit e09a379c3b
6 changed files with 51 additions and 3 deletions

View File

@ -30,6 +30,7 @@ type API interface {
// // status
// // mpool
// // // ls / show / rm
MpoolPending(context.Context) ([]*chain.SignedMessage, error)
// dag

View File

@ -4,8 +4,8 @@ import (
"context"
"github.com/filecoin-project/go-lotus/chain"
"github.com/ipfs/go-cid"
"github.com/libp2p/go-libp2p-core/peer"
)
@ -18,12 +18,18 @@ type Struct struct {
ChainSubmitBlock func(ctx context.Context, blk *chain.BlockMsg) error
ChainHead func(context.Context) ([]cid.Cid, error)
MpoolPending func(ctx context.Context) ([]*chain.SignedMessage, error)
NetPeers func(context.Context) ([]peer.AddrInfo, error)
NetConnect func(context.Context, peer.AddrInfo) error
NetAddrsListen func(context.Context) (peer.AddrInfo, error)
}
}
func (c *Struct) MpoolPending(ctx context.Context) ([]*chain.SignedMessage, error) {
return c.Internal.MpoolPending(ctx)
}
func (c *Struct) NetPeers(ctx context.Context) ([]peer.AddrInfo, error) {
return c.Internal.NetPeers(ctx)
}

View File

@ -46,4 +46,5 @@ var Commands = []*cli.Command{
chainCmd,
netCmd,
versionCmd,
mpoolCmd,
}

35
cli/mpool.go Normal file
View File

@ -0,0 +1,35 @@
package cli
import (
"fmt"
"gopkg.in/urfave/cli.v2"
)
var mpoolCmd = &cli.Command{
Name: "mpool",
Usage: "Manage message pool",
Subcommands: []*cli.Command{
mpoolPending,
},
}
var mpoolPending = &cli.Command{
Name: "pending",
Usage: "Get pending messages",
Action: func(cctx *cli.Context) error {
api := getApi(cctx)
ctx := reqContext(cctx)
msgs, err := api.MpoolPending(ctx)
if err != nil {
return err
}
for _, msg := range msgs {
fmt.Println(msg)
}
return nil
},
}

View File

@ -18,6 +18,7 @@ type API struct {
Host host.Host
Chain *chain.ChainStore
PubSub *pubsub.PubSub
Mpool *chain.MessagePool
}
func (a *API) ChainSubmitBlock(ctx context.Context, blk *chain.BlockMsg) error {
@ -44,6 +45,10 @@ func (a *API) Version(context.Context) (api.Version, error) {
}, nil
}
func (a *API) MpoolPending(context.Context) ([]*chain.SignedMessage, error) {
return a.Mpool.Pending(), nil
}
func (a *API) NetPeers(context.Context) ([]peer.AddrInfo, error) {
conns := a.Host.Network().Conns()
out := make([]peer.AddrInfo, len(conns))

View File

@ -57,7 +57,7 @@ const (
StartListeningKey
// filecoin
SetGenisisKey
SetGenesisKey
RunHelloKey
RunBlockSyncKey
@ -171,7 +171,7 @@ func Online() Option {
Override(new(*chain.MessagePool), chain.NewMessagePool),
Override(new(modules.Genesis), testing.MakeGenesis),
Override(SetGenisisKey, modules.SetGenesis),
Override(SetGenesisKey, modules.SetGenesis),
Override(new(*hello.Service), hello.NewHelloService),
Override(new(*chain.BlockSyncService), chain.NewBlockSyncService),