Skip to content
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- 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): implement FRC-0102 signing envelope for wallet sign/verify ([filecoin-project/lotus#13471](https://github.com/filecoin-project/lotus/pull/13471))
- 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
41 changes: 39 additions & 2 deletions 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,14 @@ var StateListMessagesCmd = &cli.Command{

windowSize := abi.ChainEpoch(100)

obn := cctx.Bool("order-by-nonce") && !froma.Empty()

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

cur := ts
for cur.Height() > toh {
if ctx.Err() != nil {
Expand All @@ -889,7 +901,7 @@ var StateListMessagesCmd = &cli.Command{
}

for _, c := range msgs {
if cctx.Bool("cids") {
if cctx.Bool("cids") && !obn {
fmt.Println(c.String())
continue
}
Expand All @@ -898,11 +910,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
Cid cid.Cid
}{Nonce: m.Nonce, Msg: b, Cid: c})
} else {
fmt.Println(string(b))
}
Comment thread
DarkLord017 marked this conversation as resolved.
}

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

if obn {
sort.Slice(orderedMessages, func(i, j int) bool {
return orderedMessages[i].Nonce < orderedMessages[j].Nonce
})
if cctx.Bool("cids") {
for _, om := range orderedMessages {
fmt.Println(om.Cid.String())
}
} else {
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.

Loading