Esempio n. 1
0
def get_blockchain_interface_instance(_config):
    # todo: refactor joinmarket module to get rid of loops
    # importing here is necessary to avoid import loops
    from jmclient.blockchaininterface import BitcoinCoreInterface, \
        RegtestBitcoinCoreInterface, ElectrumWalletInterface
    from jmclient.electruminterface import ElectrumInterface
    source = _config.get("BLOCKCHAIN", "blockchain_source")
    network = get_network()
    testnet = network == 'testnet'
    if source in ('bitcoin-rpc', 'regtest'):
        rpc_host = _config.get("BLOCKCHAIN", "rpc_host")
        rpc_port = _config.get("BLOCKCHAIN", "rpc_port")
        rpc_user, rpc_password = get_bitcoin_rpc_credentials(_config)
        rpc_wallet_file = _config.get("BLOCKCHAIN", "rpc_wallet_file")
        rpc = JsonRpc(rpc_host, rpc_port, rpc_user, rpc_password,
                      rpc_wallet_file)
        if source == 'bitcoin-rpc':  #pragma: no cover
            bc_interface = BitcoinCoreInterface(rpc, network)
        else:
            bc_interface = RegtestBitcoinCoreInterface(rpc)
    elif source == 'electrum':
        bc_interface = ElectrumWalletInterface(testnet)
    elif source == 'electrum-server':
        bc_interface = ElectrumInterface(
            testnet)  #can specify server, config, TODO
    else:
        raise ValueError("Invalid blockchain source")
    return bc_interface
Esempio n. 2
0
def get_blockchain_interface_instance(_config):
    # todo: refactor joinmarket module to get rid of loops
    # importing here is necessary to avoid import loops
    from jmclient.blockchaininterface import BitcoinCoreInterface, \
        RegtestBitcoinCoreInterface, ElectrumWalletInterface, \
        BitcoinCoreNoHistoryInterface
    source = _config.get("BLOCKCHAIN", "blockchain_source")
    network = get_network()
    testnet = (network == 'testnet' or network == 'signet')

    if source in ('bitcoin-rpc', 'regtest', 'bitcoin-rpc-no-history'):
        rpc_host = _config.get("BLOCKCHAIN", "rpc_host")
        rpc_port = _config.get("BLOCKCHAIN", "rpc_port")
        if rpc_port == '':
            if network == 'mainnet':
                rpc_port = 8332
            elif network == 'regtest':
                rpc_port = 18443
            elif network == 'testnet':
                rpc_port = 18332
            elif network == 'signet':
                rpc_port = 38332
            else:
                raise ValueError('wrong network configured: ' + network)
        rpc_user, rpc_password = get_bitcoin_rpc_credentials(_config)
        rpc_wallet_file = _config.get("BLOCKCHAIN", "rpc_wallet_file")
        rpc = JsonRpc(rpc_host, rpc_port, rpc_user, rpc_password)
        if source == 'bitcoin-rpc': #pragma: no cover
            bc_interface = BitcoinCoreInterface(rpc, network,
                rpc_wallet_file)
            if testnet:
                btc.select_chain_params("bitcoin/testnet")
            else:
                btc.select_chain_params("bitcoin")
        elif source == 'regtest':
            bc_interface = RegtestBitcoinCoreInterface(rpc,
                rpc_wallet_file)
            btc.select_chain_params("bitcoin/regtest")
        elif source == "bitcoin-rpc-no-history":
            bc_interface = BitcoinCoreNoHistoryInterface(rpc, network,
                rpc_wallet_file)
            if testnet or network == "regtest":
                # in tests, for bech32 regtest addresses, for bc-no-history,
                # this will have to be reset manually:
                btc.select_chain_params("bitcoin/testnet")
            else:
                btc.select_chain_params("bitcoin")
        else:
            assert 0
    elif source == 'electrum':
        bc_interface = ElectrumWalletInterface(testnet)
    elif source == 'no-blockchain':
        bc_interface = None
    else:
        raise ValueError("Invalid blockchain source")
    return bc_interface
Esempio n. 3
0
def get_blockchain_interface_instance(_config):
    # todo: refactor joinmarket module to get rid of loops
    # importing here is necessary to avoid import loops
    from jmclient.blockchaininterface import BitcoinCoreInterface, \
        RegtestBitcoinCoreInterface, BlockrInterface, ElectrumWalletInterface, \
        BlockchaininfoInterface
    from jmclient.electruminterface import ElectrumInterface
    source = _config.get("BLOCKCHAIN", "blockchain_source")
    network = get_network()
    testnet = network == 'testnet'
    if source == 'bitcoin-rpc':  #pragma: no cover
        #This cannot be tested without mainnet or testnet blockchain (not regtest)
        rpc_host = _config.get("BLOCKCHAIN", "rpc_host")
        rpc_port = _config.get("BLOCKCHAIN", "rpc_port")
        rpc_user = _config.get("BLOCKCHAIN", "rpc_user")
        rpc_password = _config.get("BLOCKCHAIN", "rpc_password")
        rpc = JsonRpc(rpc_host, rpc_port, rpc_user, rpc_password)
        bc_interface = BitcoinCoreInterface(rpc, network)
    elif source == 'regtest':
        rpc_host = _config.get("BLOCKCHAIN", "rpc_host")
        rpc_port = _config.get("BLOCKCHAIN", "rpc_port")
        rpc_user = _config.get("BLOCKCHAIN", "rpc_user")
        rpc_password = _config.get("BLOCKCHAIN", "rpc_password")
        rpc = JsonRpc(rpc_host, rpc_port, rpc_user, rpc_password)
        bc_interface = RegtestBitcoinCoreInterface(rpc)
    elif source == 'blockr':
        bc_interface = BlockrInterface(testnet)
    elif source == 'bc.i':
        bc_interface = BlockchaininfoInterface(testnet)
    elif source == 'electrum':
        bc_interface = ElectrumWalletInterface(testnet)
    elif source == 'electrum-server':
        bc_interface = ElectrumInterface(
            testnet)  #can specify server, config, TODO
    else:
        raise ValueError("Invalid blockchain source")
    return bc_interface