diff --git a/api/blockchain_utils.py b/api/blockchain_utils.py index 2d6f3ab88..5c133d6bd 100644 --- a/api/blockchain_utils.py +++ b/api/blockchain_utils.py @@ -5,6 +5,24 @@ from config import BTAPIKEY from rpcclient import gettxout from cacher import * +import config + +if config.TESTNET: + # neither blockchain.info nor blockonomics support testnet + BLOCKCHAININFO_API_URL = "https://blockchain.info" + BLOCKONOMICS_API_URL = "https://www.blockonomics.co/api" + + BLOCKR_API_URL = "http://tbtc.blockr.io/api/v1" + BLOCKTRAIL_API_URL = "https://api.blocktrail.com/v1/tbtc" + BLOCKCYPHER_API_URL = "https://api.blockcypher.com/v1/btc/test3" + BITGO_API_URL = "https://test.bitgo.com/api/v1" +else: + BLOCKCHAININFO_API_URL = "https://blockchain.info" + BLOCKR_API_URL = "http://btc.blockr.io/api/v1" + BLOCKTRAIL_API_URL = "https://api.blocktrail.com/v1/btc" + BLOCKCYPHER_API_URL = "https://api.blockcypher.com/v1/btc/main" + BITGO_API_URL = "https://www.bitgo.com/api/v1" + BLOCKONOMICS_API_URL = "https://www.blockonomics.co/api" try: expTime=config.BTCBAL_CACHE @@ -15,7 +33,7 @@ def bc_getutxo(address, ramount, page=1, retval=None, avail=0): if retval==None: retval=[] try: - r = requests.get('https://api.blocktrail.com/v1/btc/address/'+address+'/unspent-outputs?api_key='+str(BTAPIKEY)+'&limit=200&page='+str(page)) + r = requests.get(BLOCKTRAIL_API_URL + '/address/'+address+'/unspent-outputs?api_key='+str(BTAPIKEY)+'&limit=200&page='+str(page)) if r.status_code == 200: response = r.json() unspents = response['data'] @@ -40,7 +58,7 @@ def bc_getutxo(address, ramount, page=1, retval=None, avail=0): def bc_getutxo_blockcypher(address, ramount): try: - r = requests.get('https://api.blockcypher.com/v1/btc/main/addrs/'+address+'?unspentOnly=true') + r = requests.get(BLOCKCYPHER_API_URL + '/addrs/'+address+'?unspentOnly=true') if r.status_code == 200: unspents = r.json()['txrefs'] @@ -65,7 +83,7 @@ def bc_getutxo_blockcypher(address, ramount): def bc_getutxo_blockr(address, ramount): try: - r = requests.get('http://btc.blockr.io/api/v1/address/unspent/'+address+'?unconfirmed=1') + r = requests.get(BLOCKR_API_URL + '/address/unspent/'+address+'?unconfirmed=1') if r.status_code == 200: #Process and format response from blockr.io @@ -92,8 +110,12 @@ def bc_getutxo_blockr(address, ramount): def bc_getpubkey(address): + # note: only supports mainnet try: - r = requests.get('https://blockchain.info/q/pubkeyaddr/'+address) + if config.TESTNET: + return "error: tried using blockchain.info api with testnet enabled" + + r = requests.get(BLOCKCHAININFO_API_URL + '/q/pubkeyaddr/'+address) if r.status_code == 200: return str(r.text) @@ -117,7 +139,7 @@ def bc_getbalance(address): def bc_getbalance_bitgo(address): try: - r= requests.get('https://www.bitgo.com/api/v1/address/'+address) + r= requests.get(BITGO_API_URL + '/address/'+address) if r.status_code == 200: balance = int(r.json()['balance']) return {"bal":balance , "error": None} @@ -128,7 +150,7 @@ def bc_getbalance_bitgo(address): def bc_getbalance_blockcypher(address): try: - r= requests.get('https://api.blockcypher.com/v1/btc/main/addrs/'+address+'/balance') + r= requests.get(BLOCKCYPHER_API_URL + '/addrs/'+address+'/balance') if r.status_code == 200: balance = int(r.json()['balance']) return {"bal":balance , "error": None} @@ -139,7 +161,7 @@ def bc_getbalance_blockcypher(address): def bc_getbalance_blockr(address): try: - r= requests.get('http://btc.blockr.io/api/v1/address/balance/'+address) + r= requests.get(BLOCKR_API_URL + '/address/balance/'+address) if r.status_code == 200: balance = int(r.json()['data']['balance']*1e8) return {"bal":balance , "error": None} @@ -222,7 +244,10 @@ def bc_getbulkbalance_blockonomics(addresses): formatted=formatted+" "+address try: - r = requests.post('https://www.blockonomics.co/api/balance',json.dumps({"addr":formatted})) + if config.TESTNET: + return "error: tried using blockonomics api with testnet enabled" + + r = requests.post(BLOCKONOMICS_API_URL + '/balance',json.dumps({"addr":formatted})) if r.status_code == 200: balances = r.json()['response'] retval = {} @@ -243,7 +268,7 @@ def bc_getbulkbalance_blockr(addresses): formatted=formatted+","+address try: - r= requests.get('http://btc.blockr.io/api/v1/address/balance/'+formatted) + r= requests.get(BLOCKR_API_URL + '/address/balance/'+formatted) if r.status_code == 200: balances = r.json()['data'] retval = {} @@ -263,7 +288,10 @@ def bc_getbulkbalance_blockchain(addresses): else: formatted=formatted+"|"+address try: - r= requests.get('https://blockchain.info/balance?active='+formatted) + if config.TESTNET: + return "error: tried using blockchain.info api with testnet enabled" + + r= requests.get(BLOCKCHAININFO_API_URL + '/balance?active='+formatted) if r.status_code == 200: balances = r.json() retval = {} diff --git a/api/config.py.example b/api/config.py.example index bfe04cdcd..0b0c02ab4 100644 --- a/api/config.py.example +++ b/api/config.py.example @@ -34,6 +34,9 @@ REDIS_DB=0 #Use if you want custom address namespace (multiple servers on same box) #Must prefix custom name with : example ":stage" REDIS_ADDRSPACE="" + #How long, in seconds, to cache BTC balance info for new addresses, Default 10min (600) BTCBAL_CACHE=600 + +TESTNET = False diff --git a/api/rpcclient.py b/api/rpcclient.py index 5ff6f2cce..7d8d99eac 100644 --- a/api/rpcclient.py +++ b/api/rpcclient.py @@ -1,5 +1,6 @@ import requests, getpass import time, json +import config class RPCHost(): def __init__(self): @@ -7,7 +8,7 @@ def __init__(self): self._session = requests.Session() try: with open('/home/'+USER+'/.bitcoin/bitcoin.conf') as fp: - RPCPORT="8332" + RPCPORT= "8332" RPCHOST="localhost" RPCSSL=False for line in fp: diff --git a/api/send.py b/api/send.py index 3340071ec..7b5b5dd88 100644 --- a/api/send.py +++ b/api/send.py @@ -7,6 +7,7 @@ from blockchain_utils import * from msc_apps import * import random +import traceback def send_form_response(response_dict): expected_fields=['from_address', 'to_address', 'amount', 'currency', 'fee'] @@ -18,7 +19,7 @@ def send_form_response(response_dict): if len(response_dict[field]) != 1: info('Multiple values for field '+field) return (None, 'Multiple values for field '+field) - + if 'testnet' in response_dict and ( response_dict['testnet'][0] in ['true', 'True'] ): testnet =True magicbyte = 111 @@ -32,8 +33,6 @@ def send_form_response(response_dict): else: response_status='invalid pubkey' pubkey=None - - print response_dict from_addr=response_dict['from_address'][0] if not is_valid_bitcoin_address_or_pubkey(from_addr): @@ -103,6 +102,7 @@ def send_form_response(response_dict): return (response, None) except Exception as e: print "error creating unsigned tx", e + traceback.print_exc() return (None, str(e)) diff --git a/www/assets/img/icons/close.svg b/www/assets/img/icons/close.svg new file mode 100644 index 000000000..3d67832ce --- /dev/null +++ b/www/assets/img/icons/close.svg @@ -0,0 +1,27 @@ + + + + Slice 1 + Created with Sketch. + + + + + + + + + + + + + + + + + + x + + + + \ No newline at end of file diff --git a/www/assets/img/icons/up.svg b/www/assets/img/icons/up.svg new file mode 100644 index 000000000..7ebc6c7c9 --- /dev/null +++ b/www/assets/img/icons/up.svg @@ -0,0 +1,20 @@ + + + + up 4.28.27 PM + Created with Sketch. + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/www/index.html b/www/index.html index 22ca128b6..58232a3de 100644 --- a/www/index.html +++ b/www/index.html @@ -64,6 +64,9 @@ + + + @@ -93,6 +96,7 @@ + @@ -114,6 +118,7 @@ +