mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-20 18:44:20 +01:00
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:
@@ -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()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user