Skip to content
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
## 👌 Improvements
- docs: fix outdated link in documentation ([#13436](https://github.com/filecoin-project/lotus/pull/13436))
- docs: fix dead link in documentation ([#13437](https://github.com/filecoin-project/lotus/pull/13437))
- feat(cli): add --order-by-nonce flag to list messages sequentially when filtering by sender ([filecoin-project/lotus#13394](https://github.com/filecoin-project/lotus/pull/13394))

# Node v1.34.3 / 2025-12-03

Expand Down
31 changes: 30 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 thread
rvagg marked this conversation as resolved.

cur := ts
for cur.Height() > toh {
if ctx.Err() != nil {
Expand All @@ -898,11 +909,20 @@ 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})
} else {
fmt.Println(string(b))
}
Comment thread
DarkLord017 marked this conversation as resolved.
}

if end <= 0 {
Expand All @@ -917,6 +937,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
1 change: 1 addition & 0 deletions documentation/en/cli-lotus.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.