Exemplo n.º 1
0
def handle_wallet_balance(args):
    cfg = load_wallet_config(args)
    root_key = binascii.unhexlify(cfg['root_key'])
    hdpass = derive_hdpassphase(xpriv_to_xpub(root_key))

    # iterate utxo.
    print('Searching for utxo...')
    store = Storage(args.root)
    txouts = []
    for txin, txout in store.iter_utxo():
        if Address.decode(txout.addr).get_derive_path(hdpass):
            txouts.append(txout)

    balance = sum(out.c for out in txouts)
    print('balance:', balance)
    print('details:')
    for out in txouts:
        print(base58.b58encode(out.addr), out.c)
Exemplo n.º 2
0
def handle_sign(args):
    passphase = input_passphase()
    cfg = load_wallet_config(args)
    root_xpriv = binascii.unhexlify(cfg['root_key'])
    root_xpub = xpriv_to_xpub(root_xpriv)
    hdpass = derive_hdpassphase(root_xpub)
    addr = Address.decode_base58(args.addr)
    path = addr.get_derive_path(hdpass)
    if path is None:
        print('the address don\'t belong to this wallet')
        return
    xpriv = derive_key(root_xpriv, passphase, path, DERIVATION_V1)
    xpub = xpriv_to_xpub(xpriv)
    if not addr.verify_pubkey(xpub):
        print('the passphase is wrong')
        return
    sig = encrypted_sign(xpriv, passphase, args.message.encode('utf-8'))
    print(
        json.dumps({
            'xpub': binascii.hexlify(xpub).decode(),
            'addr': args.addr,
            'msg': args.message,
            'sig': binascii.hexlify(sig).decode(),
        }))