Skip to content

Instantly share code, notes, and snippets.

@robby-d
Last active August 29, 2015 14:24

Revisions

  1. Robby Dermody revised this gist Jul 13, 2015. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions test_bitcoind.py
    Original file line number Diff line number Diff line change
    @@ -22,8 +22,9 @@ def fetch_addresses():
    r = response.json()
    for tx in r['txs']:
    for out in tx['out']:
    for addr in out['addr']:
    addrs.append(out['addr'])
    if 'addr' in out:
    for addr in out['addr']:
    addrs.append(out['addr'])
    return list(set(addrs)) #uniqueify

    #call searchrawtransactions on these sample addresses
  2. Robby Dermody created this gist Jul 13, 2015.
    35 changes: 35 additions & 0 deletions test_bitcoind.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    #!/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']:
    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)