예제 #1
0
 def _get_transaction(self, hash_bytes: bytes) -> BaseTransaction:
     if hash_bytes in self.transactions:
         tx = self._clone(self.transactions[hash_bytes])
         if hash_bytes in self.metadata:
             tx._metadata = self._clone(self.metadata[hash_bytes])
         return tx
     else:
         raise TransactionDoesNotExist(hash_bytes.hex())
예제 #2
0
    def _get_transaction(self, hash_bytes: bytes) -> 'BaseTransaction':
        tx = self.get_transaction_from_weakref(hash_bytes)
        if tx is not None:
            return tx

        tx = self._get_transaction_from_db(hash_bytes)
        if not tx:
            raise TransactionDoesNotExist(hash_bytes.hex())

        assert tx.hash == hash_bytes

        self._save_to_weakref(tx)
        return tx
예제 #3
0
    def _get_transaction(self, hash_bytes: bytes) -> 'BaseTransaction':
        tx = self.get_transaction_from_weakref(hash_bytes)
        if tx is not None:
            return tx

        filepath = self.generate_filepath(hash_bytes)
        data = self.load_from_json(filepath,
                                   TransactionDoesNotExist(hash_bytes.hex()))

        tx = self.load(data['tx'])
        if 'meta' in data.keys():
            meta = TransactionMetadata.create_from_json(data['meta'])
            tx._metadata = meta
        self._save_to_weakref(tx)
        return tx
예제 #4
0
    def get_all_transactions(self) -> Iterator['BaseTransaction']:
        tx: Optional['BaseTransaction']

        for tx in self.get_all_genesis():
            yield tx

        for f in glob.iglob(os.path.join(self.path, '*/*')):
            match = self.re_pattern.match(os.path.basename(f))
            if match:
                hash_bytes = bytes.fromhex(match.groups()[0])
                tx = self.get_transaction_from_weakref(hash_bytes)
                if tx is not None:
                    yield tx
                else:
                    # TODO Return a proxy that will load the transaction only when it is used.
                    data = self.load_from_json(f, TransactionDoesNotExist())
                    tx = self.load(data['tx'])
                    if 'meta' in data.keys():
                        meta = TransactionMetadata.create_from_json(
                            data['meta'])
                        tx._metadata = meta
                    self._save_to_weakref(tx)
                    yield tx