Skip to content

Instantly share code, notes, and snippets.

@harding
Created May 31, 2017 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harding/8162cba804634bfdd02f5b077afdf934 to your computer and use it in GitHub Desktop.
Save harding/8162cba804634bfdd02f5b077afdf934 to your computer and use it in GitHub Desktop.
Scan for transactions with combined output values over 10,000 BTC
from bitcoin import rpc
from bitcoin.core import x, lx, b2x, b2lx
#from multiprocessing.dummy import Pool
from multiprocessing import Pool
from retrying import retry
threshold = 10000e8 # satoshis
high_height = rpc.Proxy().getinfo()["blocks"]
low_height = 0 #high_height - 144 * 1
## A wrapper for RPC calls that will retry instead of failing.
## Because this will NEVER FAIL for any reason, you probably want
## to monitor the program's progress to ensure it's still scanning
## the blockchain.
@retry(wait_random_min=1, wait_random_max=20)
def get_block(hash):
return(rpc.Proxy().getblock(hash))
@retry(wait_random_min=1, wait_random_max=20)
def get_hash(block_height):
return(rpc.Proxy().getblockhash(block_height))
def scan(tx):
amount = 0
for vout in tx.vout:
amount += vout.nValue
if amount >= threshold:
return str(amount) + " " + str(b2lx(tx.GetHash()))
def scan_block(height):
block_hash = get_hash(height)
block = get_block(block_hash)
txes = block.vtx
return list(map(scan, txes))
heights = list(range(low_height, high_height))
## Change if you have more or less than 8 processor cores
pool = Pool(8)
results = pool.map(scan_block, heights)
pool.close()
pool.join()
for result in results:
for result2 in result:
if result2 != None:
print(result2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment