def make_blocks(count, nonce_base=30000, previous_block_hash=b'\0' * 32): blocks = [] for i in range(count): s = i * nonce_base txs = [COINBASE_TX] # + [make_tx(i) for i in range(s, s+8)] nonce = s while True: block = Block(version=1, previous_block_hash=previous_block_hash, merkle_root=b'\0'*32, timestamp=1390000000+i*600, difficulty=i, nonce=nonce, txs=txs) if block.hash()[-1] == i & 0xff: break nonce += 1 blocks.append(block) previous_block_hash = block.hash() return blocks
def make_blocks(count, nonce_base=30000, previous_block_hash=b'\0' * 32): blocks = [] for i in range(count): s = i * nonce_base txs = [COINBASE_TX] # + [make_tx(i) for i in range(s, s+8)] nonce = s while True: block = Block(version=1, previous_block_hash=previous_block_hash, merkle_root=b'\0' * 32, timestamp=1390000000 + i * 600, difficulty=i, nonce=nonce, txs=txs) if block.hash()[-1] == i & 0xff: break nonce += 1 blocks.append(block) previous_block_hash = block.hash() return blocks
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
def get_blockheader_with_transaction_hashes(self, block_hash): URL = "%s/block/%s" % (self.base_url, b2h_rev(block_hash)) r = json.loads(urlopen(URL).read().decode("utf8")) version = r.get("version") previous_block_hash = h2b_rev(r.get("previousblockhash")) merkle_root = h2b_rev(r.get("merkleroot")) timestamp = r.get("time") difficulty = int(r.get("bits"), 16) nonce = int(r.get("nonce")) tx_hashes = [h2b_rev(tx_hash) for tx_hash in r.get("tx")] blockheader = Block(version, previous_block_hash, merkle_root, timestamp, difficulty, nonce) if blockheader.hash() != block_hash: return None, None calculated_hash = merkle(tx_hashes, double_sha256) if calculated_hash != merkle_root: return None, None blockheader.height = r.get("height") return blockheader, tx_hashes
def get_blockheader_with_transaction_hashes(self, block_hash): URL = "%s%sblock/%s" % (self.base_url, self.base_path, b2h_rev(block_hash)) r = json.loads(urlopen(URL).read().decode("utf8")) version = r.get("version") previous_block_hash = h2b_rev(r.get("previousblockhash")) merkle_root = h2b_rev(r.get("merkleroot")) timestamp = r.get("time") difficulty = int(r.get("bits"), 16) nonce = int(r.get("nonce")) tx_hashes = [h2b_rev(tx_hash) for tx_hash in r.get("tx")] blockheader = Block(version, previous_block_hash, merkle_root, timestamp, difficulty, nonce) if blockheader.hash() != block_hash: return None, None calculated_hash = merkle(tx_hashes, double_sha256) if calculated_hash != merkle_root: return None, None blockheader.height = r.get("height") return blockheader, tx_hashes