From cd1fddb524916192d20a2f9903ea356d38f45d7b Mon Sep 17 00:00:00 2001 From: sihamon <126967444+sihamon@users.noreply.github.com> Date: Wed, 8 Mar 2023 19:08:56 +0100 Subject: [PATCH] Add ability to show n pending tokens starting from offset (#135) --- cashu/wallet/cli/cli.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/cashu/wallet/cli/cli.py b/cashu/wallet/cli/cli.py index c5f08b4..4b81dd8 100644 --- a/cashu/wallet/cli/cli.py +++ b/cashu/wallet/cli/cli.py @@ -8,7 +8,7 @@ import sys import time from datetime import datetime from functools import wraps -from itertools import groupby +from itertools import groupby, islice from operator import itemgetter from os import listdir from os.path import isdir, join @@ -456,16 +456,20 @@ async def burn(ctx: Context, token: str, all: bool, force: bool): help="Print legacy token without mint information.", type=bool, ) +@click.option("--number", "-n", default=None, help='Show only n pending tokens.', type=int) +@click.option("--offset", default=0, help='Show pending tokens only starting from offset.', type=int) @click.pass_context @coro -async def pending(ctx: Context, legacy): +async def pending(ctx: Context, legacy, number: int, offset: int): wallet: Wallet = ctx.obj["WALLET"] reserved_proofs = await get_reserved_proofs(wallet.db) if len(reserved_proofs): print(f"--------------------------\n") sorted_proofs = sorted(reserved_proofs, key=itemgetter("send_id")) # type: ignore - for i, (key, value) in enumerate( - groupby(sorted_proofs, key=itemgetter("send_id")) + if number: + number += offset + for i, (key, value) in islice(enumerate( + groupby(sorted_proofs, key=itemgetter("send_id"),)), offset, number ): grouped_proofs = list(value) token = await wallet.serialize_proofs(grouped_proofs)