Add ability to force-delete pending token by send ID (#142)

* Add ability to force-delete pending token by send ID

* Make format
This commit is contained in:
sihamon
2023-03-16 01:07:30 +01:00
committed by GitHub
parent f3a31fd09e
commit 9ae222740a

View File

@@ -423,17 +423,25 @@ async def receive_cli(
@cli.command("burn", help="Burn spent tokens.") @cli.command("burn", help="Burn spent tokens.")
@click.argument("token", required=False, type=str) @click.argument("token", required=False, type=str)
@click.option("--all", "-a", default=False, is_flag=True, help="Burn all spent tokens.") @click.option("--all", "-a", default=False, is_flag=True, help="Burn all spent tokens.")
@click.option(
"--delete",
"-d",
default=None,
help="Forcefully delete pending token by send ID if mint is unavailable.",
)
@click.option( @click.option(
"--force", "-f", default=False, is_flag=True, help="Force check on all tokens." "--force", "-f", default=False, is_flag=True, help="Force check on all tokens."
) )
@click.pass_context @click.pass_context
@coro @coro
async def burn(ctx: Context, token: str, all: bool, force: bool): async def burn(ctx: Context, token: str, all: bool, force: bool, delete: str):
wallet: Wallet = ctx.obj["WALLET"] wallet: Wallet = ctx.obj["WALLET"]
if not delete:
await wallet.load_mint() await wallet.load_mint()
if not (all or token or force) or (token and all): if not (all or token or force or delete) or (token and all):
print( print(
"Error: enter a token or use --all to burn all pending tokens or --force to check all tokens." "Error: enter a token or use --all to burn all pending tokens, --force to check all tokens or"
"or --delete with send ID to force-delete pending token from list if mint is unavailable."
) )
return return
if all: if all:
@@ -442,10 +450,16 @@ async def burn(ctx: Context, token: str, all: bool, force: bool):
elif force: elif force:
# check all proofs in db # check all proofs in db
proofs = wallet.proofs proofs = wallet.proofs
elif delete:
reserved_proofs = await get_reserved_proofs(wallet.db)
proofs = [proof for proof in reserved_proofs if proof["send_id"] == delete]
else: else:
# check only the specified ones # check only the specified ones
proofs = [Proof(**p) for p in json.loads(base64.urlsafe_b64decode(token))] proofs = [Proof(**p) for p in json.loads(base64.urlsafe_b64decode(token))]
if delete:
await wallet.invalidate(proofs, check_spendable=False)
else:
await wallet.invalidate(proofs) await wallet.invalidate(proofs)
wallet.status() wallet.status()