Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/blockstore.py
Show First 20 Lines • Show All 139 Lines • ▼ Show 20 Lines | class TxStore(): | ||||
def get(self, txhash): | def get(self, txhash): | ||||
value = None | value = None | ||||
try: | try: | ||||
value = self.txDB[repr(txhash)] | value = self.txDB[repr(txhash)] | ||||
except KeyError: | except KeyError: | ||||
return None | return None | ||||
return value | return value | ||||
def get_transaction(self, txhash): | |||||
ret = None | |||||
serialized_tx = self.get(txhash) | |||||
if serialized_tx is not None: | |||||
f = BytesIO(serialized_tx) | |||||
ret = CTransaction() | |||||
ret.deserialize(f) | |||||
ret.calc_sha256() | |||||
return ret | |||||
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 as e: | ||||
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 |