add mpool pending command
This commit is contained in:
parent
999b7d568c
commit
e09a379c3b
@ -30,6 +30,7 @@ type API interface {
|
|||||||
// // status
|
// // status
|
||||||
// // mpool
|
// // mpool
|
||||||
// // // ls / show / rm
|
// // // ls / show / rm
|
||||||
|
MpoolPending(context.Context) ([]*chain.SignedMessage, error)
|
||||||
|
|
||||||
// dag
|
// dag
|
||||||
|
|
||||||
|
@ -4,8 +4,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-lotus/chain"
|
"github.com/filecoin-project/go-lotus/chain"
|
||||||
|
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
|
|
||||||
"github.com/libp2p/go-libp2p-core/peer"
|
"github.com/libp2p/go-libp2p-core/peer"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -18,12 +18,18 @@ type Struct struct {
|
|||||||
ChainSubmitBlock func(ctx context.Context, blk *chain.BlockMsg) error
|
ChainSubmitBlock func(ctx context.Context, blk *chain.BlockMsg) error
|
||||||
ChainHead func(context.Context) ([]cid.Cid, error)
|
ChainHead func(context.Context) ([]cid.Cid, error)
|
||||||
|
|
||||||
|
MpoolPending func(ctx context.Context) ([]*chain.SignedMessage, error)
|
||||||
|
|
||||||
NetPeers func(context.Context) ([]peer.AddrInfo, error)
|
NetPeers func(context.Context) ([]peer.AddrInfo, error)
|
||||||
NetConnect func(context.Context, peer.AddrInfo) error
|
NetConnect func(context.Context, peer.AddrInfo) error
|
||||||
NetAddrsListen 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) {
|
func (c *Struct) NetPeers(ctx context.Context) ([]peer.AddrInfo, error) {
|
||||||
return c.Internal.NetPeers(ctx)
|
return c.Internal.NetPeers(ctx)
|
||||||
}
|
}
|
||||||
|
@ -46,4 +46,5 @@ var Commands = []*cli.Command{
|
|||||||
chainCmd,
|
chainCmd,
|
||||||
netCmd,
|
netCmd,
|
||||||
versionCmd,
|
versionCmd,
|
||||||
|
mpoolCmd,
|
||||||
}
|
}
|
||||||
|
35
cli/mpool.go
Normal file
35
cli/mpool.go
Normal 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
|
||||||
|
},
|
||||||
|
}
|
@ -18,6 +18,7 @@ type API struct {
|
|||||||
Host host.Host
|
Host host.Host
|
||||||
Chain *chain.ChainStore
|
Chain *chain.ChainStore
|
||||||
PubSub *pubsub.PubSub
|
PubSub *pubsub.PubSub
|
||||||
|
Mpool *chain.MessagePool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *API) ChainSubmitBlock(ctx context.Context, blk *chain.BlockMsg) error {
|
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
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *API) MpoolPending(context.Context) ([]*chain.SignedMessage, error) {
|
||||||
|
return a.Mpool.Pending(), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (a *API) NetPeers(context.Context) ([]peer.AddrInfo, error) {
|
func (a *API) NetPeers(context.Context) ([]peer.AddrInfo, error) {
|
||||||
conns := a.Host.Network().Conns()
|
conns := a.Host.Network().Conns()
|
||||||
out := make([]peer.AddrInfo, len(conns))
|
out := make([]peer.AddrInfo, len(conns))
|
||||||
|
@ -57,7 +57,7 @@ const (
|
|||||||
StartListeningKey
|
StartListeningKey
|
||||||
|
|
||||||
// filecoin
|
// filecoin
|
||||||
SetGenisisKey
|
SetGenesisKey
|
||||||
|
|
||||||
RunHelloKey
|
RunHelloKey
|
||||||
RunBlockSyncKey
|
RunBlockSyncKey
|
||||||
@ -171,7 +171,7 @@ func Online() Option {
|
|||||||
Override(new(*chain.MessagePool), chain.NewMessagePool),
|
Override(new(*chain.MessagePool), chain.NewMessagePool),
|
||||||
|
|
||||||
Override(new(modules.Genesis), testing.MakeGenesis),
|
Override(new(modules.Genesis), testing.MakeGenesis),
|
||||||
Override(SetGenisisKey, modules.SetGenesis),
|
Override(SetGenesisKey, modules.SetGenesis),
|
||||||
|
|
||||||
Override(new(*hello.Service), hello.NewHelloService),
|
Override(new(*hello.Service), hello.NewHelloService),
|
||||||
Override(new(*chain.BlockSyncService), chain.NewBlockSyncService),
|
Override(new(*chain.BlockSyncService), chain.NewBlockSyncService),
|
||||||
|
Loading…
Reference in New Issue
Block a user