Example #1
0
def main():
    if len(sys.argv) != 5:
        print(
            'usage: %s <from> <to> <send value sats; negative to send everything> <max num inputs>'
            % basename(sys.argv[0]))
        sys.exit(0)

    fr = s2b(sys.argv[1])
    to = sys.argv[2]
    val = int(sys.argv[3])
    max_in = int(sys.argv[4])

    if not energi.check_address(to):
        raise RuntimeError('bad to address: %s' % to)

    if val < 0:
        val = None
        print('Sending ALL NRG to %s.' % (to))
    else:
        print('Sending %f NRG to %s.' % (val / _NRGSAT, to))

    addr_d = walletdb.get_address_d(with_change=True)
    addr_d = {fr: addr_d[fr], 'change': addr_d['change']}

    bal = balance(addr_d)
    print('\nCurrent balance: %f NRG. (%d Sat)' % (bal / _NRGSAT, bal))

    print('Removing locked outputs.')
    count = 0
    for a in addr_d.keys():
        nul = []
        for u in addr_d[a].get('utxos', []):
            if not walletdb.is_locked_txid(u['txid'],
                                           u['nout']) and count < max_in:
                nul.append(u)
                count += 1
        addr_d[a]['utxos'] = nul
    bal = balance(addr_d)
    print('\nAvailable balance: %f NRG. (%d Sat)' % (bal / _NRGSAT, bal))

    print('Creating transaction.')
    used_inputs = []
    tx = Transaction.create_tx(to,
                               val,
                               addr_d,
                               fee_minimum=4096,
                               used_inputs=used_inputs)
    print('\n\nTransaction: (%d) %s' % (len(tx), serialize.b2hs(tx)))

    sys.stdout.write('\nVerifying transaction with energid... ')
    sys.stdout.flush()
    print(eel.decode_raw_transaction(serialize.b2hs(tx)))

    input('\n\nVerified.  Press <enter> to transmit ^C to cancel.  ')

    txid = eel.send_raw_transaction(serialize.b2hs(tx))
    print('Transmitted.  Txid = %s' % (serialize.b2s(txid)))

    for u in used_inputs:
        walletdb.remove_unspent_db(u['txid'], u['nout'])
Example #2
0
def main():
    if len(sys.argv) != 3:
        print('usage: %s <to> <send value sats; negative to send everything>' %
              basename(sys.argv[0]))
        sys.exit(0)

    to = sys.argv[1]
    val = int(sys.argv[2])

    if not energi.check_address(to):
        raise RuntimeError('bad to address: %s' % to)

    if val < 0:
        val = None
        print('Sending ALL NRG to %s.' % (to))
    else:
        print('Sending %f NRG to %s.' % (val / _NRGSAT, to))

    addr_d = walletdb.get_address_d(with_change=True)
    bal = walletdb.get_balance()
    print('\nCurrent balance: %f NRG.' % (bal / _NRGSAT))

    print('Removing locked outputs.')
    for a in addr_d:
        nul = []
        for u in addr_d[a].get('utxos', []):
            if not walletdb.is_locked_txid(u['txid'], u['nout']):
                nul.append(u)
            else:
                print('removing locked: %s' % u)
        addr_d[a]['utxos'] = nul

    sys.stdout.write('Creating transaction; confirm on ledger: ')
    sys.stdout.flush()
    tx = Transaction.create_tx(to, val, addr_d)
    print('\n\nTransaction: %s' % serialize.b2hs(tx))

    sys.stdout.write('\nVerifying transaction with energid... ')
    sys.stdout.flush()
    print(eel.decode_raw_transaction(serialize.b2hs(tx)))

    input('\n\nVerified.  Press <enter> to transmit ^C to cancel.  ')

    txid = eel.send_raw_transaction(serialize.b2hs(tx))
    print('Transmitted.  Txid = %s' % (serialize.b2s(txid)))
Example #3
0
def main():
    if len(sys.argv) < 4:
        print(
            'usage: %s <to> <send value sats; negative to send everything> <txid:nout> [txid:nout [...]]'
            % basename(sys.argv[0]))
        sys.exit(0)

    to = sys.argv[1]
    val = int(sys.argv[2])
    utxol = [{
        'txid': y[0],
        'nout': int(y[1])
    } for y in [x.split(':') for x in sys.argv[3:]]]

    if len(utxol) < 1:
        raise RuntimeError('must include at least 1 utxo')

    if not energi.check_address(to):
        raise RuntimeError('bad address "%s"' % to)

    if val < 0:
        val = None
        print('Sending ALL NRG to %s.' % (to))
    else:
        print('Sending %f NRG to %s.' % (val / _NRGSAT, to))

    addr_d = walletdb.get_address_d(with_change=True)
    print('Searching for utxo%s in walletdb...' %
          ('s' if len(utxol) > 1 else ''))
    for addr in addr_d:
        if 'utxos' in addr_d[addr]:
            nutxos = []
            for u in addr_d[addr]['utxos']:
                for iu in utxol:
                    if u['txid'] == iu['txid'] and u['nout'] == iu['nout']:
                        nutxos.append(u)
                        break
            addr_d[addr]['utxos'] = nutxos

    bal = balance(addr_d)
    print('\nCurrent balance: %f NRG. (%d Sat)' % (bal / _NRGSAT, bal))

    print('Unlocking given inputs: %s' % utxol)
    input('Press <enter> to unlock, ^C to cancel')
    for addr in addr_d:
        if 'utxos' in addr_d[addr]:
            for u in addr_d[addr]['utxos']:
                print('unlocking: %s:%d' % (u['txid'], u['nout']))
                walletdb.unlock_txid(u['txid'], u['nout'])

    print('Removing locked outputs.')
    count = 0
    for a in addr_d.keys():
        nul = []
        for u in addr_d[a].get('utxos', []):
            if not walletdb.is_locked_txid(u['txid'], u['nout']):
                nul.append(u)
                count += 1
        addr_d[a]['utxos'] = nul
    bal = balance(addr_d)
    print('\nAvailable balance: %f NRG. (%d Sat)' % (bal / _NRGSAT, bal))

    print('Creating transaction.')
    used_inputs = []
    tx = Transaction.create_tx(to,
                               val,
                               addr_d,
                               fee_minimum=4096,
                               used_inputs=used_inputs)
    print('\n\nTransaction: (%d) %s' % (len(tx), serialize.b2hs(tx)))

    sys.stdout.write('\nVerifying transaction with energid... ')
    sys.stdout.flush()
    print(eel.decode_raw_transaction(serialize.b2hs(tx)))

    input('\n\nVerified.  Press <enter> to transmit ^C to cancel.  ')

    txid = eel.send_raw_transaction(serialize.b2hs(tx))
    print('Transmitted.  Txid = %s' % (serialize.b2s(txid)))

    for u in used_inputs:
        walletdb.remove_unspent_db(u['txid'], u['nout'])