コード例 #1
0
ファイル: hotkey.py プロジェクト: MarkTseng/bitcoind-ncurses
def change_mode(block_viewer, state, window, mode, poller):
    try:
        g.modes.index(mode)
    except ValueError:
        return False

    state['mode'] = mode
    block_viewer._mode = mode

    if mode == 'monitor':
        monitor.draw_window(state, window)
    elif mode == 'tx':
        tx.draw_window(state, window)
    elif mode == 'peers':
        peers.draw_window(state, window)
    elif mode == 'wallet':
        wallet.draw_window(state, window)
    elif mode == 'block':
        block_viewer.draw()
    elif mode == 'console':
        console.draw_window(state, window)
    elif mode == 'net':
        net.draw_window(state, window)
    elif mode == 'forks':
        forks.draw_window(state, window)

    footer.draw_window(state)
    poller.set_mode(mode)
コード例 #2
0
ファイル: hotkey.py プロジェクト: vertoe/darkcoind-ncurses
def change_mode(state, window, mode):
    try:
        g.modes.index(mode)
    except ValueError:
        return False

    state['mode'] = mode

    if mode == 'overview':
        monitor.draw_window(state, window)
    elif mode == 'tx':
        tx.draw_window(state, window)
    elif mode == 'peers':
        peers.draw_window(state, window)
    elif mode == 'wallet':
        wallet.draw_window(state, window)
    elif mode == 'block':
        block.draw_window(state, window)
    elif mode == 'console':
        console.draw_window(state, window)
    elif mode == 'net':
        net.draw_window(state, window)
    elif mode == 'forks':
        forks.draw_window(state, window)
    elif mode == 'mnodes':
        mnode.draw_window(state, window)
コード例 #3
0
ファイル: hotkey.py プロジェクト: TheOnePerson/coind-ncurses
def change_mode(state, window, mode, rpc_queue=None):
    try:
        g.modes.index(mode)
    except ValueError:
        return False

    state['mode'] = mode

    if mode == 'home':
        monitor.draw_window(state, window, rpc_queue)
    elif mode == 'tx':
        tx.draw_window(state, window, rpc_queue)
    elif mode == 'peers':
        peers.draw_window(state, window, rpc_queue)
    elif mode == 'wallet':
        wallet.draw_window(state, window, rpc_queue)
    elif mode == 'mempool':
        mempool.draw_window(state, window, rpc_queue)
    elif mode == 'block':
        block.draw_window(state, window, rpc_queue)
    elif mode == 'console':
        console.draw_window(state, window, rpc_queue)
    elif mode == 'net':
        net.draw_window(state, window, rpc_queue)
    elif mode == 'forks':
        forks.draw_window(state, window, rpc_queue)
コード例 #4
0
ファイル: hotkey.py プロジェクト: TheOnePerson/coind-ncurses
def key_l(state, window, rpc_queue):
    if state['mode'] == 'wallet':
        if 'wallet' in state:
            state['wallet']['mode'] = 'backupwallet'
            wallet.draw_window(state, window, rpc_queue)
    elif state['mode'] == "block":
        go_to_latest_block(state, window, rpc_queue)
コード例 #5
0
ファイル: hotkey.py プロジェクト: TheOnePerson/coind-ncurses
def key_a(state, window, rpc_queue):
    if state['mode'] == 'wallet':
        if 'wallet' in state:
            state['wallet']['mode'] = 'addresses'
            rpc_queue.put('getwalletinfo')
            rpc_queue.put('listreceivedbyaddress')
            wallet.draw_window(state, window, rpc_queue)
コード例 #6
0
def change_mode(block_viewer, state, window, mode, poller):
    try:
        g.modes.index(mode)
    except ValueError:
        return False

    state['mode'] = mode
    block_viewer._mode = mode

    if mode == 'monitor':
        monitor.draw_window(state, window)
    elif mode == 'tx':
        tx.draw_window(state, window)
    elif mode == 'peers':
        peers.draw_window(state, window)
    elif mode == 'wallet':
        wallet.draw_window(state, window)
    elif mode == 'block':
        block_viewer.draw()
    elif mode == 'console':
        console.draw_window(state, window)
    elif mode == 'net':
        net.draw_window(state, window)
    elif mode == 'forks':
        forks.draw_window(state, window)

    footer.draw_window(state)
    poller.set_mode(mode)
コード例 #7
0
ファイル: process.py プロジェクト: TheOnePerson/coind-ncurses
def getnewaddress(s, state, window, rpc_queue):
    if state['mode'] == "wallet":
        if 'wallet' in state:
            state['wallet']['newaddress'] = str(s['getnewaddress'])
            wallet.draw_new_address_update(state, window)
            state['wallet']['mode'] = 'addresses'
            rpc_queue.put('listreceivedbyaddress')
            wallet.draw_window(state, window, rpc_queue)
コード例 #8
0
ファイル: process.py プロジェクト: TheOnePerson/coind-ncurses
def listreceivedbyaddress(s, state, window, rpc_queue):
    state['wallet']['addresses'] = s['listreceivedbyaddress']
    state['wallet']['cursor'] = 0
    state['wallet']['offset'] = 0

    state['wallet']['addresses_view_string'] = []
    state['wallet']['addresses_view_colorpair'] = []
    state['wallet']['mode'] = 'addresses'

    state['wallet']['addresses'].sort(key=lambda entry: 999999 if entry['confirmations'] == 0 else entry['confirmations'], reverse=False)

    unit = g.coin_unit
    if 'testnet' in state:
        if state['testnet']:
            unit = g.coin_unit_test

    for entry in state['wallet']['addresses']:
        if 'address' in entry:
            amount_in = entry['amount']
            # find spendings for address
            if 'spendings' in state['wallet']:
                if str(entry['address']) in state['wallet']['spendings']:
                    amount_out = -state['wallet']['spendings'][str(entry['address'])]
                    amount = entry['amount'] + state['wallet']['spendings'][str(entry['address'])]
                else:
                    amount_out = 0.0
                    amount = entry['amount']
            else:
                amount_out = 0.0
                amount = entry['amount']
            if amount < 0:
                amount = 0
            if amount_out > amount_in:
                amount_in = amount_out
            
            if amount > 0:
                color = 1
            else:
                color = 0
            output_string = entry['address'] + str("% 17.8f " % amount + unit).rjust(39)
            state['wallet']['addresses_view_string'].append(output_string)
            state['wallet']['addresses_view_colorpair'].append(color)
            
            output_string = " " + str(str(entry['confirmations']) + " conf").ljust(15)
            output_string += str(str(len(entry['txids'])) + ' tx').rjust(10)
            output_string += str("(in:" + "% 1.8f" % amount_in + ", out:" + "% 1.8f" % amount_out + ")").rjust(44)
            state['wallet']['addresses_view_string'].append(output_string)
            state['wallet']['addresses_view_colorpair'].append(0)

            output_string = " " + entry['account'].ljust(36) 
            state['wallet']['addresses_view_string'].append(output_string)
            state['wallet']['addresses_view_colorpair'].append(0)

            state['wallet']['addresses_view_string'].append("")
            state['wallet']['addresses_view_colorpair'].append(0)

    if state['mode'] == "wallet":
        wallet.draw_window(state, window, rpc_queue)
コード例 #9
0
def listsinceblock(s, state, window):
    state['wallet'] = s['listsinceblock']
    state['wallet']['cursor'] = 0
    state['wallet']['offset'] = 0

    state['wallet']['view_string'] = []

    state['wallet']['transactions'].sort(key=lambda entry: entry['category'], reverse=True)

    # add cumulative balance field to transactiosn once ordered by time
    state['wallet']['transactions'].sort(key=lambda entry: entry['time'])
    state['wallet']['transactions'].sort(key=lambda entry: entry['confirmations'], reverse=True)
    cumulative_balance = 0
    nonce = 0 # ensures a definitive ordering of transactions for cumulative balance
    for entry in state['wallet']['transactions']:
        entry['nonce'] = nonce
        nonce += 1
        if 'amount' in entry:
            if 'fee' in entry:
                cumulative_balance += entry['fee']
            cumulative_balance += entry['amount']
            entry['cumulative_balance'] = cumulative_balance

    state['wallet']['transactions'].sort(key=lambda entry: entry['nonce'], reverse=True)

    unit = 'BTC'
    if 'testnet' in state:
        if state['testnet']:
            unit = 'TNC'

    for entry in state['wallet']['transactions']:
        if 'txid' in entry:
            entry_time = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(entry['time']))
            output_string = entry_time + " %8d" % entry['confirmations'] + " conf"
            delta = entry['amount']
            if 'fee' in entry:
                delta += entry['fee'] # this fails if not all inputs owned by wallet; could be 'too negative'
            output_string += "% 17.8f" % delta + unit
            output_string += " " + "% 17.8f" % entry['cumulative_balance'] + unit
            state['wallet']['view_string'].append(output_string)

            output_string = entry['txid'].rjust(74)
            state['wallet']['view_string'].append(output_string)

            if 'address' in entry: # TODO: more sanity checking here
                output_string = "          " + entry['category'].ljust(15) + entry['address']
            else:
                output_string = "          unknown transaction type"
            state['wallet']['view_string'].append(output_string)

            state['wallet']['view_string'].append("")

    if state['mode'] == "wallet":
        wallet.draw_window(state, window)
        footer.draw_window(state)
コード例 #10
0
ファイル: process.py プロジェクト: MarkTseng/bitcoind-ncurses
def listsinceblock(s, state, window):
    state['wallet'] = s['listsinceblock']
    state['wallet']['cursor'] = 0
    state['wallet']['offset'] = 0

    state['wallet']['view_string'] = []

    state['wallet']['transactions'].sort(key=lambda entry: entry['category'], reverse=True)

    # add cumulative balance field to transactiosn once ordered by time
    state['wallet']['transactions'].sort(key=lambda entry: entry['time'])
    state['wallet']['transactions'].sort(key=lambda entry: entry['confirmations'], reverse=True)
    cumulative_balance = 0
    nonce = 0 # ensures a definitive ordering of transactions for cumulative balance
    for entry in state['wallet']['transactions']:
        entry['nonce'] = nonce
        nonce += 1
        if 'amount' in entry:
            if 'fee' in entry:
                cumulative_balance += entry['fee']
            cumulative_balance += entry['amount']
            entry['cumulative_balance'] = cumulative_balance

    state['wallet']['transactions'].sort(key=lambda entry: entry['nonce'], reverse=True)

    unit = 'BTC'
    if 'testnet' in state:
        if state['testnet']:
            unit = 'TNC'

    for entry in state['wallet']['transactions']:
        if 'txid' in entry:
            entry_time = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(entry['time']))
            output_string = entry_time + " %8d" % entry['confirmations'] + " conf"
            delta = entry['amount']
            if 'fee' in entry:
                delta += entry['fee'] # this fails if not all inputs owned by wallet; could be 'too negative'
            output_string += "% 17.8f" % delta + unit
            output_string += " " + "% 17.8f" % entry['cumulative_balance'] + unit
            state['wallet']['view_string'].append(output_string)

            output_string = entry['txid'].rjust(74)
            state['wallet']['view_string'].append(output_string)

            if 'address' in entry: # TODO: more sanity checking here
                output_string = "          " + entry['category'].ljust(15) + entry['address']
            else:
                output_string = "          unknown transaction type"
            state['wallet']['view_string'].append(output_string)

            state['wallet']['view_string'].append("")

    if state['mode'] == "wallet":
        wallet.draw_window(state, window)
        footer.draw_window(state)
コード例 #11
0
ファイル: process.py プロジェクト: TheOnePerson/coind-ncurses
def getwalletinfo(s, state, window, rpc_queue):
    state['walletinfo'] = s['getwalletinfo']
    if 'walletversion' in s['getwalletinfo']:
        g.wallet_support = True
    else:
        g.wallet_support = False
        if 'wallet' in g.modes:
            g.modes.remove('wallet')

    if state['mode'] == "wallet":
        wallet.draw_window(state, window, rpc_queue)
コード例 #12
0
ファイル: hotkey.py プロジェクト: TheOnePerson/coind-ncurses
def key_e(state, window, rpc_queue):
    if state['mode'] == 'wallet':
        if 'wallet' in state:
            if state['wallet']['mode'] == 'tx':
                state['wallet']['mode'] = 'exporttx'
                wallet.draw_window(state, window, rpc_queue)

    elif state['mode'] == 'console':
        state['console']['cbuffer'] = []
        state['console']['rbuffer'] = []
        state['console']['offset'] = 0
        console.draw_window(state, window, rpc_queue)
コード例 #13
0
def resize(s, state, window):
    if state['mode'] == 'tx':
        tx.draw_window(state, window)
    elif state['mode'] == 'block':
        block.draw_window(state, window)
    elif state['mode'] == 'peers':
        peers.draw_window(state, window)
    elif state['mode'] == 'wallet':
        wallet.draw_window(state, window)
    elif state['mode'] == 'monitor':
        monitor.draw_window(state, window)
    elif state['mode'] == 'console':
        console.draw_window(state, window)
    elif state['mode'] == 'net':
        net.draw_window(state, window)
コード例 #14
0
def resize(s, state, window):
    if state['mode'] == 'tx':
        tx.draw_window(state, window)
    elif state['mode'] == 'block':
        block.draw_window(state, window)
    elif state['mode'] == 'peers':
        peers.draw_window(state, window)
    elif state['mode'] == 'wallet':
        wallet.draw_window(state, window)
    elif state['mode'] == 'monitor':
        monitor.draw_window(state, window)
    elif state['mode'] == 'console':
        console.draw_window(state, window)
    elif state['mode'] == 'net':
        net.draw_window(state, window)
コード例 #15
0
ファイル: process.py プロジェクト: TheOnePerson/coind-ncurses
def resize(s, state, window, rpc_queue):
    if state['mode'] == 'tx':
        tx.draw_window(state, window, rpc_queue)
    elif state['mode'] == 'block':
        block.draw_window(state, window, rpc_queue)
    elif state['mode'] == 'mempool':
        mempool.draw_window(state, window, rpc_queue)
    elif state['mode'] == 'peers':
        peers.draw_window(state, window, rpc_queue)
    elif state['mode'] == 'wallet':
        wallet.draw_window(state, window, rpc_queue)
    elif state['mode'] == 'home':
        monitor.draw_window(state, window, rpc_queue)
    elif state['mode'] == 'console':
        console.draw_window(state, window, rpc_queue)
    elif state['mode'] == 'net':
        net.draw_window(state, window, rpc_queue)
    elif state['mode'] == 'forks':
        forks.draw_window(state, window, rpc_queue)
コード例 #16
0
ファイル: hotkey.py プロジェクト: PRabahy/bitcoind-ncurses
def change_mode(state, window, mode):
    try:
        g.modes.index(mode)
    except ValueError:
        return False

    state['mode'] = mode

    if mode == 'monitor':
        monitor.draw_window(state, window)
    elif mode == 'transaction':
        tx.draw_window(state, window)
    elif mode == 'peers':
        peers.draw_window(state, window)
    elif mode == 'wallet':
        wallet.draw_window(state, window)
    elif mode == 'block':
        block.draw_window(state, window)
    elif mode == 'console':
        console.draw_window(state, window)
コード例 #17
0
ファイル: process.py プロジェクト: PRabahy/bitcoind-ncurses
def queue(state, window, interface_queue):
    try:
        s = interface_queue.get(False)
    except Queue.Empty:
        return False

    if 'stop' in s:
        return s['stop']

    elif 'resize' in s:
        if state['mode'] == 'transaction':
            tx.draw_window(state, window)
        elif state['mode'] == 'block':
            block.draw_window(state, window)
        elif state['mode'] == 'peers':
            peers.draw_window(state, window)
        elif state['mode'] == 'wallet':
            wallet.draw_window(state, window)
        elif state['mode'] == 'monitor':
            monitor.draw_window(state, window)
        elif state['mode'] == 'console':
            console.draw_window(state, window)
        # redraw_all_the_things
        pass

    elif 'getinfo' in s:
        state['version'] = str(s['getinfo']['version'] / 1000000)
        state['version'] += '.' + str((s['getinfo']['version'] % 1000000) / 10000)
        state['version'] += '.' + str((s['getinfo']['version'] % 10000) / 100)
        state['version'] += '.' + str((s['getinfo']['version'] % 100))
        if s['getinfo']['testnet'] == True:
            state['testnet'] = 1
        else:
            state['testnet'] = 0
        state['peers'] = s['getinfo']['connections']

        if state['mode'] == "splash":
            splash.draw_window(state, window)
    
    elif 'getconnectioncount' in s:
        state['peers'] = s['getconnectioncount']

    elif 'getblockcount' in s:
        state['blockcount'] = s['getblockcount']
        if 'browse_height' not in state['blocks']:
            state['blocks']['browse_height'] = state['blockcount']

    elif 'getbalance' in s:
        state['balance'] = s['getbalance']

    elif 'getunconfirmedbalance' in s:
        state['unconfirmedbalance'] = s['getunconfirmedbalance']

    elif 'getblock' in s:
        height = s['getblock']['height']

        state['blocks'][str(height)] = s['getblock']

        if state['mode'] == "monitor":
            monitor.draw_window(state, window)
        if state['mode'] == "block":
            if 'queried' in s['getblock']:
                state['blocks'][str(height)].pop('queried')
                state['blocks']['browse_height'] = height
                state['blocks']['offset'] = 0
                state['blocks']['cursor'] = 0
                block.draw_window(state, window)

    elif 'coinbase' in s:
        height = str(s['height'])
        if height in state['blocks']:
            state['blocks'][height]['coinbase_amount'] = s['coinbase']

    elif 'getdifficulty' in s:
        state['difficulty'] = s['getdifficulty']

    elif 'getnetworkhashps' in s:
        blocks = s['getnetworkhashps']['blocks']
        state['networkhashps'][blocks] = s['getnetworkhashps']['value']

        if state['mode'] == "splash" and blocks == 2016: # initialization complete
            state['mode'] = "monitor"
            monitor.draw_window(state, window)

    elif 'getnettotals' in s:
        state['totalbytesrecv'] = s['getnettotals']['totalbytesrecv']
        state['totalbytessent'] = s['getnettotals']['totalbytessent']

    elif 'getrawmempool' in s:
        state['rawmempool'] = s['getrawmempool']

    elif 'getpeerinfo' in s:
        state['peerinfo'] = s['getpeerinfo']
        state['peerinfo_offset'] = 0
        if state['mode'] == "peers":
            peers.draw_window(state, window)

    elif 'listsinceblock' in s:
        state['wallet'] = s['listsinceblock']
        state['wallet']['cursor'] = 0
        state['wallet']['offset'] = 0

        state['wallet']['view_string'] = []

        state['wallet']['transactions'].sort(key=lambda entry: entry['category'], reverse=True)

        # add cumulative balance field to transactiosn once ordered by time
        state['wallet']['transactions'].sort(key=lambda entry: entry['time'])
        state['wallet']['transactions'].sort(key=lambda entry: entry['confirmations'], reverse=True)
        cumulative_balance = 0
        nonce = 0 # ensures a definitive ordering of transactions for cumulative balance
        for entry in state['wallet']['transactions']:
            entry['nonce'] = nonce
            nonce += 1
            if 'amount' in entry:
                if 'fee' in entry:
                    cumulative_balance += entry['fee']
                cumulative_balance += entry['amount']
                entry['cumulative_balance'] = cumulative_balance

        state['wallet']['transactions'].sort(key=lambda entry: entry['nonce'], reverse=True)

        unit = 'BTC'
        if 'testnet' in state:
            if state['testnet']:
                unit = 'TNC'

        for entry in state['wallet']['transactions']: 
            if 'txid' in entry:
                entry_time = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(entry['time']))
                output_string = entry_time + " %8d" % entry['confirmations'] + " conf"
                delta = entry['amount']
                if 'fee' in entry:
                    delta += entry['fee'] # this fails if not all inputs owned by wallet; could be 'too negative'
                output_string += "% 17.8f" % delta + unit
                output_string += " " + "% 17.8f" % entry['cumulative_balance'] + unit
                state['wallet']['view_string'].append(output_string)

                output_string = entry['txid'].rjust(74)
                state['wallet']['view_string'].append(output_string)

                if 'address' in entry: # TODO: more sanity checking here
                    output_string = "          " + entry['category'].ljust(15) + entry['address']
                else:
                    output_string = "          unknown transaction type"
                state['wallet']['view_string'].append(output_string)

                state['wallet']['view_string'].append("")

        if state['mode'] == "wallet":
            wallet.draw_window(state, window)

    elif 'lastblocktime' in s:
        state['lastblocktime'] = s['lastblocktime']

    elif 'txid' in s:
        state['tx'] = {
            'txid': s['txid'],
            'vin': [],
            'vout_string': [],
            'cursor': 0,
            'offset': 0,
            'out_offset': 0,
            'loaded': 1,
            'mode': 'inputs',
            'size': s['size'],
        }

        for vin in s['vin']:
            if 'coinbase' in vin:
                state['tx']['vin'].append({'coinbase':  vin['coinbase']})
            elif 'txid' in vin:
                if 'prev_tx' in vin:
                    state['tx']['vin'].append({'txid': vin['txid'], 'vout': vin['vout'], 'prev_tx': vin['prev_tx']})
                else:
                    state['tx']['vin'].append({'txid': vin['txid'], 'vout': vin['vout']})

        state['tx']['total_outputs'] = 0
        for vout in s['vout']:
            if 'value' in vout:
                if vout['scriptPubKey']['type'] == "pubkeyhash":
                    buffer_string = "% 14.8f" % vout['value'] + ": " + vout['scriptPubKey']['addresses'][0]
                else:
                    buffer_string = "% 14.8f" % vout['value'] + ": " + vout['scriptPubKey']['asm']

                if 'confirmations' in s:
                    if 'spent' in vout:
                        if vout['spent'] == 'confirmed':
                            buffer_string += " [SPENT]"
                        elif vout['spent'] == 'unconfirmed':
                            buffer_string += " [UNCONFIRMED SPEND]"
                        else:
                            buffer_string += " [UNSPENT]"

                state['tx']['total_outputs'] += vout['value']
                state['tx']['vout_string'].extend(textwrap.wrap(buffer_string,70)) # change this to scale with window ?

        if 'total_inputs' in s:
            state['tx']['total_inputs'] = s['total_inputs']

        if 'confirmations' in s:
            state['tx']['confirmations'] = s['confirmations']

        if state['mode'] == "transaction":
            tx.draw_window(state, window)

    elif 'consolecommand' in s:
        state['console']['cbuffer'].append(s['consolecommand'])
        state['console']['rbuffer'].append(s['consoleresponse'])
        state['console']['offset'] = 0
        if state['mode'] == "console":
            console.draw_window(state, window)

    return False
コード例 #18
0
def queue(state, window, interface_queue):
    try: s = interface_queue.get(False)
    except Queue.Empty: s = {}

    if 'stop' in s:
        return s['stop']

    if 'getinfo' in s:
        state['version'] = str(s['getinfo']['version'] / 1000000)
        state['version'] += '.' + str((s['getinfo']['version'] % 1000000) / 10000)
        state['version'] += '.' + str((s['getinfo']['version'] % 10000) / 100)
        state['version'] += '.' + str((s['getinfo']['version'] % 100))
        if s['getinfo']['testnet'] == True:
            state['testnet'] = 1
        else:
            state['testnet'] = 0
        state['peers'] = s['getinfo']['connections']
    
    elif 'getconnectioncount' in s:
        state['peers'] = s['getconnectioncount']

    elif 'getblockcount' in s:
        state['blockcount'] = s['getblockcount']
        if 'browse_height' not in state['blocks']:
            state['blocks']['browse_height'] = state['blockcount']

    elif 'getbalance' in s:
        state['balance'] = s['getbalance']

    elif 'getunconfirmedbalance' in s:
        state['unconfirmedbalance'] = s['getunconfirmedbalance']

    elif 'getblock' in s:
        height = s['getblock']['height']

        state['blocks'][str(height)] = s['getblock']

        if state['mode'] == "monitor":
            monitor.draw_window(state, window)
        if state['mode'] == "block":
            if 'queried' in s['getblock']:
                state['blocks'][str(height)].pop('queried')
                state['blocks']['browse_height'] = height
                state['blocks']['offset'] = 0
                state['blocks']['cursor'] = 0
                block.draw_window(state, window)

    elif 'coinbase' in s:
        height = str(s['height'])
        if height in state['blocks']:
            state['blocks'][height]['coinbase_amount'] = s['coinbase']

    elif 'getdifficulty' in s:
        state['difficulty'] = s['getdifficulty']

    elif 'getnetworkhashps' in s:
        blocks = s['getnetworkhashps']['blocks']
        state['networkhashps'][blocks] = s['getnetworkhashps']['value']

    elif 'getnettotals' in s:
        state['totalbytesrecv'] = s['getnettotals']['totalbytesrecv']
        state['totalbytessent'] = s['getnettotals']['totalbytessent']

    elif 'getrawmempool' in s:
        state['rawmempool'] = s['getrawmempool']

    elif 'getpeerinfo' in s:
        state['peerinfo'] = s['getpeerinfo']
        state['peerinfo_offset'] = 0
        if state['mode'] == "peers":
            peers.draw_window(state, window)

    elif 'listsinceblock' in s:
        state['wallet'] = s['listsinceblock']
        state['wallet']['cursor'] = 0
        state['wallet']['offset'] = 0

        state['wallet']['view_string'] = []

        state['wallet']['transactions'].sort(key=lambda entry: entry['category'], reverse=True)

        # add cumulative balance field to transactiosn once ordered by time
        state['wallet']['transactions'].sort(key=lambda entry: entry['time'])
        cumulative_balance = 0
        nonce = 0 # ensures a definitive ordering of transactions for cumulative balance
        for entry in state['wallet']['transactions']:
            entry['nonce'] = nonce
            nonce += 1
            if 'amount' in entry:
                if 'fee' in entry:
                    cumulative_balance += entry['fee']
                cumulative_balance += entry['amount']
                entry['cumulative_balance'] = cumulative_balance

        state['wallet']['transactions'].sort(key=lambda entry: entry['nonce'], reverse=True)

        for entry in state['wallet']['transactions']: 
            if 'txid' in entry:
                entry_time = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(entry['time']))
                output_string = entry_time + " %8d" % entry['confirmations'] + " conf"
                delta = entry['amount']
                if 'fee' in entry:
                    delta += entry['fee']
                output_string +=  "% 17.8f" % delta + "BTC "
                output_string +=  "% 17.8f" % entry['cumulative_balance'] + "BTC"
                state['wallet']['view_string'].append(output_string)

                output_string = entry['txid'].rjust(74)
                state['wallet']['view_string'].append(output_string)

                if 'address' in entry: # TODO: more sanity checking here
                    output_string = "          " + entry['category'].ljust(15) + entry['address']
                else:
                    output_string = "          unknown transaction type"
                state['wallet']['view_string'].append(output_string)

                state['wallet']['view_string'].append("")

        if state['mode'] == "wallet":
            wallet.draw_window(state, window)

    elif 'lastblocktime' in s:
        state['lastblocktime'] = s['lastblocktime']

    elif 'txid' in s:
        state['tx'] = {
            'txid': s['txid'],
            'vin': [],
            'vout_string': [],
            'cursor': 0,
            'offset': 0,
            'out_offset': 0,
            'size': s['size']
        }

        for vin in s['vin']:
            if 'coinbase' in vin:
                state['tx']['vin'].append({'coinbase':  vin['coinbase']})
            elif 'txid' in vin:
                state['tx']['vin'].append({'txid': vin['txid'], 'vout': vin['vout']})

        for vout in s['vout']:
            if 'value' in vout:
                if vout['scriptPubKey']['type'] == "pubkeyhash":
                    buffer_string = "% 14.8f" % vout['value'] + ": " + vout['scriptPubKey']['addresses'][0]
                else:
                    buffer_string = "% 14.8f" % vout['value'] + ": " + vout['scriptPubKey']['asm']
                state['tx']['vout_string'].extend(textwrap.wrap(buffer_string,70)) # change this to scale with window ?

        if state['mode'] == "transaction":
            tx.draw_window(state, window)

    return False
コード例 #19
0
ファイル: process.py プロジェクト: TheOnePerson/coind-ncurses
def settxfee(s, state, window, rpc_queue):
    state['wallet']['mode'] = 'tx'
    rpc_queue.put('getwalletinfo')
    wallet.draw_window(state, window, rpc_queue)
コード例 #20
0
ファイル: process.py プロジェクト: TheOnePerson/coind-ncurses
def importaddress(s, state, window, rpc_queue):
    if state['mode'] == "wallet":
        if 'wallet' in state:
            state['wallet']['mode'] = 'addresses'
            rpc_queue.put('listreceivedbyaddress')
            wallet.draw_window(state, window, rpc_queue)
コード例 #21
0
ファイル: process.py プロジェクト: TheOnePerson/coind-ncurses
def listsinceblock(s, state, window, rpc_queue, reload=True):
    if reload:
        state['wallet'] = s['listsinceblock']
    state['wallet']['cursor'] = 0
    state['wallet']['offset'] = 0
    if not 'verbose' in state['wallet']:
        state['wallet']['verbose'] = 0

    state['wallet']['view_string'] = []
    state['wallet']['view_colorpair'] = []
    state['wallet']['csv_data'] = []
    state['wallet']['spendings'] = {}
    state['wallet']['mode'] = 'tx'

    state['wallet']['transactions'].sort(key=lambda entry: entry['category'],
                                         reverse=True)

    # add cumulative balance field to transactions once ordered by time
    state['wallet']['transactions'].sort(key=lambda entry: entry['time'])
    state['wallet']['transactions'].sort(
        key=lambda entry: entry['confirmations'], reverse=True)
    cumulative_balance = 0
    nonce = 0  # ensures a definitive ordering of transactions for cumulative balance
    for entry in state['wallet']['transactions']:
        entry['nonce'] = nonce
        nonce += 1
        if 'amount' in entry:
            if 'fee' in entry:
                cumulative_balance += entry['fee']
            cumulative_balance += entry['amount']
            entry['cumulative_balance'] = cumulative_balance
            # store csv data to state
            csv = {}
            csv['Confirmed'] = 'true' if int(
                entry['confirmations']) > 0 else 'false'
            csv['Date'] = time.strftime("%Y-%m-%dT%H:%M:%S",
                                        time.gmtime(entry['time']))
            csv['Type'] = entry['category']
            if 'label' in entry:
                csv['Label'] = entry['label']
            else:
                csv['Label'] = u''
            csv['Address'] = entry['address']
            csv['Amount'] = entry['amount']
            csv['ID'] = entry['txid']
            state['wallet']['csv_data'].append(csv)

    state['wallet']['transactions'].sort(key=lambda entry: entry['nonce'],
                                         reverse=True)

    unit = g.coin_unit
    if 'testnet' in state:
        if state['testnet']:
            unit = g.coin_unit_test

    indent = "          "
    comment_split = " To: "
    comment_maxlen = (g.x - len(indent) - len(comment_split)) // 2
    for entry in state['wallet']['transactions']:
        if 'txid' in entry:
            entry_time = time.strftime("%Y-%m-%d %H:%M:%S",
                                       time.gmtime(entry['time']))
            output_string = entry_time + " %8d" % entry[
                'confirmations'] + " conf"
            delta = entry['amount']
            # keep track of spendings for later use in addresses view
            if delta < 0 and 'address' in entry:
                if str(entry['address']) in state['wallet']['spendings']:
                    state['wallet']['spendings'][str(
                        entry['address']
                    )] += delta  # TODO: check if fee has to be substracted here also!
                else:
                    state['wallet']['spendings'].update(
                        {str(entry['address']): delta})

            if 'fee' in entry:
                delta += entry[
                    'fee']  # this fails if not all inputs owned by wallet; could be 'too negative'
            output_string += "% 17.8f " % delta + unit
            output_string += " " + "% 17.8f" % entry[
                'cumulative_balance'] + " " + unit
            state['wallet']['view_string'].append(output_string)
            if delta < 0:
                state['wallet']['view_colorpair'].append(3)
            else:
                state['wallet']['view_colorpair'].append(1)

            is_watchonly = True if 'involvesWatchonly' in entry else False
            color = 2 if is_watchonly else 0
            output_string = entry['txid'].rjust(74)
            state['wallet']['view_string'].append(output_string)
            state['wallet']['view_colorpair'].append(color)

            if 'address' in entry:  # TODO: more sanity checking here
                output_string = indent + entry['category'].ljust(
                    15) + entry['address'].ljust(34)
            else:
                output_string = indent + "unknown transaction type"
            if is_watchonly:
                output_string += "(watchonly)".rjust(15)
            state['wallet']['view_string'].append(output_string)
            state['wallet']['view_colorpair'].append(color)

            if state['wallet']['verbose'] > 0:
                if 'comment' in entry and 'to' in entry:
                    output_string = indent + unidecode(
                        entry['comment'][:comment_maxlen].ljust(comment_maxlen)
                    ) + comment_split + unidecode(entry['to'][:comment_maxlen])
                    state['wallet']['view_string'].append(output_string)
                    state['wallet']['view_colorpair'].append(color)
                else:
                    state['wallet']['view_string'].append("")
                    state['wallet']['view_colorpair'].append(color)

            state['wallet']['view_string'].append("")
            state['wallet']['view_colorpair'].append(0)

    if state['mode'] == "wallet":
        wallet.draw_window(state, window, rpc_queue)
コード例 #22
0
ファイル: process.py プロジェクト: TheOnePerson/coind-ncurses
def listreceivedbyaddress(s, state, window, rpc_queue):
    state['wallet']['addresses'] = s['listreceivedbyaddress']
    state['wallet']['cursor'] = 0
    state['wallet']['offset'] = 0

    state['wallet']['addresses_view_string'] = []
    state['wallet']['addresses_view_colorpair'] = []
    state['wallet']['mode'] = 'addresses'

    state['wallet']['addresses'].sort(
        key=lambda entry: 999999
        if entry['confirmations'] == 0 else entry['confirmations'],
        reverse=False)

    unit = g.coin_unit
    if 'testnet' in state:
        if state['testnet']:
            unit = g.coin_unit_test

    for entry in state['wallet']['addresses']:
        if 'address' in entry:
            amount_in = entry['amount']
            # find spendings for address
            if 'spendings' in state['wallet']:
                if str(entry['address']) in state['wallet']['spendings']:
                    amount_out = -state['wallet']['spendings'][str(
                        entry['address'])]
                    amount = entry['amount'] + state['wallet']['spendings'][
                        str(entry['address'])]
                else:
                    amount_out = 0.0
                    amount = entry['amount']
            else:
                amount_out = 0.0
                amount = entry['amount']

            if amount > 0:
                color = 1
            elif amount < 0:
                color = 3
            else:
                color = 0
            if 'involvesWatchonly' in entry:
                color = 2
                output_string = entry['address'] + " (watchonly)" + str(
                    "% 17.8f " % amount + unit).rjust(27)
            else:
                output_string = entry['address'] + str("% 17.8f " % amount +
                                                       unit).rjust(39)
            state['wallet']['addresses_view_string'].append(output_string)
            state['wallet']['addresses_view_colorpair'].append(color)

            output_string = " " + str(str(entry['confirmations']) +
                                      " conf").ljust(15)
            output_string += str(str(len(entry['txids'])) + ' tx').rjust(10)
            output_string += str("(in:" + "% 1.8f" % amount_in + ", out:" +
                                 "% 1.8f" % amount_out + ")").rjust(44)
            state['wallet']['addresses_view_string'].append(output_string)
            state['wallet']['addresses_view_colorpair'].append(0)

            output_string = " " + unidecode(entry['account'].ljust(36))
            state['wallet']['addresses_view_string'].append(output_string)
            state['wallet']['addresses_view_colorpair'].append(0)

            state['wallet']['addresses_view_string'].append("")
            state['wallet']['addresses_view_colorpair'].append(0)

    if state['mode'] == "wallet":
        wallet.draw_window(state, window, rpc_queue)
コード例 #23
0
ファイル: hotkey.py プロジェクト: TheOnePerson/coind-ncurses
def key_s(state, window, rpc_queue):
    if state['mode'] == 'wallet':
        if 'wallet' in state:
            state['wallet']['mode'] = 'sendtoaddress'
            state['newtransaction'] = {}
            wallet.draw_window(state, window, rpc_queue)
コード例 #24
0
ファイル: hotkey.py プロジェクト: TheOnePerson/coind-ncurses
def key_x(state, window, rpc_queue):
    if state['mode'] == 'wallet':
        if 'wallet' in state:
            state['wallet']['mode'] = 'settxfee'
            wallet.draw_window(state, window, rpc_queue)
コード例 #25
0
ファイル: process.py プロジェクト: TheOnePerson/coind-ncurses
def listsinceblock(s, state, window, rpc_queue):
    state['wallet'] = s['listsinceblock']
    state['wallet']['cursor'] = 0
    state['wallet']['offset'] = 0

    state['wallet']['view_string'] = []
    state['wallet']['view_colorpair'] = []
    state['wallet']['spendings'] = {}
    state['wallet']['mode'] = 'tx'

    state['wallet']['transactions'].sort(key=lambda entry: entry['category'], reverse=True)

    # add cumulative balance field to transactions once ordered by time
    state['wallet']['transactions'].sort(key=lambda entry: entry['time'])
    state['wallet']['transactions'].sort(key=lambda entry: entry['confirmations'], reverse=True)
    cumulative_balance = 0
    nonce = 0 # ensures a definitive ordering of transactions for cumulative balance
    for entry in state['wallet']['transactions']:
        entry['nonce'] = nonce
        nonce += 1
        if 'amount' in entry:
            if 'fee' in entry:
                cumulative_balance += entry['fee']
            cumulative_balance += entry['amount']
            entry['cumulative_balance'] = cumulative_balance

    state['wallet']['transactions'].sort(key=lambda entry: entry['nonce'], reverse=True)

    unit = g.coin_unit
    if 'testnet' in state:
        if state['testnet']:
            unit = g.coin_unit_test

    for entry in state['wallet']['transactions']:
        if 'txid' in entry:
            entry_time = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(entry['time']))
            output_string = entry_time + " %8d" % entry['confirmations'] + " conf"
            delta = entry['amount']
            # keep track of spendings for later use in addresses view
            if delta < 0 and 'address' in entry:
                if str(entry['address']) in state['wallet']['spendings']:
                    state['wallet']['spendings'][str(entry['address'])] += delta      # TODO: check if fee has to be substracted here also!
                else:
                    state['wallet']['spendings'].update({str(entry['address']): delta})
                
            if 'fee' in entry:
                delta += entry['fee'] # this fails if not all inputs owned by wallet; could be 'too negative'
            output_string += "% 17.8f " % delta + unit
            output_string += " " + "% 17.8f" % entry['cumulative_balance'] + unit
            state['wallet']['view_string'].append(output_string)
            if delta < 0:
                state['wallet']['view_colorpair'].append(3)
            else:
                state['wallet']['view_colorpair'].append(1)

            output_string = entry['txid'].rjust(74)
            state['wallet']['view_string'].append(output_string)
            state['wallet']['view_colorpair'].append(0)

            if 'address' in entry: # TODO: more sanity checking here
                output_string = "          " + entry['category'].ljust(15) + entry['address']
            else:
                output_string = "          unknown transaction type"
            state['wallet']['view_string'].append(output_string)
            state['wallet']['view_colorpair'].append(0)

            state['wallet']['view_string'].append("")
            state['wallet']['view_colorpair'].append(0)

    if state['mode'] == "wallet":
        wallet.draw_window(state, window, rpc_queue)
コード例 #26
0
ファイル: hotkey.py プロジェクト: TheOnePerson/coind-ncurses
def key_r(state, window, rpc_queue):
    if state['mode'] == 'wallet':
        if 'wallet' in state:
            state['wallet']['mode'] = 'newaddress'
            wallet.draw_window(state, window, rpc_queue)
コード例 #27
0
ファイル: hotkey.py プロジェクト: TheOnePerson/coind-ncurses
def key_a(state, window, rpc_queue):
    if state['mode'] == 'wallet':
        state['wallet']['mode'] = 'addresses'
        s = {'listreceivedbyaddress': '0 true'}
        rpc_queue.put(s)
        wallet.draw_window(state, window, rpc_queue)