Skip to content

Instantly share code, notes, and snippets.

@killerstorm
Created November 1, 2013 03:15
Show Gist options
  • Save killerstorm/7260528 to your computer and use it in GitHub Desktop.
Save killerstorm/7260528 to your computer and use it in GitHub Desktop.
tx_queue = [genesis_tx]
for cur_block_height in xrange(genesis_height, max_height):
# remove txs from this block from the queue
block_tx_queue = [tx for tx in tx_queue if tx.block_height == cur_block_height]
tx_queue = [tx for tx in tx_queue if tx.block_height != cur_block_height]
block_txs = {}
while block_tx_queue:
tx = block_tx_queue.pop()
block_txs[tx.txhash] = tx
spends = get_spends(tx)
for stx in spends:
if stx.block_height == cur_block_height:
block_tx_queue.append(stx)
else:
tx_queue.append(stx)
def dependent(tx):
"""all transactions from current block this transaction directly depends on"""
dep_tx = []
for inp in tx.inputs:
if inp.outpoint.hash in block_txs:
dep_tx.append(block_txs[inp.outpoint.hash])
return dep_tx
sorted_block_txs = toposorted(block_txs.values(), dependent)
for tx in sorted_block_txs:
scan_tx(tx)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment