Last active
August 29, 2015 14:24
-
-
Save robby-d/4fd00cd52e53fd5f5857 to your computer and use it in GitHub Desktop.
bitcoind searchrawtransactions tester
This file contains hidden or 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
#!/usr/bin/env python3 | |
import requests, json | |
import time | |
rpcPort = 8332 | |
rpcUser = 'rpc' | |
rpcPassword = 'YOUR PASSWORD HERE' | |
serverURL = 'http://' + rpcUser + ':' + rpcPassword + '@localhost:' + str(rpcPort) | |
def call_rpc(method, params): | |
print("Calling %s with params: %s" % (method, params)) | |
headers = {'content-type': 'application/json'} | |
if not isinstance(params, list): params = [params,] | |
payload = json.dumps({"method": method, "params": params, "jsonrpc": "2.0"}) | |
response = requests.get(serverURL, headers=headers, data=payload) | |
print("RESPONSE: %s" % (response.text[:75] + '..') if len(response.text) > 75 else response.text) | |
def fetch_addresses(): | |
#get a list of addresses to mess with | |
response = requests.get("https://blockchain.info/unconfirmed-transactions?format=json") | |
addrs = [] | |
r = response.json() | |
for tx in r['txs']: | |
for out in tx['out']: | |
if 'addr' in out: | |
for addr in out['addr']: | |
addrs.append(out['addr']) | |
return list(set(addrs)) #uniqueify | |
#call searchrawtransactions on these sample addresses | |
while True: | |
call_rpc("getmempoolinfo", []) | |
for a in fetch_addresses(): | |
call_rpc("searchrawtransactions", a) | |
time.sleep(.5) | |
time.sleep(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment