Created
November 1, 2013 03:15
-
-
Save killerstorm/7260528 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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