Ejemplo 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
Ejemplo 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, 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