<commit_before>#!/usr/bin/env python
import curses, time

import global_mod as g
import getstr

def draw_window(state, window):
    # TODO: add transaction locktime, add sequence to inputs
    window.clear()
    window.refresh()
    win_header = curses.newwin(3, 75, 0, 0)

    if 'tx' in state:
        color = curses.color_pair(1)
        if 'testnet' in state:
            if state['testnet']: color = curses.color_pair(2)
        win_header.addstr(0, 1, "bitcoind-ncurses " + g.version + " [transaction mode] (press 'G' to enter a txid)", color + curses.A_BOLD)
        win_header.addstr(1, 1, "txid: " + state['tx']['txid'], curses.A_BOLD)
        win_header.addstr(2, 1, str(state['tx']['size']) + " bytes (" + str(state['tx']['size']/1024) + " KB)       ", curses.A_BOLD)
        draw_inputs(state)
        draw_outputs(state)

    else:
        win_header.addstr(0, 1, "no transaction loaded", curses.A_BOLD)
        win_header.addstr(1, 1, "press 'G' to enter a txid", curses.A_BOLD)
        win_header.addstr(2, 1, "or 'M' to return to monitor window", curses.A_BOLD)

    win_header.refresh()

def draw_inputs(state):
    win_inputs = curses.newwin(9, 75, 3, 0)
    win_inputs.addstr(0, 1, "inputs (UP/DOWN: select, SPACE: view, V: verbose)", curses.A_BOLD)

    offset = state['tx']['offset']

    for index in xrange(offset, offset+7):
        if index < len(state['tx']['vin']):
            if 'txid' in state['tx']['vin'][index]:

                buffer_string = state['tx']['vin'][index]['txid'] + ":" + "%03d" % state['tx']['vin'][index]['vout']
                if 'prev_tx' in state['tx']['vin'][index]:
                        vout = state['tx']['vin'][index]['prev_tx']

                        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']
                            buffer_string += " " + state['tx']['vin'][index]['txid'][:5] + "...:" + "%03d" % state['tx']['vin'][index]['vout']

                if len(buffer_string) > 71:
                    buffer_string = buffer_string[0:68] + "..."

                if index == (state['tx']['cursor']):
                    win_inputs.addstr(index+1-offset, 1, ">", curses.A_REVERSE + curses.A_BOLD)

                if (index == offset+6) and (index+1 < len(state['tx']['vin'])):
                    win_inputs.addstr(index+1-offset, 3, "... ")
                elif (index == offset) and (index > 0):
                    win_inputs.addstr(index+1-offset, 3, "... ")
                else:
                    win_inputs.addstr(index+1-offset, 3, buffer_string)

            elif 'coinbase' in state['tx']['vin'][index]:
                win_inputs.addstr(index+1-offset, 3, "coinbase " + state['tx']['vin'][index]['coinbase'])<commit_msg>(tx view) Improve display of verbose mode<commit_after>#!/usr/bin/env python
import curses, time

import global_mod as g
import getstr

def draw_window(state, window):
    # TODO: add transaction locktime, add sequence to inputs
    window.clear()
    window.refresh()
    win_header = curses.newwin(3, 75, 0, 0)

    if 'tx' in state:
        color = curses.color_pair(1)
        if 'testnet' in state:
            if state['testnet']: color = curses.color_pair(2)
        win_header.addstr(0, 1, "bitcoind-ncurses " + g.version + " [transaction mode] (press 'G' to enter a txid)", color + curses.A_BOLD)
        win_header.addstr(1, 1, "txid: " + state['tx']['txid'], curses.A_BOLD)
        win_header.addstr(2, 1, str(state['tx']['size']) + " bytes (" + str(state['tx']['size']/1024) + " KB)       ", curses.A_BOLD)
        draw_inputs(state)
        draw_outputs(state)

    else:
        win_header.addstr(0, 1, "no transaction loaded", curses.A_BOLD)
        win_header.addstr(1, 1, "press 'G' to enter a txid", curses.A_BOLD)
        win_header.addstr(2, 1, "or 'M' to return to monitor window", curses.A_BOLD)

    win_header.refresh()

def draw_inputs(state):
    win_inputs = curses.newwin(9, 75, 3, 0)
    win_inputs.addstr(0, 1, "inputs (UP/DOWN: select, SPACE: view, V: verbose)", curses.A_BOLD)

    offset = state['tx']['offset']

    for index in xrange(offset, offset+7):
        if index < len(state['tx']['vin']):
            if 'txid' in state['tx']['vin'][index]:

                buffer_string = state['tx']['vin'][index]['txid'] + ":" + "%03d" % state['tx']['vin'][index]['vout']
                if 'prev_tx' in state['tx']['vin'][index]:
                        vout = state['tx']['vin'][index]['prev_tx']

                        if 'value' in vout:
                            if vout['scriptPubKey']['type'] == "pubkeyhash":
                                buffer_string = "% 14.8f" % vout['value'] + ": " + vout['scriptPubKey']['addresses'][0].ljust(34)
                            else:
                                if (vout['scriptPubKey']['asm']) > 34:
                                    buffer_string = "% 14.8f" % vout['value'] + ": ..." + vout['scriptPubKey']['asm'][-31:]
                                else:
                                    buffer_string = "% 14.8f" % vout['value'] + ": " + vout['scriptPubKey']['asm']
                            buffer_string += " " + state['tx']['vin'][index]['txid'][:8] + "[...]:" + "%03d" % state['tx']['vin'][index]['vout']

                if index == (state['tx']['cursor']):
                    win_inputs.addstr(index+1-offset, 1, ">", curses.A_REVERSE + curses.A_BOLD)

                if (index == offset+6) and (index+1 < len(state['tx']['vin'])):
                    win_inputs.addstr(index+1-offset, 3, "... ")
                elif (index == offset) and (index > 0):
                    win_inputs.addstr(index+1-offset, 3, "... ")
                else:
                    win_inputs.addstr(index+1-offset, 3, buffer_string)

            elif 'coinbase' in state['tx']['vin'][index]:
                win_inputs.addstr(index+1-offset, 3, "coinbase " + state['tx']['vin'][index]['coinbase'])
{'fraction_non_alphanumeric': 0.18258064516129033, 'fraction_numerical': 0.02032258064516129, 'mean_word_length': 2.186536485097636, 'pattern_counts': {'":': 9, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1572680', 'n_tokens_mistral': 2115, 'n_tokens_neox': 1997, 'n_words': 406}