def test_thread_provider(self): p_list_1 = providers.providers_for_config_string( "blockchain.info", "BTC") p_list_2 = providers.providers_for_config_string( "blockexplorer.com", "BTC") providers.set_default_providers_for_netcode("BTC", p_list_1) self.assertEqual(providers.get_default_providers_for_netcode("BTC"), p_list_1) # use a dictionary so it can be mutable in the subthread d = {"is_ok": False} def subthread(): providers.set_default_providers_for_netcode("BTC", []) self.assertEqual( providers.get_default_providers_for_netcode("BTC"), []) providers.set_default_providers_for_netcode("BTC", p_list_2) self.assertEqual( providers.get_default_providers_for_netcode("BTC"), p_list_2) d["is_ok"] = True t = threading.Thread(target=subthread) t.start() t.join() self.assertTrue(d["is_ok"]) self.assertEqual(providers.get_default_providers_for_netcode("BTC"), p_list_1)
def init_connectors(conf): """ Initialize broadcasting and payment connectors. This allows fallback and confirmation across different chains :param conf: :return: """ # configure mainnet providers provider_list = providers.providers_for_config_string(PYCOIN_BTC_PROVIDERS, 'BTC') blockio_index = -1 for idx, val in enumerate(provider_list): print(idx, val) if isinstance(val, BlockrioProvider): blockio_index = idx if blockio_index > -1: provider_list[blockio_index] = BlockrBroadcaster('BTC') else: provider_list.append(BlockrBroadcaster('BTC')) provider_list.append(InsightBroadcaster('https://insight.bitpay.com/', 'BTC')) # initialize payment connectors based on config file if conf.wallet_connector_type == 'blockchain.info': provider_list.append(LocalBlockchainInfoConnector(conf)) else: provider_list.append(BitcoindConnector('BTC')) providers.set_default_providers_for_netcode('BTC', provider_list) # initialize testnet providers testnet_list = [] testnet_list.append(BitcoindConnector('XTN')) providers.set_default_providers_for_netcode('XTN', testnet_list)
def test_thread_provider(self): p_list_1 = providers.providers_for_config_string("blockchain.info", "BTC") p_list_2 = providers.providers_for_config_string("blockexplorer.com", "BTC") providers.set_default_providers_for_netcode("BTC", p_list_1) self.assertEqual(providers.get_default_providers_for_netcode("BTC"), p_list_1) # use a dictionary so it can be mutable in the subthread l = {"is_ok": False} def subthread(): providers.set_default_providers_for_netcode("BTC", []) self.assertEqual(providers.get_default_providers_for_netcode("BTC"), []) providers.set_default_providers_for_netcode("BTC", p_list_2) self.assertEqual(providers.get_default_providers_for_netcode("BTC"), p_list_2) l["is_ok"] = True t = threading.Thread(target=subthread) t.start() t.join() self.assertTrue(l["is_ok"]) self.assertEqual(providers.get_default_providers_for_netcode("BTC"), p_list_1)
def _init_connectors(self, netcode, wallet_connector_type, wallet_credentials=None): """ Initialize broadcasting and payment connectors. This allows fallback and confirmation across different chains :param wallet_connector_type: :return: """ if netcode == 'BTC': # configure mainnet providers provider_list = providers.providers_for_config_string( PYCOIN_BTC_PROVIDERS, 'BTC') blockio_index = -1 for idx, val in enumerate(provider_list): print(idx, val) if isinstance(val, BlockrioProvider): blockio_index = idx if blockio_index > -1: provider_list[blockio_index] = BlockrBroadcaster('BTC') else: provider_list.append(BlockrBroadcaster('BTC')) provider_list.append( InsightBroadcaster('https://insight.bitpay.com/', 'BTC')) # initialize payment connectors based on config file if wallet_connector_type == 'blockchain.info': provider_list.append( LocalBlockchainInfoConnector(wallet_credentials)) else: provider_list.append(BitcoindConnector('BTC')) providers.set_default_providers_for_netcode('BTC', provider_list) elif netcode == 'XTN': # initialize testnet providers testnet_list = [] testnet_list.append(BitcoindConnector('XTN')) providers.set_default_providers_for_netcode('XTN', testnet_list) else: logging.error('Unrecognized chain %s', netcode) raise UnrecognizedChainError('Unrecognized chain ' + netcode)
def init_connectors(conf): """ Initialize broadcasting and payment connectors. This allows fallback and confirmation across different chains :param conf: :return: """ # configure mainnet providers provider_list = providers.providers_for_config_string( PYCOIN_BTC_PROVIDERS, 'BTC') blockio_index = -1 for idx, val in enumerate(provider_list): print(idx, val) if isinstance(val, BlockrioProvider): blockio_index = idx if blockio_index > -1: provider_list[blockio_index] = BlockrBroadcaster('BTC') else: provider_list.append(BlockrBroadcaster('BTC')) provider_list.append( InsightBroadcaster('https://insight.bitpay.com/', 'BTC')) # initialize payment connectors based on config file if conf.wallet_connector_type == 'blockchain.info': provider_list.append(LocalBlockchainInfoConnector(conf)) else: provider_list.append(BitcoindConnector('BTC')) providers.set_default_providers_for_netcode('BTC', provider_list) # initialize testnet providers testnet_list = [] testnet_list.append(BitcoindConnector('XTN')) providers.set_default_providers_for_netcode('XTN', testnet_list)
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) PYCOIN_BTC_PROVIDERS = "blockchain.info blockexplorer.com blockcypher.com chain.so" PYCOIN_XTN_PROVIDERS = "blockexplorer.com" # chain.so # initialize connectors connectors = {} # configure mainnet providers provider_list = providers.providers_for_config_string(PYCOIN_BTC_PROVIDERS, Chain.mainnet.netcode) provider_list.append(BlockrIOBroadcaster('https://btc.blockr.io/api/v1')) provider_list.append(BlockExplorerBroadcaster('https://blockexplorer.com/api')) provider_list.append(BlockrioProvider(Chain.mainnet.netcode)) provider_list.append(InsightProvider(netcode=Chain.mainnet.netcode)) connectors[Chain.mainnet.netcode] = provider_list # configure testnet providers xtn_provider_list = providers.providers_for_config_string(PYCOIN_XTN_PROVIDERS, Chain.testnet.netcode) xtn_provider_list.append(InsightProvider(base_url='https://test-insight.bitpay.com', netcode=Chain.testnet.netcode)) xtn_provider_list.append(BlockrIOBroadcaster('https://tbtc.blockr.io/api/v1')) xtn_provider_list.append(BlockExplorerBroadcaster('https://testnet.blockexplorer.com/api')) xtn_provider_list.append(BlockrioProvider(Chain.testnet.netcode)) connectors[Chain.testnet.netcode] = xtn_provider_list
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 PYCOIN_BTC_PROVIDERS = "blockchain.info blockexplorer.com blockr.io blockcypher.com chain.so" PYCOIN_XTN_PROVIDERS = "blockexplorer.com chain.so" # initialize connectors connectors = {} # configure mainnet providers provider_list = providers.providers_for_config_string(PYCOIN_BTC_PROVIDERS, Chain.mainnet.netcode) provider_list.append(BlockrIOBroadcaster('https://btc.blockr.io/api/v1')) provider_list.append(BlockExplorerBroadcaster('https://blockexplorer.com/api')) connectors['BTC'] = provider_list # configure testnet providers xtn_provider_list = providers.providers_for_config_string( PYCOIN_XTN_PROVIDERS, Chain.testnet.netcode) xtn_provider_list.append(BlockrIOBroadcaster('https://tbtc.blockr.io/api/v1')) xtn_provider_list.append( BlockExplorerBroadcaster('https://testnet.blockexplorer.com/api')) connectors[Chain.testnet.netcode] = xtn_provider_list # workaround for regtest connectors['REG'] = [BitcoindConnector(Chain.testnet.netcode)]
def test_env(self): CS = "blockchain.info blockexplorer.com chain.so insight:https://hostname/url" provider_list = providers.providers_for_config_string(CS, "BTC") self.assertEqual(len(provider_list), len(CS.split()))
'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) PYCOIN_BTC_PROVIDERS = "blockchain.info blockexplorer.com blockcypher.com chain.so" PYCOIN_XTN_PROVIDERS = "blockexplorer.com" # chain.so # initialize connectors connectors = {} # configure mainnet providers provider_list = providers.providers_for_config_string( PYCOIN_BTC_PROVIDERS, helpers.to_pycoin_chain(Chain.bitcoin_mainnet)) provider_list.append(BlockrIOBroadcaster('https://btc.blockr.io/api/v1')) provider_list.append(BlockExplorerBroadcaster('https://blockexplorer.com/api')) provider_list.append( InsightProvider(netcode=helpers.to_pycoin_chain(Chain.bitcoin_mainnet))) provider_list.append( ChainSoProvider(netcode=helpers.to_pycoin_chain(Chain.bitcoin_mainnet))) connectors[Chain.bitcoin_mainnet] = provider_list # configure testnet providers xtn_provider_list = providers.providers_for_config_string( PYCOIN_XTN_PROVIDERS, helpers.to_pycoin_chain(Chain.bitcoin_testnet)) xtn_provider_list.append( ChainSoProvider(netcode=helpers.to_pycoin_chain(Chain.bitcoin_testnet))) xtn_provider_list.append(BlockrIOBroadcaster('https://tbtc.blockr.io/api/v1')) xtn_provider_list.append(
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) PYCOIN_BTC_PROVIDERS = "blockchain.info blockexplorer.com blockcypher.com chain.so" PYCOIN_XTN_PROVIDERS = "blockexplorer.com" # chain.so # initialize connectors connectors = {} # configure mainnet providers provider_list = providers.providers_for_config_string(PYCOIN_BTC_PROVIDERS, helpers.to_pycoin_chain(Chain.bitcoin_mainnet)) provider_list.append(BlockrIOBroadcaster('https://btc.blockr.io/api/v1')) provider_list.append(BlockExplorerBroadcaster('https://blockexplorer.com/api')) provider_list.append(InsightProvider(netcode=helpers.to_pycoin_chain(Chain.bitcoin_mainnet))) provider_list.append(ChainSoProvider(netcode=helpers.to_pycoin_chain(Chain.bitcoin_mainnet))) connectors[Chain.bitcoin_mainnet] = provider_list # configure testnet providers xtn_provider_list = providers.providers_for_config_string(PYCOIN_XTN_PROVIDERS, helpers.to_pycoin_chain(Chain.bitcoin_testnet)) xtn_provider_list.append(ChainSoProvider(netcode=helpers.to_pycoin_chain(Chain.bitcoin_testnet))) xtn_provider_list.append(BlockrIOBroadcaster('https://tbtc.blockr.io/api/v1')) xtn_provider_list.append(BlockExplorerBroadcaster('https://testnet.blockexplorer.com/api')) connectors[Chain.bitcoin_testnet] = xtn_provider_list