def getaddressinfo(address): infos = util.get_url(get_host() + '/api/v1/address/info/{}'.format(address), abort_on_error=True) if 'status' in infos and infos['status'] == 'success': txs = util.get_url(get_host() + '/api/v1/address/txs/{}'.format(address), abort_on_error=True) if 'status' in txs and txs['status'] == 'success': transactions = [] for tx in txs['data']['txs']: transactions.append(tx['tx']) return { 'addrStr': address, 'balance': infos['data']['balance'], 'balanceSat': infos['data']['balance'] * config.UNIT, 'totalReceived': infos['data']['totalreceived'], 'totalReceivedSat': infos['data']['totalreceived'] * config.UNIT, 'unconfirmedBalance': 0, 'unconfirmedBalanceSat': 0, 'unconfirmedTxApperances': 0, 'txApperances': txs['data']['nb_txs'], 'transactions': transactions } return None
def searchrawtransactions(proxy, address): result = util.get_url(get_host() + '/api/txs/?address=' + address, abort_on_error=False) if 'txs' in result: return result['txs'] else: return []
def gettransaction(tx_hash): url = get_host() + '/api/v1/tx/raw/{}'.format(tx_hash) tx = util.get_url(url, abort_on_error=False) assert tx and tx.get('status') and tx.get('code') if tx['code'] == 404: return None elif tx['code'] != 200: raise Exception("Invalid result (code %s), body: %s" % (tx['code'], tx)) if 'status' in tx and tx['status'] == 'success': valueOut = 0 for vout in tx['data']['tx']['vout']: valueOut += vout['value'] return { 'txid': tx_hash, 'version': tx['data']['tx']['version'], 'locktime': tx['data']['tx']['locktime'], 'blockhash': tx['data']['tx'].get('blockhash', None), #will be None if not confirmed yet... 'confirmations': tx['data']['tx'].get('confirmations', None), 'time': tx['data']['tx'].get('time', None), 'blocktime': tx['data']['tx'].get('blocktime', None), 'valueOut': valueOut, 'vin': tx['data']['tx']['vin'], 'vout': tx['data']['tx']['vout'] } return None
def gettransaction(tx_hash): url = get_host() + '/api/transaction/{}'.format(tx_hash) tx = util.get_url(url, abort_on_error=False) #assert tx and tx.get('status') and tx.get('code') #if tx['code'] == 404: # return None #elif tx['code'] != 200: # raise Exception("Invalid result (code %s), body: %s" % (tx['code'], tx)) if 'Hash' in tx: valueOut = 0 for vout in tx['Outputs']['Index']: valueOut += vout['Amount'] return { 'txid': tx_hash, 'version': 0, 'locktime': 0, 'blockhash': tx['Block'], #will be None if not confirmed yet... 'confirmations': 0, 'time': tx['Time'], 'blocktime': tx['Time'], 'valueOut': valueOut, 'vin': 0, 'vout': 0 } return None
def getinfo(): result = util.get_url(get_host() + '/api/v1/coin/info', abort_on_error=True) if 'status' in result and result['status'] == 'success': return {"info": {"blocks": result['data']['last_block']['nb']}} return None
def gettransaction(tx_hash): # tx = util.get_url(get_host() + '/api/v1/tx/raw/{}'.format(tx_hash), abort_on_error=True) # # Handle missing transactions properly url = get_host() + '/api/v1/tx/raw/{}'.format(tx_hash) tx = util.get_url(url, abort_on_error=False) if tx and tx.get('code') == 404: return None if 'status' in tx and tx['status'] == 'success': valueOut = 0 for vout in tx['data']['tx']['vout']: valueOut += vout['value'] return { 'txid': tx_hash, 'version': tx['data']['tx']['version'], 'locktime': tx['data']['tx']['locktime'], 'blockhash': tx['data']['tx'].get('blockhash', None), #will be None if not confirmed yet... 'confirmations': tx['data']['tx'].get('confirmations', None), 'time': tx['data']['tx'].get('time', None), 'blocktime': tx['data']['tx'].get('blocktime', None), 'valueOut': valueOut, 'vin': tx['data']['tx']['vin'], 'vout': tx['data']['tx']['vout'] } return None
def check(): result = util.get_url(get_host() + '/api/sync/', abort_on_error=True) if not result: raise Exception('Insight reports error: %s' % result['error']) if result['status'] == 'error': raise Exception('Insight reports error: %s' % result['error']) if result['status'] == 'syncing': logging.warning("WARNING: Insight is not fully synced to the blockchain: %s%% complete" % result['syncPercentage'])
def getinfo(): result = util.get_url(get_host() + '/api/v2/get_info/{}'.format(sochain_network()), abort_on_error=True) if 'status' in result and result['status'] == 'success': return {"info": {"blocks": result['data']['blocks']}} else: return None
def getinfo(): result = util.get_url(get_host() + '/api/coindetails', abort_on_error=True) if 'TotalCoins' in result: return { "info": { "blocks": result['Blocks'] } } return None
def getinfo(): result = util.get_url(get_host() + '/api/v1/coin/info', abort_on_error=True) if 'status' in result and result['status'] == 'success': return { "info": { "blocks": result['data']['last_block']['nb'] } } return None
def getinfo(): result = util.get_url(get_host() + '/api/v2/get_info/{}'.format(sochain_network()), abort_on_error=True) if 'status' in result and result['status'] == 'success': return { "info": { "blocks": result['data']['blocks'] } } else: return None
def searchrawtransactions(proxy, address): unconfirmed = backend.unconfirmed_transactions(proxy, address) confirmed = [] txs = util.get_url(get_host() + '/api/v2/get_tx/{}/{}'.format(sochain_network(), address), abort_on_error=True) if 'status' in txs and txs['status'] == 'success': for tx in txs['data']['txs']: tx = backend.old_rpc('getrawtransaction', [tx['txid'], 1]) confirmed.append(tx) return unconfirmed + confirmed
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
def searchrawtransactions(address): unconfirmed = util.unconfirmed_transactions(address) confirmed = [] txs = util.get_url(get_host() + '/api/v2/get_tx/{}/{}'.format(sochain_network(), address), abort_on_error=True) if 'status' in txs and txs['status'] == 'success': for tx in txs['data']['txs']: tx = backend.old_rpc('getrawtransaction', [tx['txid'], 1]) confirmed.append(tx) return unconfirmed + confirmed
def listunspent(address): result = util.get_url(get_host() + '/api/v2/get_tx_unspent/{}/{}'.format(sochain_network(), address), abort_on_error=True) if 'status' in result and result['status'] == 'success': utxo = [] for txo in result['data']['txs']: newtxo = { 'address': address, 'txid': txo['txid'], 'vout': txo['output_no'], 'ts': txo['time'], 'scriptPubKey': txo['script_hex'], 'amount': float(txo['value']), 'confirmations': txo['confirmations'], 'confirmationsFromCache': False } utxo.append(newtxo) return utxo else: return None
def listunspent(address): result = util.get_url(get_host() + '/api/address/{}'.format(address), abort_on_error=True) if 'status' in result and result['status'] == 'success': utxo = [] for txo in result['data']['unspent']: newtxo = { 'address': address, 'txid': txo['tx'], 'vout': txo['n'], 'ts': 0, 'scriptPubKey': txo['script'], 'amount': float(txo['amount']), 'confirmations': txo['confirmations'], 'confirmationsFromCache': False } utxo.append(newtxo) return utxo return None
def listunspent(address): result = util.get_url(get_host() + '/api/v1/address/unspent/{}/'.format(address), abort_on_error=True) if 'status' in result and result['status'] == 'success': utxo = [] for txo in result['data']['unspent']: newtxo = { 'address': address, 'txid': txo['tx'], 'vout': txo['n'], 'ts': 0, 'scriptPubKey': txo['script'], 'amount': float(txo['amount']), 'confirmations': txo['confirmations'], 'confirmationsFromCache': False } utxo.append(newtxo) return utxo return None
def getaddressinfo(address): infos = util.get_url(get_host() + '/api/v2/address/{}/{}'.format(sochain_network(), address), abort_on_error=True) if 'status' in infos and infos['status'] == 'success': transactions = [] for tx in infos['data']['txs']: transactions.append(tx['txid']) return { 'addrStr': address, 'balance': float(infos['data']['balance']), 'balanceSat': float(infos['data']['balance']) * config.UNIT, 'totalReceived': float(infos['data']['received_value']), 'totalReceivedSat': float(infos['data']['received_value']) * config.UNIT, 'unconfirmedBalance': 0, 'unconfirmedBalanceSat': 0, 'unconfirmedTxApperances': 0, 'txApperances': infos['data']['total_txs'], 'transactions': transactions } return None
def gettransaction(tx_hash): tx = util.get_url(get_host() + '/api/v2/get_tx/{}/{}'.format(sochain_network(), address), abort_on_error=True) if 'status' in tx and tx['status'] == 'success': valueOut = 0 for vout in tx['data']['tx']['vout']: valueOut += float(vout['value']) return { 'txid': tx_hash, 'version': tx['data']['tx']['version'], 'locktime': tx['data']['tx']['locktime'], 'blockhash': tx['data']['tx']['blockhash'], 'confirmations': tx['data']['tx']['confirmations'], 'time': tx['data']['tx']['time'], 'blocktime': tx['data']['tx']['blocktime'], 'valueOut': valueOut, 'vin': tx['data']['tx']['vin'], 'vout': tx['data']['tx']['vout'] } return None
def gettransaction(tx_hash): tx = util.get_url(get_host() + '/api/v1/tx/raw/{}'.format(tx_hash), abort_on_error=True) if 'status' in tx and tx['status'] == 'success': valueOut = 0 for vout in tx['data']['tx']['vout']: valueOut += vout['value'] return { 'txid': tx_hash, 'version': tx['data']['tx']['version'], 'locktime': tx['data']['tx']['locktime'], 'blockhash': tx['data']['tx'].get('blockhash', None), #will be None if not confirmed yet... 'confirmations': tx['data']['tx'].get('confirmations', None), 'time': tx['data']['tx'].get('time', None), 'blocktime': tx['data']['tx'].get('blocktime', None), 'valueOut': valueOut, 'vin': tx['data']['tx']['vin'], 'vout': tx['data']['tx']['vout'] } return None
def getinfo(): return util.get_url(get_host() + '/api/status?q=getInfo', abort_on_error=True)
def gettransaction(tx_hash): return util.get_url(get_host() + '/api/tx/' + tx_hash + '/', abort_on_error=False)
def listunspent(address): return util.get_url(get_host() + '/api/addr/' + address + '/utxo/', abort_on_error=True)
def getaddressinfo(address): return util.get_url(get_host() + '/api/addr/' + address + '/', abort_on_error=True)