From e09a379c3b9d2cb808b84892ef318bc99a2d31d1 Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Tue, 9 Jul 2019 15:58:51 -0700 Subject: [PATCH] add mpool pending command --- api/api.go | 1 + api/struct.go | 8 +++++++- cli/cmd.go | 1 + cli/mpool.go | 35 +++++++++++++++++++++++++++++++++++ node/api.go | 5 +++++ node/builder.go | 4 ++-- 6 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 cli/mpool.go diff --git a/api/api.go b/api/api.go index 159769bf6..7882e34ce 100644 --- a/api/api.go +++ b/api/api.go @@ -30,6 +30,7 @@ type API interface { // // status // // mpool // // // ls / show / rm + MpoolPending(context.Context) ([]*chain.SignedMessage, error) // dag diff --git a/api/struct.go b/api/struct.go index 89c57c5af..628e919c7 100644 --- a/api/struct.go +++ b/api/struct.go @@ -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) } diff --git a/cli/cmd.go b/cli/cmd.go index e76669a4f..111cd7a35 100644 --- a/cli/cmd.go +++ b/cli/cmd.go @@ -46,4 +46,5 @@ var Commands = []*cli.Command{ chainCmd, netCmd, versionCmd, + mpoolCmd, } diff --git a/cli/mpool.go b/cli/mpool.go new file mode 100644 index 000000000..6c344420a --- /dev/null +++ b/cli/mpool.go @@ -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 + }, +} diff --git a/node/api.go b/node/api.go index 1efdfd3af..c1b296c9f 100644 --- a/node/api.go +++ b/node/api.go @@ -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)) diff --git a/node/builder.go b/node/builder.go index ec3bfb313..533919232 100644 --- a/node/builder.go +++ b/node/builder.go @@ -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),