Skip to content

Commit

Permalink
cmd: Modified listchaintxns command.
Browse files Browse the repository at this point in the history
- Added reverse flag to listchaintxns command.
- Listchaintxns command returns error when start_height is
less than end_height if end_height is not -1.
  • Loading branch information
kornpow committed Feb 26, 2025
1 parent e3d9fcb commit 400f736
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions cmd/commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -2248,7 +2248,7 @@ var listChainTxnsCommand = cli.Command{
to an address our wallet controls, or spent utxos that we held. The
start_height and end_height flags can be used to specify an inclusive
block range over which to query for transactions. If the end_height is
less than the start_height, transactions will be queried in reverse.
less than the start_height, an error will be returned.
To get all transactions until the chain tip, including unconfirmed
transactions (identifiable with BlockHeight=0), set end_height to -1.
By default, this call will get all transactions our wallet was involved
Expand All @@ -2267,10 +2267,24 @@ func listChainTxns(ctx *cli.Context) error {
MaxTransactions: uint32(ctx.Uint64("max_transactions")),
}

if ctx.IsSet("start_height") {
switch {
case ctx.IsSet("start_height") && ctx.IsSet("end_height"):
startHeight := ctx.Int64("start_height")
endHeight := ctx.Int64("end_height")

if endHeight != -1 && startHeight > endHeight {
return errors.New("start_height should " +
"be less than end_height if end_height" +
" is not equal to -1")
}

req.StartHeight = int32(startHeight)
req.EndHeight = int32(endHeight)

case ctx.IsSet("start_height"):
req.StartHeight = int32(ctx.Int64("start_height"))
}
if ctx.IsSet("end_height") {

case ctx.IsSet("end_height"):
req.EndHeight = int32(ctx.Int64("end_height"))
}

Expand Down

0 comments on commit 400f736

Please sign in to comment.