pybit/Examples/Py2_ReadBlock.py
def read_header(m, cursor,
                pr=True):
    """
    Read:
        - Block header:
            - Magic number
            - Block size
            - Version
            - Previous hash
            - Merkle root hash
            - Timestamp
            - Size
            - Nonce
        - Number of transactions in the bock

    Note here this function only returns cursor position and the number of
    transactions to read with read_trans. The rest of the information is just
    printed.
    In the Block class this information will be saved to the object.
    """
    if pr:
        print cursor

    # Read magic number: 4 bytes
    magic = read_next(m, cursor, 4)
    cursor += 4
    if pr:
        print 'magic: ' + magic

    # Read block size: 4 bytes
    blockSize = read_next(m, cursor, 4, rev=True)
    blockSize = int(blockSize, 16)
    cursor += 4
    if pr:
        print 'block_size: ' + str(blockSize)

    # Read version: 4 bytes
    version = read_next(m, cursor, 4)
    cursor += 4
    if pr:
        print 'version: ' + version

    # Read the previous hash: 32 bytes
    prevHash = read_next(m, cursor, 32, rev=True)
    cursor += 32
    if pr:
        print 'prevHash: ' + prevHash

    # Read the merkle root: 32 bytes
    merkleRootHash = read_next(m, cursor, 32)
    cursor += 32
    if pr:
        print 'merkle_root: ' + merkleRootHash

    # Read the time stamp: 32 bytes
    timestamp = read_next(m, cursor, 4, rev=True)
    cursor += 4
    if pr:
        print 'timestamp: ' + timestamp
        print 'times: ' + str(dt.fromtimestamp(int(timestamp, 16)))

    # Read the size: 4 bytes
    nBits = read_next(m, cursor, 4)
    cursor += 4
    if pr:
        print 'nBits: ' + nBits

    # Read the nonce: 4 bytes
    nonce = read_next(m, cursor, 4)
    cursor += 4
    if pr:
        print 'nonce: ' + nonce

    # Read the number of transactions: varint (1-9 bytes)
    nTransactions, steps = read_var(m, cursor)
    cursor += steps
    if pr:
        print 'n transactions: ' + str(nTransactions)

    if pr:
        print cursor

    return cursor, nTransactions

    Read:
        - Block header:
            - Magic number
            - Block size
            - Version
            - Previous hash
            - Merkle root hash
            - Timestamp
            - Size
            - Nonce
        - Number of transactions in the bock

    Note here this function only returns cursor position and the number of
    transactions to read with read_trans. The rest of the information is just
    printed.
    In the Block class this information will be saved to the object.
    
Block header:
Magic number
Block size
Version
Previous hash
Merkle root hash
Timestamp
Size
Nonce
Number of transactions in the bock

Note here this function only returns cursor position and the number of
transactions to read with read_trans. The rest of the information is just
printed.
In the Block class this information will be saved to the object.
Block header : Magic number Block size Version Previous hash Merkle root hash Timestamp Size Nonce Number of transactions in the bock Note here this function only returns cursor position and the number of transactions to read with read_trans . The rest of the information is just printed . In the Block class this information will be saved to the object .
def read_header(m, cursor,
                pr=True):
    if pr:
        print cursor
    magic = read_next(m, cursor, 4)
    cursor += 4
    if pr:
        print 'magic: ' + magic
    blockSize = read_next(m, cursor, 4, rev=True)
    blockSize = int(blockSize, 16)
    cursor += 4
    if pr:
        print 'block_size: ' + str(blockSize)
    version = read_next(m, cursor, 4)
    cursor += 4
    if pr:
        print 'version: ' + version
    prevHash = read_next(m, cursor, 32, rev=True)
    cursor += 32
    if pr:
        print 'prevHash: ' + prevHash
    merkleRootHash = read_next(m, cursor, 32)
    cursor += 32
    if pr:
        print 'merkle_root: ' + merkleRootHash
    timestamp = read_next(m, cursor, 4, rev=True)
    cursor += 4
    if pr:
        print 'timestamp: ' + timestamp
        print 'times: ' + str(dt.fromtimestamp(int(timestamp, 16)))
    nBits = read_next(m, cursor, 4)
    cursor += 4
    if pr:
        print 'nBits: ' + nBits
    nonce = read_next(m, cursor, 4)
    cursor += 4
    if pr:
        print 'nonce: ' + nonce
    nTransactions, steps = read_var(m, cursor)
    cursor += steps
    if pr:
        print 'n transactions: ' + str(nTransactions)
    if pr:
        print cursor
    return cursor, nTransactions
def read_header ( m , cursor , pr = True ) : if pr : print cursor magic = read_next ( m , cursor , 4 ) cursor += 4 if pr : print 'magic: ' + magic blockSize = read_next ( m , cursor , 4 , rev = True ) blockSize = int ( blockSize , 16 ) cursor += 4 if pr : print 'block_size: ' + str ( blockSize ) version = read_next ( m , cursor , 4 ) cursor += 4 if pr : print 'version: ' + version prevHash = read_next ( m , cursor , 32 , rev = True ) cursor += 32 if pr : print 'prevHash: ' + prevHash merkleRootHash = read_next ( m , cursor , 32 ) cursor += 32 if pr : print 'merkle_root: ' + merkleRootHash timestamp = read_next ( m , cursor , 4 , rev = True ) cursor += 4 if pr : print 'timestamp: ' + timestamp print 'times: ' + str ( dt . fromtimestamp ( int ( timestamp , 16 ) ) ) nBits = read_next ( m , cursor , 4 ) cursor += 4 if pr : print 'nBits: ' + nBits nonce = read_next ( m , cursor , 4 ) cursor += 4 if pr : print 'nonce: ' + nonce nTransactions , steps = read_var ( m , cursor ) cursor += steps if pr : print 'n transactions: ' + str ( nTransactions ) if pr : print cursor return cursor , nTransactions
Read:
 Block header:
 Magic number
 Block size
 Version
 Previous hash
 Merkle root hash
 Timestamp
 Size
 Nonce
 Number of transactions in the bock
Read : Block header : Magic number Block size Version Previous hash Merkle root hash Timestamp Size Nonce Number of transactions in the bock
"""
    Read:
        - Block header:
            - Magic number
            - Block size
            - Version
            - Previous hash
            - Merkle root hash
            - Timestamp
            - Size
            - Nonce
        - Number of transactions in the bock

    Note here this function only returns cursor position and the number of
    transactions to read with read_trans. The rest of the information is just
    printed.
    In the Block class this information will be saved to the object.
    """ # Read magic number: 4 bytes # Read block size: 4 bytes # Read version: 4 bytes # Read the previous hash: 32 bytes # Read the merkle root: 32 bytes # Read the time stamp: 32 bytes # Read the size: 4 bytes # Read the nonce: 4 bytes # Read the number of transactions: varint (1-9 bytes)
m
cursor
pr