joinmarket-clientserver icon indicating copy to clipboard operation
joinmarket-clientserver copied to clipboard

Wallet file not specified (must request wallet RPC through /wallet/<filename> uri-path).

Open 5F43CCDF opened this issue 2 years ago • 5 comments

When no default wallet exists you get the following error: jmclient.jsonrpc.JsonRpcError: {'code': -18, 'message': 'No wallet is loaded. Load a wallet using loadwallet or create a new one with createwallet. (Note: A default wallet is no longer automatically created)'}

When multiple wallets exist you get the following error. jmclient.jsonrpc.JsonRpcError: {'code': -19, 'message': 'Wallet file not specified (must request wallet RPC through /wallet/<filename> uri-path).'}

The first error is arguably acceptable, but the second one is leaves the user wondering what the problem even is. A preferred solution would catch the exception and tell the user what they need to do. For example, show the correct combination of bitcoin-cli listwallets, bitcoin-cli unloadwallet "extra_wallet1", bitcoin-cli unloadwallet "extra_wallet2", bitcoin-cli loadwallet "", and bitcoin-cli createwallet "" commands needed to get the bitcoind full node back into a state that is usable.

5F43CCDF avatar Jan 12 '22 16:01 5F43CCDF

That's the Bitcoin Core issue, not JM's. bitcoin-cli listwallets will show you the list of loaded wallets. JoinMarket will try to auto-load wallet specified as rpc_wallet_file in joinmarket.cfg. But will not work with empty Core wallet name ("") which is sometimes name for the default wallet, automatically created and loaded by older Bitcoin Core versions. In that case you must create new Core wallet for JM, see #395.

kristapsk avatar Jan 12 '22 17:01 kristapsk

Yes, but instead of throwing an exception, it could print out a hint and gracefully exit.

5F43CCDF avatar Jan 12 '22 19:01 5F43CCDF

Yes, agree, it could, should catch JsonRpcError and check code.

kristapsk avatar Jan 12 '22 19:01 kristapsk

When the exception occurs in the Qt client, currently the exception is logged to the console and the wallet never loads, but the program doesn't crash. How should we go about adding in a hint message? Is a hint in the console enough or should a dialog pop up?

EDIT: Using jmprint shows promise. https://github.com/JoinMarket-Org/joinmarket-clientserver/pull/926/files#diff-9b630423c9a14a63d735f73cb7584bebec7e4ce0efea21c0cee232dfd3944b60R1392-R1396

EDIT: We could probably solve this issue #483 at the same time with an error code lookup table for hints.

  File "/home/user/git/joinmarket-clientserver/jmclient/jmclient/jsonrpc.py", line 175, in call
    raise JsonRpcError(response["error"])
jmclient.jsonrpc.JsonRpcError: {'code': -13, 'message': 'Error: Please enter the wallet passphrase with walletpassphrase first.'}```

5F43CCDF avatar Jan 13 '22 05:01 5F43CCDF

I wasn't sure where to catch the exception at, or the preferred method of shutting down the client. I refactored https://github.com/JoinMarket-Org/joinmarket-clientserver/blob/8b3d21f226185e31aa10e8e16cdfc719cea4a98e/jmclient/jmclient/wallet_service.py#L102 to take any message for shutdown and it worked on the Qt client, but not on the cli tools, so somebody with more experience should probably implement the shutdown of the clients. Here is a rough draft of the hints I came up with:

        try:
            # code that throws
        except JsonRpcError as e:
            hints = {
                -13: """
Bitcoin Core requires you to unlock your wallet before the RPC will work. To
do this you can use the following command to unlock the wallet for 60 seconds:

  bitcoin-cli walletpassphrase "my pass phrase" 60

Alternatively, you can use a wallet without a passphrase. To do this, you will
need to load a wallet on Bitcoin Core. If multiple wallets are loaded then
you will have to set 'rpc_wallet_file'in joinmarket.cfg. You can manage
wallets on your node with the following commands:

  bitcoin-cli listwalletdir
  bitcoin-cli listwallets
  bitcoin-cli createwallet "wallet_name"
  bitcoin-cli loadwallet "wallet_name"
  bitcoin-cli unloadwallet "wallet_name"
""",
                -18: """
Bitcoin Core needs a loaded wallet for the RPC to work. Note: A default wallet
is not automatically created. You can fix this with the following commands:

  bitcoin-cli listwalletdir
  bitcoin-cli listwallets
  bitcoin-cli createwallet "wallet_name"
  bitcoin-cli loadwallet "wallet_name"
""",
                -19: """
Bitcoin Core has multiple wallet files loaded. For the RPC to work a RPC
wallet file must be specified. You can fix this by setting 'rpc_wallet_file'
in the joinmarket.cfg to a loaded wallet. Alternatively, you can unload unused
wallets. Note the following relevant commands:

  bitcoin-cli listwallets
  bitcoin-cli unloadwallet "wallet_name"
  bitcoin-cli listwalletdir
  bitcoin-cli loadwallet "wallet_name"
"""
            }

            if e.code in hints.keys():
                #self.critical_error(hints[e.code])
                jlog.error(hints[e.code])
                # shutdown
            else:
                raise e

Originally, I was trying to catch the exception in sync_wallet(), but I am not sure that's the best place as the cli tools get stuck in an infinite loop. https://github.com/JoinMarket-Org/joinmarket-clientserver/blob/8b3d21f226185e31aa10e8e16cdfc719cea4a98e/jmclient/jmclient/wallet_service.py#L438

5F43CCDF avatar Jan 14 '22 16:01 5F43CCDF