From 255ff1beb3107184017d1b59b478a9bf514fc8e0 Mon Sep 17 00:00:00 2001 From: Sam Korn Date: Sat, 9 Sep 2023 17:40:13 +0100 Subject: [PATCH] cmd: Modified listchaintxns command. - Added reverse flag to listchaintxns command. - Listchaintxns command returns error when start_height is less than end_height if end_height is not -1. --- cmd/commands/commands.go | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/cmd/commands/commands.go b/cmd/commands/commands.go index f41925392..ce4253bdc 100644 --- a/cmd/commands/commands.go +++ b/cmd/commands/commands.go @@ -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 @@ -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")) }