Пример #1
0
def make_blocks(count,
                nonce_base=30000,
                previous_block_hash=HASH_INITIAL_BLOCK):
    blocks = []
    for i in range(count):
        s = i * nonce_base
        txs = [coinbase_tx(i + 1)] + [make_tx(i) for i in range(s, s + 8)]
        nonce = s
        while True:
            merkle_root = merkle([tx.hash() for tx in txs])
            block = Block(version=1,
                          previous_block_hash=previous_block_hash,
                          merkle_root=merkle_root,
                          timestamp=GENESIS_TIME + i * 600,
                          difficulty=i,
                          nonce=nonce)
            block.set_txs(txs)
            if block.hash()[-1] == i & 0xff:
                break
            nonce += 1
        blocks.append(block)
        previous_block_hash = block.hash()
    return blocks