Files
nutshell/cashu
callebtc 35707ba6ff update
2022-09-13 22:10:36 +03:00

76 lines
2.2 KiB
Python
Executable File

#!/usr/bin/env python
import asyncio
import base64
import json
from functools import wraps
import click
from bech32 import bech32_decode, bech32_encode, convertbits
from wallet.migrations import m001_initial
from wallet.wallet import Wallet as Wallet
from core.settings import MINT_URL
# https://github.com/pallets/click/issues/85#issuecomment-503464628
def coro(f):
@wraps(f)
def wrapper(*args, **kwargs):
return asyncio.run(f(*args, **kwargs))
return wrapper
@click.command("mint")
@click.option("--host", default=MINT_URL, help="Mint hostname.")
@click.option("--wallet", default="wallet", help="Wallet to use.")
@click.option("--mint", default=0, help="Mint tokens.")
@click.option("--hash", default="", help="Hash of the paid invoice.")
@click.option("--send", default=0, help="Send tokens.")
@click.option("--receive", default="", help="Receive tokens.")
@click.option("--invalidate", default="", help="Invalidate tokens.")
@coro
async def main(host, wallet, mint, hash, send, receive, invalidate):
wallet = Wallet(host, f"data/{wallet}", wallet)
await m001_initial(db=wallet.db)
await wallet.load_proofs()
if mint and not hash:
print(f"Balance: {wallet.balance}")
r = await wallet.request_mint(mint)
print(r)
if mint and hash:
print(f"Balance: {wallet.balance}")
await wallet.mint(mint, hash)
print(f"Balance: {wallet.balance}")
if send:
wallet.status()
_, send_proofs = await wallet.split(wallet.proofs, send)
print(base64.urlsafe_b64encode(json.dumps(send_proofs).encode()).decode())
if receive:
wallet.status()
proofs = json.loads(base64.urlsafe_b64decode(receive))
_, _ = await wallet.redeem(proofs)
wallet.status()
if invalidate:
wallet.status()
proofs = json.loads(base64.urlsafe_b64decode(invalidate))
await wallet.invalidate(proofs)
wallet.status()
if __name__ == "__main__":
main()
@click.command("send")
@click.option("--send", default=1, help="Mint tokens.")
@coro
async def send(send):
print("asd")
# w1_fst_proofs, w1_snd_proofs = await wallet.split(proofs, 20)
return "asd"