-
-
Save robby-d/bbd01adddd010442fb4b 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
#!/usr/bin/env python3 | |
import requests, json | |
import time | |
rpcPort = 8332 | |
rpcUser = 'rpc' | |
rpcPassword = 'YOUR PASSWORD HERE' | |
serverURL = 'http://' + rpcUser + ':' + rpcPassword + '@localhost:' + str(rpcPort) | |
print ("Timestamp,Milliseconds") | |
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"}) | |
start_time = int(round(time.time() * 1000)) | |
response = requests.get(serverURL, headers=headers, data=payload) | |
request_time = int(round(time.time() * 1000)) - start_time | |
# print("time: {}ms, address: {}, response: {}".format(request_time, params, (response.text[:75].rstrip() + '...') if len(response.text) > 75 else response.text.rstrip())) | |
print("{},{}".format(int(round(time.time() * 1000)), request_time)) | |
def fetch_addresses(): | |
addrs = [] | |
#get a list of addresses in the mempool to use | |
response = requests.get("https://blockchain.info/unconfirmed-transactions?format=json") | |
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']) | |
#get a list of addresses with committed CP txes to use | |
response = requests.get("http://xcp.blockscan.com/api2?module=transaction&action=list&page=1&count=25") | |
r = response.json() | |
for tx in r['data']: | |
addrs.append(tx['source']) | |
addrs.append(tx['destination']) | |
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(.25) | |
time.sleep(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment