本文整理汇总了Python中storage.Storage.write_undo_info方法的典型用法代码示例。如果您正苦于以下问题:Python Storage.write_undo_info方法的具体用法?Python Storage.write_undo_info怎么用?Python Storage.write_undo_info使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类storage.Storage
的用法示例。
在下文中一共展示了Storage.write_undo_info方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BlockchainProcessor
# 需要导入模块: from storage import Storage [as 别名]
# 或者: from storage.Storage import write_undo_info [as 别名]
#.........这里部分代码省略.........
is_coinbase = False
return tx_hashes, txdict
def import_block(self, block, block_hash, block_height, sync, revert=False):
touched_addr = set([])
# deserialize transactions
tx_hashes, txdict = self.deserialize_block(block)
# undo info
if revert:
undo_info = self.storage.get_undo_info(block_height)
tx_hashes.reverse()
else:
undo_info = {}
for txid in tx_hashes: # must be ordered
tx = txdict[txid]
if not revert:
undo = self.storage.import_transaction(txid, tx, block_height, touched_addr)
undo_info[txid] = undo
else:
undo = undo_info.pop(txid)
self.storage.revert_transaction(txid, tx, block_height, touched_addr, undo)
if revert:
assert undo_info == {}
# add undo info
if not revert:
self.storage.write_undo_info(block_height, self.bitcoind_height, undo_info)
# add the max
self.storage.db_undo.put('height', repr( (block_hash, block_height, self.storage.db_version) ))
for addr in touched_addr:
self.invalidate_cache(addr)
self.storage.update_hashes()
def add_request(self, session, request):
# see if we can get if from cache. if not, add request to queue
message_id = request.get('id')
try:
result = self.process(request, cache_only=True)
except BaseException as e:
self.push_response(session, {'id': message_id, 'error': str(e)})
return
if result == -1:
self.queue.put((session, request))
else:
self.push_response(session, {'id': message_id, 'result': result})
def do_subscribe(self, method, params, session):
with self.watch_lock:
if method == 'blockchain.numblocks.subscribe':
if session not in self.watch_blocks:
self.watch_blocks.append(session)
elif method == 'blockchain.headers.subscribe':
示例2: BlockchainProcessor
# 需要导入模块: from storage import Storage [as 别名]
# 或者: from storage.Storage import write_undo_info [as 别名]
#.........这里部分代码省略.........
is_coinbase = False
return tx_hashes, txdict
def import_block(self, block, block_hash, block_height, revert=False):
touched_addr = set()
# deserialize transactions
tx_hashes, txdict = self.deserialize_block(block)
# undo info
if revert:
undo_info = self.storage.get_undo_info(block_height)
tx_hashes.reverse()
else:
undo_info = {}
for txid in tx_hashes: # must be ordered
tx = txdict[txid]
if not revert:
undo = self.storage.import_transaction(txid, tx, block_height, touched_addr)
undo_info[txid] = undo
else:
undo = undo_info.pop(txid)
self.storage.revert_transaction(txid, tx, block_height, touched_addr, undo)
if revert:
assert undo_info == {}
# add undo info
if not revert:
self.storage.write_undo_info(block_height, self.bitcoind_height, undo_info)
# add the max
self.storage.save_height(block_hash, block_height)
for addr in touched_addr:
self.invalidate_cache(addr)
self.storage.update_hashes()
# batch write modified nodes
self.storage.batch_write()
# return length for monitoring
return len(tx_hashes)
def add_request(self, session, request):
# see if we can get if from cache. if not, add request to queue
message_id = request.get('id')
try:
result = self.process(request, cache_only=True)
except BaseException as e:
self.push_response(session, {'id': message_id, 'error': str(e)})
return
if result == -1:
self.queue.put((session, request))
else:
self.push_response(session, {'id': message_id, 'result': result})
def do_subscribe(self, method, params, session):
with self.watch_lock:
if method == 'blockchain.numblocks.subscribe':
示例3: BlockchainProcessor
# 需要导入模块: from storage import Storage [as 别名]
# 或者: from storage.Storage import write_undo_info [as 别名]
#.........这里部分代码省略.........
tx_hashes.append(tx_hash)
txdict[tx_hash] = tx
is_coinbase = False
return tx_hashes, txdict
def import_block(self, block, block_hash, block_height, sync, revert=False):
touched_addr = set([])
# deserialize transactions
tx_hashes, txdict = self.deserialize_block(block)
# undo info
if revert:
undo_info = self.storage.get_undo_info(block_height)
tx_hashes.reverse()
else:
undo_info = {}
for txid in tx_hashes: # must be ordered
tx = txdict[txid]
if not revert:
undo = self.storage.import_transaction(txid, tx, block_height, touched_addr)
undo_info[txid] = undo
else:
undo = undo_info.pop(txid)
self.storage.revert_transaction(txid, tx, block_height, touched_addr, undo)
if revert:
assert undo_info == {}
# add undo info
if not revert:
self.storage.write_undo_info(block_height, self.bitcoind_height, undo_info)
# add the max
self.storage.db_undo.put("height", repr((block_hash, block_height, self.storage.db_version)))
for addr in touched_addr:
self.invalidate_cache(addr)
self.storage.update_hashes()
def add_request(self, session, request):
# see if we can get if from cache. if not, add to queue
if self.process(session, request, cache_only=True) == -1:
self.queue.put((session, request))
def do_subscribe(self, method, params, session):
with self.watch_lock:
if method == "blockchain.numblocks.subscribe":
if session not in self.watch_blocks:
self.watch_blocks.append(session)
elif method == "blockchain.headers.subscribe":
if session not in self.watch_headers:
self.watch_headers.append(session)
elif method == "blockchain.address.subscribe":
address = params[0]
l = self.watched_addresses.get(address)
if l is None:
self.watched_addresses[address] = [session]
elif session not in l:
l.append(session)