Beispiel #1
0
def iter_blockchain(last_hash=None):
    bc = BlockChain()

    if not last_hash:
        last_hash = bc.blocks.get("l")

    last_block = bc.blocks.get(last_hash).decode()

    print(last_block)
    if eval(last_block)["PrevBlockHash"]:
        return iter_blockchain(eval(last_block)["PrevBlockHash"])

    # ### the way to itertor.
    # for i in range(bc.get_height()):
    #     print(bc.iterator())

    print(next(bc.iterator()))
    print(next(bc.iterator()))
    print(next(bc.iterator()))
Beispiel #2
0
    # ### the way to itertor.
    # for i in range(bc.get_height()):
    #     print(bc.iterator())

    print(next(bc.iterator()))
    print(next(bc.iterator()))
    print(next(bc.iterator()))


if __name__ == '__main__':
    # test_create_bc()
    # s = iter_blockchain()
    bc = BlockChain()

    while True:
        try:
            last_block = next(bc.iterator())
        except StopIteration:
            genesis_hash = bc.blocks.get(bc.current_hash).decode()
            last_block = eval(genesis_hash)

            coinbase_tx = last_block["Transactions"]

            for tx in coinbase_tx:

                tx_str = tx.decode()
                print(json.loads(tx_str))
            break

        # for tx in last_block["Transactions"]:
        #     print(tx)