Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/mininode.py
| Show First 20 Lines • Show All 522 Lines • ▼ Show 20 Lines | def get_merkle_root(self, hashes): | ||||
| while len(hashes) > 1: | while len(hashes) > 1: | ||||
| newhashes = [] | newhashes = [] | ||||
| for i in range(0, len(hashes), 2): | for i in range(0, len(hashes), 2): | ||||
| i2 = min(i + 1, len(hashes) - 1) | i2 = min(i + 1, len(hashes) - 1) | ||||
| newhashes.append(hash256(hashes[i] + hashes[i2])) | newhashes.append(hash256(hashes[i] + hashes[i2])) | ||||
| hashes = newhashes | hashes = newhashes | ||||
| return uint256_from_str(hashes[0]) | return uint256_from_str(hashes[0]) | ||||
| # Finds a prefixed commitment in the coinbase outputs | |||||
| def get_coinbase_commitment(self, prefix): | |||||
| for txo in self.vtx[0].vout: | |||||
| r = txo.scriptPubKey | |||||
| if len(r) == 38 and r[0:6] == prefix: | |||||
| h = r[6:] | |||||
| return h[::-1] | |||||
| return None | |||||
| def calc_merkle_root(self): | def calc_merkle_root(self): | ||||
| hashes = [] | hashes = [] | ||||
| for tx in self.vtx: | for tx in self.vtx: | ||||
| tx.calc_sha256() | tx.calc_sha256() | ||||
| hashes.append(ser_uint256(tx.sha256)) | hashes.append(ser_uint256(tx.sha256)) | ||||
| return self.get_merkle_root(hashes) | return self.get_merkle_root(hashes) | ||||
| def is_valid(self): | def is_valid(self): | ||||
| ▲ Show 20 Lines • Show All 1,224 Lines • Show Last 20 Lines | |||||