Skip to content
32 changes: 31 additions & 1 deletion cli/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,10 @@ var StateListMessagesCmd = &cli.Command{
Name: "cids",
Usage: "print message CIDs instead of messages",
},
&cli.BoolFlag{
Name: "order-by-nonce",
Usage: "order messages by nonce (only applies when filtering by 'from' address)",
},
},
Action: func(cctx *cli.Context) error {
api, closer, err := GetFullNodeAPI(cctx)
Expand Down Expand Up @@ -872,6 +876,13 @@ var StateListMessagesCmd = &cli.Command{

windowSize := abi.ChainEpoch(100)

obn := cctx.Bool("order-by-nonce") && !froma.Empty()
Comment thread
DarkLord017 marked this conversation as resolved.
Outdated

var orderedMessages []struct {
Nonce uint64
Msg []byte
}
Comment thread
rvagg marked this conversation as resolved.

cur := ts
for cur.Height() > toh {
if ctx.Err() != nil {
Expand All @@ -898,11 +909,21 @@ var StateListMessagesCmd = &cli.Command{
if err != nil {
return err
}

b, err := json.MarshalIndent(m, "", " ")
if err != nil {
return err
}
fmt.Println(string(b))

if obn {
orderedMessages = append(orderedMessages, struct {
Nonce uint64
Msg []byte
}{Nonce: m.Nonce, Msg: b})
continue
Comment thread
rvagg marked this conversation as resolved.
Outdated
} else {
fmt.Println(string(b))
}
Comment thread
DarkLord017 marked this conversation as resolved.
}

if end <= 0 {
Expand All @@ -917,6 +938,15 @@ var StateListMessagesCmd = &cli.Command{
cur = next
}

if obn {
sort.Slice(orderedMessages, func(i, j int) bool {
return orderedMessages[i].Nonce < orderedMessages[j].Nonce
})
for _, om := range orderedMessages {
fmt.Println(string(om.Msg))
}
}

return nil
},
}
Expand Down