def broadcast_tx_with_chain(tx, bitcoin_chain): """ Broadcast the transaction through the configured set of providers :param tx: :param bitcoin_chain: :return: """ last_exception = None final_tx_id = None # Unlike other providers, we want to broadcast to all available apis for method_provider in service_provider_methods( 'broadcast_tx', get_providers_for_chain(bitcoin_chain)): try: tx_id = method_provider(tx) if tx_id: final_tx_id = tx_id except Exception as e: logging.warning( 'Caught exception trying provider %s. Trying another. Exception=%s', str(method_provider), e) last_exception = e if final_tx_id: return final_tx_id logging.error('Failed broadcasting through all providers') logging.error(last_exception, exc_info=True) raise last_exception
def spendables_for_address(self, bitcoin_address): for m in service_provider_methods('spendables_for_address', get_providers_for_chain(self.bitcoin_chain, self.bitcoind)): try: logging.debug('m=%s', m) spendables = m(bitcoin_address) return spendables except Exception as e: logging.warning(e) pass return []
def pay(from_address, to_address, amount, fee): last_exception = None for method_provider in service_provider_methods('pay', get_default_providers_for_netcode(CONFIG_NETCODE)): try: method_provider(from_address, to_address, amount, fee, CONFIG_NETCODE) return except Exception as e: logging.warning('Caught exception trying provider %s. Trying another. Exception=%s', str(method_provider), e) last_exception = e logging.error('Failed paying through all providers') raise last_exception
def pay(from_address, to_address, amount, fee): last_exception = None for method_provider in service_provider_methods( 'pay', get_default_providers_for_netcode(CONFIG_NETCODE)): try: method_provider(from_address, to_address, amount, fee, CONFIG_NETCODE) return except Exception as e: logging.warning( 'Caught exception trying provider %s. Trying another. Exception=%s', str(method_provider), e) last_exception = e logging.error('Failed paying through all providers') raise last_exception
def broadcast_tx_with_chain(tx, bitcoin_chain, bitcoind=False): """ Broadcast the transaction through the configured set of providers :param tx: :param bitcoin_chain: :return: """ last_exception = None final_tx_id = None # Unlike other providers, we want to broadcast to all available apis for attempt_number in range(0, MAX_BROADCAST_ATTEMPTS): for method_provider in service_provider_methods( 'broadcast_tx', get_providers_for_chain(bitcoin_chain, bitcoind)): try: tx_id = method_provider(tx) if tx_id: logging.info( 'Broadcasting succeeded with method_provider=%s, txid=%s', str(method_provider), tx_id) if final_tx_id and final_tx_id != tx_id: logging.error( 'This should never happen; fail and investigate if it does. Got conflicting tx_ids=%s and %s. Hextx=%s', final_tx_id, tx_id, tx.as_hex()) raise Exception('Got conflicting tx_ids.') final_tx_id = tx_id except Exception as e: logging.warning( 'Caught exception trying provider %s. Trying another. Exception=%s', str(method_provider), e) last_exception = e # At least 1 provider succeeded, so return if final_tx_id: return final_tx_id else: logging.warning( 'Broadcasting failed. Waiting before retrying. This is attempt number %d', attempt_number) time.sleep(BROADCAST_RETRY_INTERVAL) logging.error('Failed broadcasting through all providers') logging.error(last_exception, exc_info=True) raise BroadcastError(last_exception)
def broadcast_tx(tx, netcode=CONFIG_NETCODE): """ Broadcast the transaction through the configured set of providers :param tx: :param netcode: :return: """ last_exception = None for method_provider in service_provider_methods('broadcast_tx', get_default_providers_for_netcode(netcode)): try: tx_id = method_provider(tx) if tx_id: return tx_id except Exception as e: logging.warning('Caught exception trying provider %s. Trying another. Exception=%s', str(method_provider), e) last_exception = e logging.error('Failed broadcasting through all providers') raise last_exception
def broadcast_tx_with_chain(tx, bitcoin_chain, bitcoind=False): """ Broadcast the transaction through the configured set of providers :param tx: :param bitcoin_chain: :return: """ last_exception = None final_tx_id = None # Unlike other providers, we want to broadcast to all available apis for attempt_number in range(0, MAX_BROADCAST_ATTEMPTS): for method_provider in service_provider_methods('broadcast_tx', get_providers_for_chain(bitcoin_chain, bitcoind)): try: tx_id = method_provider(tx) if tx_id: logging.info('Broadcasting succeeded with method_provider=%s, txid=%s', str(method_provider), tx_id) if final_tx_id and final_tx_id != tx_id: logging.error( 'This should never happen; fail and investigate if it does. Got conflicting tx_ids=%s and %s. Hextx=%s', final_tx_id, tx_id, tx.as_hex()) raise Exception('Got conflicting tx_ids.') final_tx_id = tx_id except Exception as e: logging.warning('Caught exception trying provider %s. Trying another. Exception=%s', str(method_provider), e) last_exception = e # At least 1 provider succeeded, so return if final_tx_id: return final_tx_id else: logging.warning('Broadcasting failed. Waiting before retrying. This is attempt number %d', attempt_number) time.sleep(BROADCAST_RETRY_INTERVAL) logging.error('Failed broadcasting through all providers') logging.error(last_exception, exc_info=True) raise BroadcastError(last_exception)
def broadcast_tx(tx, netcode=CONFIG_NETCODE): """ Broadcast the transaction through the configured set of providers :param tx: :param netcode: :return: """ last_exception = None for method_provider in service_provider_methods( 'broadcast_tx', get_default_providers_for_netcode(netcode)): try: tx_id = method_provider(tx) if tx_id: return tx_id except Exception as e: logging.warning( 'Caught exception trying provider %s. Trying another. Exception=%s', str(method_provider), e) last_exception = e logging.error('Failed broadcasting through all providers') raise last_exception