Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix BitcoinClient LoadWallet Errors #48

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/bitcoin/BitcoinClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ export default class BitcoinClient {
private async loadWallet () {
const request = {
method: 'loadwallet',
params: [this.walletNameToUse, true] // the wallet name
params: [this.walletNameToUse] // the wallet name
};

// Intentionally not throwing because bitcoin returns 500 when a wallet is already loaded
Expand All @@ -320,7 +320,9 @@ export default class BitcoinClient {
} catch (e) {
// using error message because bitcoin core error code is not reliable as a single code can contain multiple errors
const duplicateLoadString = 'already loaded';
if (e.toString().toLowerCase().includes(duplicateLoadString)) {
// this error is seen on some versions of bitcoin core when loading a loaded wallet, including v0.20.1
const alternateDuplicateLoadString = 'Duplicate -wallet filename specified';
if (e.toString().toLowerCase().includes(duplicateLoadString) || e.toString().includes(alternateDuplicateLoadString)) {
Logger.info(`Wallet with name ${this.walletNameToUse} already loaded.`);
} else {
throw e;
Expand Down
6 changes: 3 additions & 3 deletions tests/bitcoin/BitcoinClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ describe('BitcoinClient', async () => {
await bitcoinClient['loadWallet']();
expect(rpcSpy).toHaveBeenCalledWith({
method: 'loadwallet',
params: ['sidetreeDefaultWallet', true]
params: ['sidetreeDefaultWallet']
}, true, false);
expect(loggerSpy).toHaveBeenCalledWith(`Wallet loaded with name "sidetreeDefaultWallet".`);
});
Expand All @@ -425,7 +425,7 @@ describe('BitcoinClient', async () => {
} catch {
expect(rpcSpy).toHaveBeenCalledWith({
method: 'loadwallet',
params: ['sidetreeDefaultWallet', true]
params: ['sidetreeDefaultWallet']
}, true, false);
}
});
Expand All @@ -436,7 +436,7 @@ describe('BitcoinClient', async () => {
await bitcoinClient['loadWallet']();
expect(rpcSpy).toHaveBeenCalledWith({
method: 'loadwallet',
params: ['sidetreeDefaultWallet', true]
params: ['sidetreeDefaultWallet']
}, true, false);
expect(loggerSpy).toHaveBeenCalledWith(`Wallet with name sidetreeDefaultWallet already loaded.`);
});
Expand Down