コード例 #1
0
ファイル: tx.py プロジェクト: bitcoinsSG/moneywagon
 def _get_utxos(self, address, services, **modes):
     """
     Using the service fallback engine, get utxos from remote service.
     """
     return get_unspent_outputs(
         self.crypto, address, services=services,
         **modes
     )
コード例 #2
0
 def _get_utxos(self, address, services, **modes):
     """
     Using the service fallback engine, get utxos from remote service.
     """
     return get_unspent_outputs(self.crypto,
                                address,
                                services=services,
                                **modes)
コード例 #3
0
    def fast_reload(self, master_key):
        addresses = []
        for i in range(self.deposit_skip, self.deposit_skip + 10):
            addresses.append(self.derive_deposit_address(i, master_key))

        for i in range(self.change_skip, self.change_skip + 10):
            addresses.append(self.derive_change_address(i, master_key))

        utxos = get_unspent_outputs(crypto=self.code, addresses=addresses)

        self.save()
コード例 #4
0
ファイル: models.py プロジェクト: shackra/MultiExplorer
    def fast_reload(self, master_key):
        addresses = []
        for i in range(self.deposit_skip, self.deposit_skip + 10):
            addresses.append(self.derive_deposit_address(i, master_key))

        for i in range(self.change_skip, self.change_skip + 10):
            addresses.append(self.derive_change_address(i, master_key))

        utxos = get_unspent_outputs(crypto=self.code, addresses=addresses)

        self.save()
コード例 #5
0
def _make_moneywagon_fetch(Service,
                           service_mode,
                           service_id,
                           address,
                           addresses,
                           xpub,
                           currency,
                           currency_name,
                           block_args,
                           fiat=None,
                           txid=None,
                           random_mode=False,
                           **k):

    if Service:
        if Service.supported_cryptos and currency not in Service.supported_cryptos:
            raise Exception("%s not supported for %s with %s" %
                            (currency_name, service_mode, Service.name))
        services = [Service]
    else:
        services = []  # fallback mode

    modes = dict(report_services=True,
                 services=services,
                 random=random_mode,
                 timeout=10.0,
                 verbose=settings.DEBUG)

    if service_id.startswith("paranoid"):
        modes['paranoid'] = int(service_id[8:])
    elif service_id.startswith("average"):
        modes['average'] = int(service_id[7:])
    elif service_id.startswith("private"):
        modes['private'] = int(service_id[7:])
        if modes['private'] > 30:
            raise Exception("Private mode maximum of 30")

    if address:
        modes['address'] = address
    elif addresses:
        modes['addresses'] = addresses.split(',')

    if service_mode == 'current_price':
        used_services, price = get_current_price(currency, fiat, **modes)
        PriceTick.record_price(price, currency, fiat, used_services[0].name)
        ret = {'current_price': price}
    elif service_mode == 'address_balance':
        used_services, balance = get_address_balance(currency, **modes)
        ret = {'balance': balance}
    elif service_mode == 'unspent_outputs':
        used_services, utxos = get_unspent_outputs(currency, **modes)
        ret = {'utxos': sorted(utxos, key=lambda x: x['output'])}
    elif service_mode == 'historical_transactions':
        used_services, txs = get_historical_transactions(currency, **modes)
        ret = {'transactions': sorted(txs, key=lambda x: x['txid'])}
    elif service_mode == 'single_transaction':
        used_services = None
        tx = CachedTransaction.fetch_full_tx(currency, txid=txid, fiat=fiat)
        ret = {'transaction': tx}
    elif service_mode == 'get_block':
        if block_args['block_number']:
            block_args['block_number'] = int(block_args['block_number'])
        modes.update(block_args)
        used_services, block_data = get_block(currency, **modes)
        ret = {'block': block_data}
    elif service_mode == 'optimal_fee':
        used_services, fee = get_optimal_fee(currency, 1024, **modes)
        ret = {'optimal_fee_per_KiB': fee}
    else:
        raise Exception("Unsupported Service mode")

    if not used_services:
        pass  # private mode does not return services
    elif len(used_services) == 1:
        s = used_services[0]
        if s:
            ret['url'] = s.last_url
            ret['raw_response'] = s.last_raw_response.json()
            ret['service_name'] = s.name
            ret['service_id'] = s.service_id
    else:
        ret['services'] = [{
            'name': s.name,
            'id': s.service_id,
            'raw_response': s.last_raw_response.json()
        } for s in used_services]

    return ret
コード例 #6
0
ファイル: views.py プロジェクト: priestc/MultiExplorer
def _make_moneywagon_fetch(Service, service_mode, service_id, address, addresses,
    xpub, currency, currency_name, block_args, fiat=None, txid=None, random_mode=False, **k):

    if Service:
        if Service.supported_cryptos and currency not in Service.supported_cryptos:
            raise Exception("%s not supported for %s with %s" % (
                currency_name, service_mode, Service.name
            ))
        services = [Service]
    else:
        services = [] # fallback mode

    modes = dict(
        report_services=True,
        services=services,
        random=random_mode,
        timeout=10.0,
        verbose=settings.DEBUG
    )

    if service_id.startswith("paranoid"):
        modes['paranoid'] = int(service_id[8:])
    elif service_id.startswith("average"):
        modes['average'] = int(service_id[7:])
    elif service_id.startswith("private"):
        modes['private'] = int(service_id[7:])
        if modes['private'] > 30:
            raise Exception("Private mode maximum of 30")

    if address:
        modes['address'] = address
    elif addresses:
        modes['addresses'] = addresses.split(',')

    if service_mode == 'current_price':
        used_services, price = get_current_price(currency, fiat, **modes)
        PriceTick.record_price(price, currency, fiat, used_services[0].name)
        ret = {'current_price': price}
    elif service_mode == 'address_balance':
        used_services, balance = get_address_balance(currency, **modes)
        ret = {'balance': balance}
    elif service_mode == 'unspent_outputs':
        used_services, utxos = get_unspent_outputs(currency, **modes)
        ret = {'utxos': sorted(utxos, key=lambda x: x['output'])}
    elif service_mode == 'historical_transactions':
        used_services, txs = get_historical_transactions(currency, **modes)
        ret = {'transactions': sorted(txs, key=lambda x: x['txid'])}
    elif service_mode == 'single_transaction':
        used_services = None
        tx = CachedTransaction.fetch_full_tx(currency, txid=txid, fiat=fiat)
        ret = {'transaction': tx}
    elif service_mode == 'get_block':
        if block_args['block_number']:
            block_args['block_number'] = int(block_args['block_number'])
        modes.update(block_args)
        used_services, block_data = get_block(currency, **modes)
        ret = {'block': block_data}
    elif service_mode == 'optimal_fee':
        used_services, fee = get_optimal_fee(currency, 1024, **modes)
        ret = {'optimal_fee_per_KiB': fee}
    else:
        raise Exception("Unsupported Service mode")

    if not used_services:
        pass # private mode does not return services
    elif len(used_services) == 1:
        s = used_services[0]
        if s:
            ret['url'] = s.last_url
            ret['raw_response'] = s.last_raw_response.json()
            ret['service_name'] = s.name
            ret['service_id'] = s.service_id
    else:
        ret['services'] = [
            {'name': s.name, 'id': s.service_id, 'raw_response': s.last_raw_response.json()}
            for s in used_services
        ]

    return ret