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.
This commit is contained in:
Sam Korn 2023-09-09 17:40:13 +01:00
parent e3d9fcb5ac
commit 255ff1beb3
No known key found for this signature in database
GPG key ID: C54D890495E29E91

View file

@ -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"))
}