def flush_cache(self): if self.block_cache: self.blocks.insert_many([BlockSerializer.to_database(block) for block in self.block_cache.values()]) if self.tr_cache: self.transactions.insert_many([TransactionSerializer.to_database(tr) for tr in self.tr_cache.values()]) self.block_cache = {} self.tr_cache = {}
def setUp(self): self.db.blocks.insert_many( [BlockSerializer.to_database(block) for block in self.blocks]) self.db.transactions.insert_many([ TransactionSerializer.to_database(tr) for tr in self.transactions ]) self.db_gateway = MongoDatabaseGateway(database=self.db, config=self.config)
def put_transaction(self, tr): if self.cache: self.tr_cache[tr.txid] = (TransactionSerializer.to_database(tr)) for vin in tr.vin: self.vin_cache.append(VinSerializer.to_database(vin, tr.txid)) for (index, vout) in enumerate(tr.vout): self.vout_cache += VoutSerializer.to_database( vout, tr.txid, index) else: vins = [] vouts = [] for vin in tr.vin: vins.append(VinSerializer.to_database(vin, tr.txid)) for vout in tr.vout: vouts += VoutSerializer.to_database(vout, tr.txid, tr.index) self.transactions.insert_one(TransactionSerializer.to_database(tr)) self.vin.insert_many(vins) self.vout.insert_many(vouts)
def setUp(self): self.db.blocks.insert_many( [BlockSerializer.to_database(block) for block in self.blocks]) self.db.transactions.insert_many([ TransactionSerializer.to_database(tr) for tr in self.transactions ]) for tr in self.transactions: self.db.vin.insert_many( [VinSerializer.to_database(vin, tr.txid) for vin in tr.vin]) list_of_lists = [ VoutSerializer.to_database(vout, tr.txid, index) for (index, vout) in enumerate(tr.vout) ] self.db.vout.insert_many( [item for sublist in list_of_lists for item in sublist]) self.db_gateway = MongoDatabaseGateway(database=self.db, cache=True, cache_size=5)