pybit/Examples/Py2_ReadBlock.py
def read_trans(m, cursor,
               pr=True):
    """
    Read transaction header (just version) and inputs and outputs.

    Note here this function only returns cursor position and prints the other
    information. In the transaction class this information will be saved to
    the object.
    """
    tVersion = read_next(m, cursor, 4)
    if pr:
        print "  {0}-{1}: Version: {2}".format(cursor, cursor+4, tVersion)
    cursor += 4

    # Read number of inputs: varint (1-9 bytes)
    nInputs, steps = read_var(m, cursor)
    if pr:
        print "  {0}-{1}: nInputs: {2}".format(cursor, cursor+1, nInputs)
    cursor += steps

    # Read each input
    inputs = []
    for inp in range(nInputs):
        # Read the inputs (previous_outputs): 36 bytes each
        prevOutput = read_next(m, cursor, 36)
        if pr:
            print "    {0}-{1}: prevOutput: {2}".format(cursor,
                                                        cursor+36,
                                                        prevOutput)
        cursor += 36

        # Read the script length: 1 byte
        scriptLength = read_next(m, cursor, 1)
        if pr:
            print "    {0}-{1}: scriptLength: {2}".format(cursor,
                                                          cursor+1,
                                                          scriptLength)
        cursor += 1

        # Read the script sig: Variable
        scriptSig = read_next(m, cursor, int(scriptLength, 16))
        if pr:
            print "    {0}-{1}: scriptSig: {2}".format(cursor,
                                                       cursor+int(scriptLength,
                                                                  16),
                                                       scriptSig)
        cursor += int(scriptLength, 16)

        # Read sequence: 4 bytes
        sequence = read_next(m, cursor, 4)
        if pr:
            print "    {0}-{1}: sequence: {2}".format(cursor,
                                                      cursor+1,
                                                      sequence)
        cursor += 4

        # Compile input info
        txIn = {'n': inp,
                'prevOutput': prevOutput,
                'scriptLength': scriptLength,
                'scriptSig': scriptSig,
                'sequence': sequence}

        # Collect into list of inputs
        inputs.append(txIn)

    # Read number of outputs:  varint (1-9 bytes)
    nOutputs, steps = read_var(m, cursor)
    if pr:
        print "  {0}-{1}: nOutputs: {2}".format(cursor, cursor+1, nOutputs)
    cursor += steps

    outputs = []
    for oup in range(nOutputs):
        # Read value: 8 bytes
        value = read_next(m, cursor, 8)
        if pr:
            print "    {0}-{1}: output value: {2}".format(cursor,
                                                          cursor+8,
                                                          value)
        cursor += 8

        # pk script
        pkScriptLen = read_next(m, cursor, 1)
        if pr:
            print "    {0}-{1}: pkScriptLen: {2}".format(cursor,
                                                         cursor+1,
                                                         pkScriptLen)
        cursor += 1

        pkScript = read_next(m, cursor, int(pkScriptLen, 16))
        if pr:
            print "    {0}-{1}: pkScript: {2}".format(cursor,
                                                      cursor+int(pkScriptLen,
                                                                 16),
                                                      pkScript)
        cursor += int(pkScriptLen, 16)

        # Compile output info
        txOut = {'n': oup,
                 'value': value,
                 'pkScriptLen': pkScriptLen,
                 'pkScript ': pkScript}

        # Add to list of outputs
        outputs.append(txOut)

    # lock time: 4 bytes
    lockTime = read_next(m, cursor, 4)
    if pr:
        print "  {0}-{1}: lockTime: {2}".format(cursor, cursor+4, lockTime)
    cursor += 4

    return cursor

    Read transaction header (just version) and inputs and outputs.

    Note here this function only returns cursor position and prints the other
    information. In the transaction class this information will be saved to
    the object.
    
Read transaction header (just version) and inputs and outputs.
Note here this function only returns cursor position and prints the other
information. In the transaction class this information will be saved to
the object.
Read transaction header ( just version ) and inputs and outputs . Note here this function only returns cursor position and prints the other information . In the transaction class this information will be saved to the object .
def read_trans(m, cursor,
               pr=True):
    tVersion = read_next(m, cursor, 4)
    if pr:
        print "  {0}-{1}: Version: {2}".format(cursor, cursor+4, tVersion)
    cursor += 4
    nInputs, steps = read_var(m, cursor)
    if pr:
        print "  {0}-{1}: nInputs: {2}".format(cursor, cursor+1, nInputs)
    cursor += steps
    inputs = []
    for inp in range(nInputs):
        prevOutput = read_next(m, cursor, 36)
        if pr:
            print "    {0}-{1}: prevOutput: {2}".format(cursor,
                                                        cursor+36,
                                                        prevOutput)
        cursor += 36
        scriptLength = read_next(m, cursor, 1)
        if pr:
            print "    {0}-{1}: scriptLength: {2}".format(cursor,
                                                          cursor+1,
                                                          scriptLength)
        cursor += 1
        scriptSig = read_next(m, cursor, int(scriptLength, 16))
        if pr:
            print "    {0}-{1}: scriptSig: {2}".format(cursor,
                                                       cursor+int(scriptLength,
                                                                  16),
                                                       scriptSig)
        cursor += int(scriptLength, 16)
        sequence = read_next(m, cursor, 4)
        if pr:
            print "    {0}-{1}: sequence: {2}".format(cursor,
                                                      cursor+1,
                                                      sequence)
        cursor += 4
        txIn = {'n': inp,
                'prevOutput': prevOutput,
                'scriptLength': scriptLength,
                'scriptSig': scriptSig,
                'sequence': sequence}
        inputs.append(txIn)
    nOutputs, steps = read_var(m, cursor)
    if pr:
        print "  {0}-{1}: nOutputs: {2}".format(cursor, cursor+1, nOutputs)
    cursor += steps
    outputs = []
    for oup in range(nOutputs):
        value = read_next(m, cursor, 8)
        if pr:
            print "    {0}-{1}: output value: {2}".format(cursor,
                                                          cursor+8,
                                                          value)
        cursor += 8
        pkScriptLen = read_next(m, cursor, 1)
        if pr:
            print "    {0}-{1}: pkScriptLen: {2}".format(cursor,
                                                         cursor+1,
                                                         pkScriptLen)
        cursor += 1
        pkScript = read_next(m, cursor, int(pkScriptLen, 16))
        if pr:
            print "    {0}-{1}: pkScript: {2}".format(cursor,
                                                      cursor+int(pkScriptLen,
                                                                 16),
                                                      pkScript)
        cursor += int(pkScriptLen, 16)
        txOut = {'n': oup,
                 'value': value,
                 'pkScriptLen': pkScriptLen,
                 'pkScript ': pkScript}
        outputs.append(txOut)
    lockTime = read_next(m, cursor, 4)
    if pr:
        print "  {0}-{1}: lockTime: {2}".format(cursor, cursor+4, lockTime)
    cursor += 4
    return cursor
def read_trans ( m , cursor , pr = True ) : tVersion = read_next ( m , cursor , 4 ) if pr : print "  {0}-{1}: Version: {2}" . format ( cursor , cursor + 4 , tVersion ) cursor += 4 nInputs , steps = read_var ( m , cursor ) if pr : print "  {0}-{1}: nInputs: {2}" . format ( cursor , cursor + 1 , nInputs ) cursor += steps inputs = [ ] for inp in range ( nInputs ) : prevOutput = read_next ( m , cursor , 36 ) if pr : print "    {0}-{1}: prevOutput: {2}" . format ( cursor , cursor + 36 , prevOutput ) cursor += 36 scriptLength = read_next ( m , cursor , 1 ) if pr : print "    {0}-{1}: scriptLength: {2}" . format ( cursor , cursor + 1 , scriptLength ) cursor += 1 scriptSig = read_next ( m , cursor , int ( scriptLength , 16 ) ) if pr : print "    {0}-{1}: scriptSig: {2}" . format ( cursor , cursor + int ( scriptLength , 16 ) , scriptSig ) cursor += int ( scriptLength , 16 ) sequence = read_next ( m , cursor , 4 ) if pr : print "    {0}-{1}: sequence: {2}" . format ( cursor , cursor + 1 , sequence ) cursor += 4 txIn = { 'n' : inp , 'prevOutput' : prevOutput , 'scriptLength' : scriptLength , 'scriptSig' : scriptSig , 'sequence' : sequence } inputs . append ( txIn ) nOutputs , steps = read_var ( m , cursor ) if pr : print "  {0}-{1}: nOutputs: {2}" . format ( cursor , cursor + 1 , nOutputs ) cursor += steps outputs = [ ] for oup in range ( nOutputs ) : value = read_next ( m , cursor , 8 ) if pr : print "    {0}-{1}: output value: {2}" . format ( cursor , cursor + 8 , value ) cursor += 8 pkScriptLen = read_next ( m , cursor , 1 ) if pr : print "    {0}-{1}: pkScriptLen: {2}" . format ( cursor , cursor + 1 , pkScriptLen ) cursor += 1 pkScript = read_next ( m , cursor , int ( pkScriptLen , 16 ) ) if pr : print "    {0}-{1}: pkScript: {2}" . format ( cursor , cursor + int ( pkScriptLen , 16 ) , pkScript ) cursor += int ( pkScriptLen , 16 ) txOut = { 'n' : oup , 'value' : value , 'pkScriptLen' : pkScriptLen , 'pkScript ' : pkScript } outputs . append ( txOut ) lockTime = read_next ( m , cursor , 4 ) if pr : print "  {0}-{1}: lockTime: {2}" . format ( cursor , cursor + 4 , lockTime ) cursor += 4 return cursor
Read transaction header (just version) and inputs and outputs.
Read transaction header ( just version ) and inputs and outputs .
"""
    Read transaction header (just version) and inputs and outputs.

    Note here this function only returns cursor position and prints the other
    information. In the transaction class this information will be saved to
    the object.
    """ # Read number of inputs: varint (1-9 bytes) # Read each input # Read the inputs (previous_outputs): 36 bytes each # Read the script length: 1 byte # Read the script sig: Variable # Read sequence: 4 bytes # Compile input info # Collect into list of inputs # Read number of outputs:  varint (1-9 bytes) # Read value: 8 bytes # pk script # Compile output info # Add to list of outputs # lock time: 4 bytes
m
cursor
pr