woodser/monero-ts

Can't use openWalletFull together with a ConnectionManager

Closed this issue · 4 comments

Hello

I'm currently building an app where payment with Monero will be accepted.
For this I'm using the monero-ts package to validate and track transactions.

When playing around I noticed, that opening a previously created wallet I can't use a connectionManager.

Here's how I'm creating and opening the wallets:

Create if wallet does not exist:

wallet = await monero.createWalletFull({
    path: WALLET_PATH,
    networkType: monero.MoneroNetworkType.STAGENET,
    primaryAddress:
      "address",
    privateViewKey:
      "privateViewKey",
    restoreHeight,
    connectionManager,
  });

Open if it exists:

 wallet = await monero.openWalletFull({
      path: WALLET_PATH,
      networkType: monero.MoneroNetworkType.STAGENET,
      connectionManager,
    });

The error I receive:

* Exception when interacting with a Monero wallet or daemon.
3 |  */
4 | class MoneroError extends Error {
5 | 
6 | 
7 | 
               ^
error: Wallet is not connected to daemon
 code: "undefined"

      at new MoneroError (/home/luke/playground/test-monero/node_modules/monero-ts/dist/src/main/ts/common/MoneroError.js:7:12)
      at deserializeError (/home/luke/playground/test-monero/node_modules/monero-ts/dist/src/main/ts/common/LibraryUtils.js:262:73)
      at /home/luke/playground/test-monero/node_modules/monero-ts/dist/src/main/ts/common/LibraryUtils.js:251:26
      at processTicksAndRejections (:61:39)
      at new MoneroError (/home/luke/playground/test-monero/node_modules/monero-ts/dist/src/main/ts/common/MoneroError.js:24:69)
      at /home/luke/playground/test-monero/node_modules/monero-ts/dist/src/main/ts/wallet/MoneroWalletFull.js:563:69
      at processTicksAndRejections (:61:39)

The way I'm currently solving it is:

 const connection = connectionManager.getConnection();

 const wallet = await monero.openWalletFull({
    path: WALLET_PATH,
    networkType: monero.MoneroNetworkType.STAGENET,
    server: connection,
  });

 connectionManager.addListener(
    new (class extends monero.MoneroConnectionManagerListener {
      async onConnectionChanged(connection: monero.MoneroRpcConnection) {
        if (!wallet) return;
        await wallet.setDaemonConnection(connection);
      }
    })()
  );

What I'm using:

Bun: 1.0.22
Node: 20.11.0
monero-ts: 0.9.5

I don't know if that is a bug or not since the connectionManager exists on the openWalletFull config object.

Best regards
Lukas

Thanks for pointing this out. The implementation is missing for opening a wallet, whereas it's supported when creating a wallet.

I'll fix this in the next release, but in the meantime, you can call await wallet.setConnectionManager(manager) after opening the wallet to avoid manually listening for connection changes.

Awesome, thank you for the workaround!

This is now fixed in the last release. Thanks for reporting it. :)

Thank you for the quick fix :)