Esempio n. 1
0
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
Esempio n. 2
0
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 []
Esempio n. 3
0
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
Esempio n. 4
0
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
Esempio n. 5
0
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
Esempio n. 6
0
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
Esempio n. 7
0
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
Esempio n. 8
0
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
Esempio n. 9
0
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'])
Esempio n. 10
0
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'])
Esempio n. 11
0
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
Esempio n. 12
0
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
Esempio n. 13
0
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
Esempio n. 14
0
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
Esempio n. 15
0
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
Esempio n. 16
0
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
Esempio n. 17
0
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
Esempio n. 18
0
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
Esempio n. 19
0
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
Esempio n. 20
0
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
Esempio n. 21
0
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
Esempio n. 22
0
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
Esempio n. 23
0
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
Esempio n. 24
0
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
Esempio n. 25
0
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
Esempio n. 26
0
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
Esempio n. 27
0
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
Esempio n. 28
0
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
Esempio n. 29
0
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 []
Esempio n. 30
0
def getinfo():
    return util.get_url(get_host() + '/api/status?q=getInfo',
                        abort_on_error=True)
Esempio n. 31
0
def gettransaction(tx_hash):
    return util.get_url(get_host() + '/api/tx/' + tx_hash + '/', abort_on_error=False)
Esempio n. 32
0
def listunspent(address):
    return util.get_url(get_host() + '/api/addr/' + address + '/utxo/',
                        abort_on_error=True)
Esempio n. 33
0
def getaddressinfo(address):
    return util.get_url(get_host() + '/api/addr/' + address + '/', abort_on_error=True)
Esempio n. 34
0
def listunspent(address):
    return util.get_url(get_host() + '/api/addr/' + address + '/utxo/', abort_on_error=True)
Esempio n. 35
0
def getinfo():
    return util.get_url(get_host() + '/api/status?q=getInfo', abort_on_error=True)
Esempio n. 36
0
def getaddressinfo(address):
    return util.get_url(get_host() + '/api/addr/' + address + '/',
                        abort_on_error=True)
Esempio n. 37
0
def gettransaction(tx_hash):
    return util.get_url(get_host() + '/api/tx/' + tx_hash + '/',
                        abort_on_error=False)