<commit_before>import simplejson
import requests
import decimal
import json, re
from config import BTAPIKEY
from rpcclient import gettxout
from cacher import *

try:
  expTime=config.BTCBAL_CACHE
except:
  expTime=600


def bc_getutxo(address, ramount, page=1, retval=None, avail=0):
  if retval==None:
    retval=[]
  try:
    r = requests.get('https://chain.api.btc.com/v3/address/'+address+'/unspent?pagesize=50&page='+str(page))
    if r.status_code == 200:
      response = r.json()['data']
      unspents = response['list']
      print "got unspent list (btc)", response
      for tx in unspents:
        txUsed=gettxout(tx['tx_hash'],tx['tx_output_n'])['result']
        isUsed = txUsed==None
        coinbaseHold = (txUsed['coinbase'] and txUsed['confirmations'] < 100)
        multisigSkip = ("scriptPubKey" in txUsed and txUsed['scriptPubKey']['type'] == "multisig")
        if not isUsed and not coinbaseHold and txUsed['confirmations'] > 0 and not multisigSkip:
          avail += tx['value']
          retval.append([ tx['tx_hash'], tx['tx_output_n'], tx['value'] ])
          if avail >= ramount:
            return {"avail": avail, "utxos": retval, "error": "none"}
      if int(response['total_count'])-(int(response['pagesize'])*page ) > 0:
        return bc_getutxo(address, ramount, page+1, retval, avail)
      return {"avail": avail, "error": "Low balance error"}
    else:
      return bc_getutxo_blockcypher(address, ramount)
  except:<commit_msg>add blockchaincom for utxo source<commit_after>import simplejson
import requests
import decimal
import json, re
from config import BTAPIKEY
from rpcclient import gettxout
from cacher import *

try:
  expTime=config.BTCBAL_CACHE
except:
  expTime=600


def bc_getutxo(address, ramount):
  try:
    r = requests.get('https://blockchain.info/unspent?active='+address)
    if r.status_code == 200:
      avail=0
      retval=[]
      response = r.json()
      unspents = response['unspent_outputs']
      print "got unspent list (blockchain)", response
      for tx in sorted(unspents, key = lambda i: i['value'],reverse=True):
        txUsed=gettxout(tx['tx_hash_big_endian'],tx['tx_output_n'])['result']
        isUsed = txUsed==None
        if not isUsed:
          coinbaseHold = (txUsed['coinbase'] and txUsed['confirmations'] < 100)
          multisigSkip = ("scriptPubKey" in txUsed and txUsed['scriptPubKey']['type'] == "multisig")
          if not coinbaseHold and txUsed['confirmations'] > 0 and not multisigSkip:
            avail += tx['value']
            retval.append([ tx['tx_hash_big_endian'], tx['tx_output_n'], tx['value'] ])
            if avail >= ramount:
              return {"avail": avail, "utxos": retval, "error": "none"}
      if ('notice' in response and 'Ignoring' in response['notice']):
        return bc_getutxo_btccom(address, ramount)
      else:
        return {"avail": avail, "error": "Low balance error"}
    else:
      return bc_getutxo_btccom(address, ramount)
  except:
    return bc_getutxo_btccom(address, ramount)


def bc_getutxo_btccom(address, ramount, page=1, retval=None, avail=0):
  if retval==None:
    retval=[]
  try:
    r = requests.get('https://chain.api.btc.com/v3/address/'+address+'/unspent?pagesize=50&page='+str(page))
    if r.status_code == 200:
      response = r.json()['data']
      unspents = response['list']
      print "got unspent list (btc)", response
      for tx in unspents:
        txUsed=gettxout(tx['tx_hash'],tx['tx_output_n'])['result']
        isUsed = txUsed==None
        coinbaseHold = (txUsed['coinbase'] and txUsed['confirmations'] < 100)
        multisigSkip = ("scriptPubKey" in txUsed and txUsed['scriptPubKey']['type'] == "multisig")
        if not isUsed and not coinbaseHold and txUsed['confirmations'] > 0 and not multisigSkip:
          avail += tx['value']
          retval.append([ tx['tx_hash'], tx['tx_output_n'], tx['value'] ])
          if avail >= ramount:
            return {"avail": avail, "utxos": retval, "error": "none"}
      if int(response['total_count'])-(int(response['pagesize'])*page ) > 0:
        return bc_getutxo(address, ramount, page+1, retval, avail)
      return {"avail": avail, "error": "Low balance error"}
    else:
      return bc_getutxo_blockcypher(address, ramount)
  except:
{'fraction_non_alphanumeric': 0.14389330837622835, 'fraction_numerical': 0.009826860084230228, 'mean_word_length': 3.5575692963752665, 'pattern_counts': {'":': 15, '<': 6, '<?xml version=': 0, '>': 11, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1644560', 'n_tokens_mistral': 1460, 'n_tokens_neox': 1412, 'n_words': 336}