-
-
Save deweller/b823eb3f76f84071b761 to your computer and use it in GitHub Desktop.
Test bitcoind searchrawtransactions. Suitable for logging. Use python3 -u test_bitcoind.py > timing.csv
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(): | |
#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(.25) | |
time.sleep(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment