コード例 #1
0
    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)
コード例 #2
0
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)
コード例 #3
0
ファイル: services_test.py プロジェクト: onestarshang/pycoin
    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)
コード例 #4
0
    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)
コード例 #5
0
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)
コード例 #6
0
                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

コード例 #7
0
ファイル: connectors.py プロジェクト: tonypius/cert-issuer
                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)]
コード例 #8
0
ファイル: services_test.py プロジェクト: onestarshang/pycoin
 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()))
コード例 #9
0
                    '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(
コード例 #10
0
ファイル: services_test.py プロジェクト: zhp562176325/pycoin
 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()))
コード例 #11
0
ファイル: connectors.py プロジェクト: NiclausLiu/cert-issuer
                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