mpool cli: --local flag
This commit is contained in:
parent
014092443f
commit
cb5e5a1325
52
cli/mpool.go
52
cli/mpool.go
@ -26,6 +26,12 @@ var mpoolCmd = &cli.Command{
|
|||||||
var mpoolPending = &cli.Command{
|
var mpoolPending = &cli.Command{
|
||||||
Name: "pending",
|
Name: "pending",
|
||||||
Usage: "Get pending messages",
|
Usage: "Get pending messages",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "local",
|
||||||
|
Usage: "print pending messages for addresses in local wallet only",
|
||||||
|
},
|
||||||
|
},
|
||||||
Action: func(cctx *cli.Context) error {
|
Action: func(cctx *cli.Context) error {
|
||||||
api, closer, err := GetFullNodeAPI(cctx)
|
api, closer, err := GetFullNodeAPI(cctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -35,12 +41,32 @@ var mpoolPending = &cli.Command{
|
|||||||
|
|
||||||
ctx := ReqContext(cctx)
|
ctx := ReqContext(cctx)
|
||||||
|
|
||||||
|
var filter map[address.Address]struct{}
|
||||||
|
if cctx.Bool("local") {
|
||||||
|
filter = map[address.Address]struct{}{}
|
||||||
|
|
||||||
|
addrss, err := api.WalletList(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return xerrors.Errorf("getting local addresses: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, a := range addrss {
|
||||||
|
filter[a] = struct{}{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
msgs, err := api.MpoolPending(ctx, types.EmptyTSK)
|
msgs, err := api.MpoolPending(ctx, types.EmptyTSK)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, msg := range msgs {
|
for _, msg := range msgs {
|
||||||
|
if filter != nil{
|
||||||
|
if _, has := filter[msg.Message.From]; !has {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
out, err := json.MarshalIndent(msg, "", " ")
|
out, err := json.MarshalIndent(msg, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -95,6 +121,12 @@ type mpStat struct {
|
|||||||
var mpoolStat = &cli.Command{
|
var mpoolStat = &cli.Command{
|
||||||
Name: "stat",
|
Name: "stat",
|
||||||
Usage: "print mempool stats",
|
Usage: "print mempool stats",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "local",
|
||||||
|
Usage: "print stats for addresses in local wallet only",
|
||||||
|
},
|
||||||
|
},
|
||||||
Action: func(cctx *cli.Context) error {
|
Action: func(cctx *cli.Context) error {
|
||||||
api, closer, err := GetFullNodeAPI(cctx)
|
api, closer, err := GetFullNodeAPI(cctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -109,6 +141,20 @@ var mpoolStat = &cli.Command{
|
|||||||
return xerrors.Errorf("getting chain head: %w", err)
|
return xerrors.Errorf("getting chain head: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var filter map[address.Address]struct{}
|
||||||
|
if cctx.Bool("local") {
|
||||||
|
filter = map[address.Address]struct{}{}
|
||||||
|
|
||||||
|
addrss, err := api.WalletList(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return xerrors.Errorf("getting local addresses: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, a := range addrss {
|
||||||
|
filter[a] = struct{}{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
msgs, err := api.MpoolPending(ctx, types.EmptyTSK)
|
msgs, err := api.MpoolPending(ctx, types.EmptyTSK)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -117,6 +163,12 @@ var mpoolStat = &cli.Command{
|
|||||||
buckets := map[address.Address]*statBucket{}
|
buckets := map[address.Address]*statBucket{}
|
||||||
|
|
||||||
for _, v := range msgs {
|
for _, v := range msgs {
|
||||||
|
if filter != nil{
|
||||||
|
if _, has := filter[v.Message.From]; !has {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bkt, ok := buckets[v.Message.From]
|
bkt, ok := buckets[v.Message.From]
|
||||||
if !ok {
|
if !ok {
|
||||||
bkt = &statBucket{
|
bkt = &statBucket{
|
||||||
|
Loading…
Reference in New Issue
Block a user