Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/blockstore.py
Show First 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | def headers_for(self, locator, hash_stop, current_tip=None): | ||||
index = hashList.index(hash_stop) + 1 | index = hashList.index(hash_stop) + 1 | ||||
response.headers = headersList[:index] | response.headers = headersList[:index] | ||||
return response | return response | ||||
def add_block(self, block): | def add_block(self, block): | ||||
block.calc_sha256() | block.calc_sha256() | ||||
try: | try: | ||||
self.blockDB[repr(block.sha256)] = bytes(block.serialize()) | self.blockDB[repr(block.sha256)] = bytes(block.serialize()) | ||||
except TypeError as e: | except TypeError: | ||||
logger.exception("Unexpected error") | logger.exception("Unexpected error") | ||||
self.currentBlock = block.sha256 | self.currentBlock = block.sha256 | ||||
self.headers_map[block.sha256] = CBlockHeader(block) | self.headers_map[block.sha256] = CBlockHeader(block) | ||||
def add_header(self, header): | def add_header(self, header): | ||||
self.headers_map[header.sha256] = header | self.headers_map[header.sha256] = header | ||||
# lookup the hashes in "inv", and return p2p messages for delivering | # lookup the hashes in "inv", and return p2p messages for delivering | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | def get(self, txhash): | ||||
except KeyError: | except KeyError: | ||||
return None | return None | ||||
return value | return value | ||||
def add_transaction(self, tx): | def add_transaction(self, tx): | ||||
tx.calc_sha256() | tx.calc_sha256() | ||||
try: | try: | ||||
self.txDB[repr(tx.sha256)] = bytes(tx.serialize()) | self.txDB[repr(tx.sha256)] = bytes(tx.serialize()) | ||||
except TypeError as e: | except TypeError: | ||||
logger.exception("Unexpected error") | logger.exception("Unexpected error") | ||||
def get_transactions(self, inv): | def get_transactions(self, inv): | ||||
responses = [] | responses = [] | ||||
for i in inv: | for i in inv: | ||||
if (i.type == 1): # MSG_TX | if (i.type == 1): # MSG_TX | ||||
tx = self.get(i.hash) | tx = self.get(i.hash) | ||||
if tx is not None: | if tx is not None: | ||||
responses.append(msg_generic(b"tx", tx)) | responses.append(msg_generic(b"tx", tx)) | ||||
return responses | return responses |