Skip to content

Commit

Permalink
add blockr support
Browse files Browse the repository at this point in the history
  • Loading branch information
JahPowerBit committed Nov 11, 2014
1 parent 3c4e78a commit 7db1c1c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 26 deletions.
27 changes: 27 additions & 0 deletions lib/blockchain/blockr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'''
blockr.io
'''
import logging

from lib import config, util

def get_host():
if config.BLOCKCHAIN_SERVICE_CONNECT:
return config.BLOCKCHAIN_SERVICE_CONNECT
else:
return 'http://tbtc.blockr.io' if config.TESTNET else 'http://btc.blockr.io'

def check():
pass

def searchrawtransactions(address):
unconfirmed = util.unconfirmed_transactions(address)

confirmed = []
txs = util.get_url(get_host() + '/api/v1/address/txs/{}'.format(address), abort_on_error=True)
if 'status' in txs and txs['status'] == 'success':
for tx in txs['data']['txs']:
tx = util.rpc('getrawtransaction', [tx['tx'], 1])
confirmed.append(tx)

return unconfirmed + confirmed
27 changes: 1 addition & 26 deletions lib/blockchain/jmcorgan.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,6 @@ def check():
return True

def searchrawtransactions(address):
unconfirmed = search_mempool_transactions(address)
unconfirmed = util.unconfirmed_transactions(address)
confirmed = util.rpc('searchrawtransactions', [address, 1, 0, 9999999])
return unconfirmed + confirmed

def extract_addresses(tx):
addresses = []

for vout in tx['vout']:
if 'addresses' in vout['scriptPubKey']:
addresses += vout['scriptPubKey']['addresses']

for vin in tx['vin']:
vin_tx = util.rpc('getrawtransaction', [vin['txid'], 1])
vout = vin_tx['vout'][vin['vout']]
if 'addresses' in vout['scriptPubKey']:
addresses += vout['scriptPubKey']['addresses']

return addresses

def search_mempool_transactions(address):
transactions = []

for tx_hash in util.rpc('getrawmempool', []):
tx = util.rpc('getrawtransaction', [tx_hash, 1])
if address in extract_addresses(tx):
transactions.append(tx)

return transactions
27 changes: 27 additions & 0 deletions lib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -990,4 +990,31 @@ def asset_names_v2(block_index):
return True
return False

### Unconfirmed Transactions ###

def extract_addresses(tx):
addresses = []

for vout in tx['vout']:
if 'addresses' in vout['scriptPubKey']:
addresses += vout['scriptPubKey']['addresses']

for vin in tx['vin']:
vin_tx = rpc('getrawtransaction', [vin['txid'], 1])
vout = vin_tx['vout'][vin['vout']]
if 'addresses' in vout['scriptPubKey']:
addresses += vout['scriptPubKey']['addresses']

return addresses

def unconfirmed_transactions(address):
transactions = []

for tx_hash in rpc('getrawmempool', []):
tx = rpc('getrawtransaction', [tx_hash, 1])
if address in extract_addresses(tx):
transactions.append(tx)

return transactions

# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

0 comments on commit 7db1c1c

Please sign in to comment.