def __init__(self, jsonRpc, network):
        super().__init__()
        self.jsonRpc = jsonRpc
        blockchainInfo = self.rpc("getblockchaininfo", [])
        if not blockchainInfo:
            # see note in BitcoinCoreInterface.rpc - here
            # we have to create this object before reactor start,
            # so reactor is not stopped, so we override the 'swallowing'
            # of the Exception that happened in self.rpc():
            raise JsonRpcConnectionError("RPC connection to Bitcoin Core "
                                         "was not established successfully.")
        actualNet = blockchainInfo['chain']

        netmap = {'main': 'mainnet', 'test': 'testnet', 'regtest': 'regtest'}
        if netmap[actualNet] != network and \
                (not (actualNet == "regtest" and network == "testnet")):
            #special case of regtest and testnet having the same addr format
            raise Exception('wrong network configured')
Exemple #2
0
    def __init__(self, jsonRpc, network, wallet_name):
        super().__init__()
        self.jsonRpc = jsonRpc
        blockchainInfo = self._rpc("getblockchaininfo", [])
        if not blockchainInfo:
            # see note in BitcoinCoreInterface.rpc - here
            # we have to create this object before reactor start,
            # so reactor is not stopped, so we override the 'swallowing'
            # of the Exception that happened in self._rpc():
            raise JsonRpcConnectionError("RPC connection to Bitcoin Core "
                                         "was not established successfully.")
        actualNet = blockchainInfo['chain']

        netmap = {
            'main': 'mainnet',
            'test': 'testnet',
            'regtest': 'regtest',
            'signet': 'signet'
        }
        if netmap[actualNet] != network and \
                (not (actualNet == "regtest" and network == "testnet")):
            #special case of regtest and testnet having the same addr format
            raise Exception('wrong network configured')

        if wallet_name:
            self.jsonRpc.setURL("/wallet/" + wallet_name)
            # Check that RPC wallet is loaded. If not, try to load it.
            loaded_wallets = self._rpc("listwallets", [])
            if not wallet_name in loaded_wallets:
                self._rpc("loadwallet", [wallet_name])
            # We only support legacy wallets currently
            wallet_info = self._rpc("getwalletinfo", [])
            if "descriptors" in wallet_info and wallet_info["descriptors"]:
                raise Exception(
                    "JoinMarket currently does not support Bitcoin Core "
                    "descriptor wallets, use legacy wallet (rpc_wallet_file "
                    "setting in joinmarket.cfg) instead. See docs/USAGE.md "
                    "for details.")