Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()

var orderedMessages []struct {
Nonce uint64
Msg []byte
}
Comment on lines +881 to +884
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The inline anonymous struct makes the code harder to maintain. Consider defining a named type like type OrderedMessage struct { Nonce uint64; Msg []byte } at the package level or before the command definition.

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should i do this @rvagg @wjmelements


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
} else {
fmt.Println(string(b))
}
}

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