Skip to content

Default wallet rpc polar patch1 - #1356

Closed
TomLucasakaTGeek wants to merge 3 commits into
jamaljsr:masterfrom
TomLucasakaTGeek:default-wallet-rpc-polar-patch1
Closed

Default wallet rpc polar patch1#1356
TomLucasakaTGeek wants to merge 3 commits into
jamaljsr:masterfrom
TomLucasakaTGeek:default-wallet-rpc-polar-patch1

Conversation

@TomLucasakaTGeek

@TomLucasakaTGeek TomLucasakaTGeek commented Jan 27, 2026

Copy link
Copy Markdown

Closes #1096

Description

The Problem

By default, when multiple wallets are loaded in a Bitcoin Core node, RPC calls require an explicit wallet context. Polar was previously making calls to the base RPC endpoint. When a user connected an external tool (like Sparrow Wallet) that created additional wallets, Bitcoin Core would return an error:

The Fix
I updated the BitcoindService to ensure all RPC interactions are explicitly directed to the default Polar wallet, even if other wallets are present on the node.

Explicit Wallet Targeting: Modified the RPC client configuration to append wallet/ to the base URL path.

Default Wallet Fallback: Ensured that commands are executed against the default wallet ("" or the primary loaded wallet) by utilizing the -rpcwallet equivalent in the service layer.

Environment Stability: Resolved several environment-related TypeScript and Babel conflicts that arose during the development of this fix on Windows/WSL2 environments to ensure the build remains stable across platforms.

Technical Changes
src/lib/bitcoin/bitcoindService.ts: Updated the RPC request logic to include the wallet name in the request path.

src/shared/lndDefaults.ts & src/shared/tapdDefaults.ts: Applied nullish coalescing operators to handle stricter type definitions in newer Bitcoin/LND/TAP libraries.

Verification Results

<--
Manual Testing: Verified that Polar remains connected and functional even after creating multiple wallets via bitcoin-cli and Sparrow Wallet on a Regtest node.
-->

Linting: yarn lint:all passes successfully.

Tests: All unit tests pass.

Steps to Test

  1. Download Sparrow Wallet
  2. Open Sparrow Wallet in regtest mode by opening it using "Sparrow.exe -n regtest" command
  3. Generate keys and connect wallet to Polar by selecting "Bitcoin Core" as Polar acts as a Core Network
  4. Provide values of credentials from the Polar Network and connect it.
  5. The issue is resolved.

Screenshots

image Screenshot 2026-01-27 205714

TomLucasakaTGeek and others added 3 commits December 21, 2025 05:32
…ults.ts tapdservice.spec.ts): c

Polar was creating multiple wallet credentials when connected to a wallet(eg- Sparrow Wallet),
enforced default values during wallet connection
@TomLucasakaTGeek
TomLucasakaTGeek marked this pull request as draft January 27, 2026 15:57
@greptile-apps

greptile-apps Bot commented Jan 30, 2026

Copy link
Copy Markdown

Greptile Overview

Greptile Summary

This PR addresses a multi-wallet compatibility issue in Bitcoin Core by explicitly targeting the default wallet in RPC calls. The core fix (adding wallet: '' to the BitcoinCore client config in src/lib/bitcoin/bitcoind/bitcoindService.ts:20) is sound and solves the stated problem.

Key Changes:

  • Modified BitcoindService to include explicit wallet parameter when creating RPC client
  • Added test coverage for the wallet parameter initialization
  • Attempted to fix TypeScript strict type checking issues in LND and TAP defaults

Critical Issues Found:

  • src/shared/lndDefaults.ts:143-147: Contains duplicate property definitions that will cause bugs - confirmationsUntilActive and confirmationHeight are defined twice with conflicting values
  • src/shared/tapdDefaults.ts:27-31: Triple assignment of unconfirmedTransfers with conflicting logic
  • src/utils/network.ts:1144-1145: Unsafe type assertion ({} as TapdNode | LitdNode) that bypasses TypeScript's type checking and can hide runtime errors
  • package.json:157: TypeScript downgrade from 5.5.4 to 5.3.3 is unexplained and potentially problematic

The wallet RPC fix itself is correct, but the ancillary "type safety" changes introduce new bugs rather than fixing them. These appear to be workarounds for stricter TypeScript checking rather than proper solutions.

Confidence Score: 2/5

  • This PR contains critical bugs in the type safety changes that will cause runtime errors
  • The core wallet RPC fix is well-implemented and solves the multi-wallet issue. However, the PR includes several problematic changes that introduce bugs: duplicate property definitions in lndDefaults.ts, conflicting assignments in tapdDefaults.ts, and an unsafe type assertion in network.ts. The TypeScript downgrade also raises concerns about type safety regression across the project
  • Pay close attention to src/shared/lndDefaults.ts, src/shared/tapdDefaults.ts, and src/utils/network.ts - these files contain bugs that need to be fixed before merging

Important Files Changed

Filename Overview
src/lib/bitcoin/bitcoind/bitcoindService.ts Added wallet: '' parameter to Bitcoin Core client initialization to explicitly target default wallet in multi-wallet scenarios
src/shared/lndDefaults.ts Contains duplicate property definitions for confirmationsUntilActive and confirmationHeight that will cause incorrect behavior
src/shared/tapdDefaults.ts Attempts to handle unconfirmedTransfers type safety but contains redundant assignments that override each other
src/utils/network.ts Changes tapNode initialization from undefined to empty object with unsafe type assertion, which can hide bugs
package.json Downgrades TypeScript from 5.5.4 to 5.3.3 without explanation in PR description

Sequence Diagram

sequenceDiagram
    participant UI as Polar UI
    participant Service as BitcoindService
    participant Client as BitcoinCore Client
    participant Node as Bitcoin Core Node
    
    UI->>Service: createClient(node)
    Service->>Client: new BitcoinCore({wallet: ''})
    Note over Client: Configures RPC endpoint<br/>with explicit wallet path
    Client-->>Service: BitcoinCoreClient
    
    UI->>Service: getWalletInfo(node)
    Service->>Client: createClient(node)
    Client->>Node: RPC: /wallet/ endpoint
    Note over Node: Routes to default wallet ('')<br/>even with multiple wallets
    Node-->>Client: wallet info
    Client-->>Service: wallet data
    Service-->>UI: wallet info
    
    Note over UI,Node: External tool (e.g., Sparrow)<br/>creates additional wallets
    
    UI->>Service: mine(blocks, node)
    Service->>Client: createClient(node)
    Client->>Node: RPC: /wallet/ endpoint
    Note over Node: Still routes to default wallet<br/>Multi-wallet conflict avoided
    Node-->>Client: mining result
    Client-->>Service: block hashes
    Service-->>UI: mining complete
Loading

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 files reviewed, 4 comments

Edit Code Review Agent Settings | Greptile

Comment thread src/shared/lndDefaults.ts
Comment on lines +143 to 147
// Use the nullish coalescing operator (??) to provide 0 if the value is missing
confirmationsUntilActive: rest.confirmationsUntilActive ?? 0,
confirmationHeight: rest.confirmationHeight ?? 0,
confirmationsUntilActive: 6,
confirmationHeight: 1234,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate property definitions - these properties are defined twice with different values

Suggested change
// Use the nullish coalescing operator (??) to provide 0 if the value is missing
confirmationsUntilActive: rest.confirmationsUntilActive ?? 0,
confirmationHeight: rest.confirmationHeight ?? 0,
confirmationsUntilActive: 6,
confirmationHeight: 1234,
// Use the nullish coalescing operator (??) to provide 0 if the value is missing
confirmationsUntilActive: rest.confirmationsUntilActive ?? 0,
confirmationHeight: rest.confirmationHeight ?? 0,
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/shared/lndDefaults.ts
Line: 143:147

Comment:
duplicate property definitions - these properties are defined twice with different values

```suggestion
    // Use the nullish coalescing operator (??) to provide 0 if the value is missing
    confirmationsUntilActive: rest.confirmationsUntilActive ?? 0,
    confirmationHeight: rest.confirmationHeight ?? 0,
```

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +27 to +31
// Spread the incoming values first
unconfirmedTransfers: '0',
...value,
// Force unconfirmedTransfers to be a string at the end
unconfirmedTransfers: value.unconfirmedTransfers ?? '',

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unconfirmedTransfers is being set three times with conflicting logic - this will always result in a string (or empty string)

Suggested change
// Spread the incoming values first
unconfirmedTransfers: '0',
...value,
// Force unconfirmedTransfers to be a string at the end
unconfirmedTransfers: value.unconfirmedTransfers ?? '',
assetBalances: {},
assetGroupBalances: {},
...value,
// Use nullish coalescing to ensure unconfirmedTransfers is always a string
unconfirmedTransfers: value.unconfirmedTransfers ?? '0',
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/shared/tapdDefaults.ts
Line: 27:31

Comment:
`unconfirmedTransfers` is being set three times with conflicting logic - this will always result in a string (or empty string)

```suggestion
  assetBalances: {},
  assetGroupBalances: {},
  ...value,
  // Use nullish coalescing to ensure unconfirmedTransfers is always a string
  unconfirmedTransfers: value.unconfirmedTransfers ?? '0',
```

How can I resolve this? If you propose a fix, please make it concise.

Comment thread src/utils/network.ts
Comment on lines +1144 to +1145
// Initializing tapNode from undefined to empty Tapdnode / LitdNode object
let tapNode: TapdNode | LitdNode = {} as TapdNode | LitdNode;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unsafe type assertion bypasses TypeScript's type checking - this can hide bugs. If tapNode is accessed when it's an empty object, it will cause runtime errors because required properties like implementation and lndName won't exist

Suggested change
// Initializing tapNode from undefined to empty Tapdnode / LitdNode object
let tapNode: TapdNode | LitdNode = {} as TapdNode | LitdNode;
// Initialize as undefined - will be set when matching node is found
let tapNode: TapdNode | LitdNode | undefined = undefined;
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/utils/network.ts
Line: 1144:1145

Comment:
unsafe type assertion bypasses TypeScript's type checking - this can hide bugs. If `tapNode` is accessed when it's an empty object, it will cause runtime errors because required properties like `implementation` and `lndName` won't exist

```suggestion
  // Initialize as undefined - will be set when matching node is found
  let tapNode: TapdNode | LitdNode | undefined = undefined;
```

How can I resolve this? If you propose a fix, please make it concise.

Comment thread package.json
"testcafe-react-selectors": "5.0.3",
"ts-node": "10.9.2",
"typescript": "5.5.4",
"typescript": "5.3.3",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

downgrading TypeScript from 5.5.4 to 5.3.3 is a significant change that isn't explained in the PR description. Check if this downgrade is necessary or if the actual issues can be resolved without downgrading

Prompt To Fix With AI
This is a comment left during a code review.
Path: package.json
Line: 157:157

Comment:
downgrading TypeScript from 5.5.4 to 5.3.3 is a significant change that isn't explained in the PR description. Check if this downgrade is necessary or if the actual issues can be resolved without downgrading

How can I resolve this? If you propose a fix, please make it concise.

@jamaljsr

Copy link
Copy Markdown
Owner

Thanks for the PR to resolve the bitcoin wallet issue. The code includes a bunch of changes unrelated to the issue. Can you please only limit the scope of this PR to only address the wallet issue. This should be just the bitcoindService and test files.

Also, please provide detailed steps to test the behavior. This significantly helps speed up the review process.

@TomLucasakaTGeek

Copy link
Copy Markdown
Author

Thanks for the PR to resolve the bitcoin wallet issue. The code includes a bunch of changes unrelated to the issue. Can you please only limit the scope of this PR to only address the wallet issue. This should be just the bitcoindService and test files.

Also, please provide detailed steps to test the behavior. This significantly helps speed up the review process.

Sure sir, the changes made were not intentional but cause there were some kind of errors arising when converting the code to binary or while running the application,

I will surely add detailed testing procedure soon and will convert draft to Merge-ready PR.

@TomLucasakaTGeek
TomLucasakaTGeek marked this pull request as ready for review February 7, 2026 15:35
@TomLucasakaTGeek

Copy link
Copy Markdown
Author

Sir @jamaljsr please have a look at the PR.

@greptile-apps

greptile-apps Bot commented Feb 7, 2026

Copy link
Copy Markdown

Greptile Overview

Greptile Summary

This PR fixes the multi-wallet RPC routing issue (#1096) by explicitly targeting the default wallet in Bitcoin Core RPC calls. The core fix in bitcoindService.ts:20 adds wallet: '' to route all requests to the default Polar wallet, preventing errors when external tools like Sparrow create additional wallets.

Key Changes:

  • Fixed multi-wallet conflict by adding explicit wallet routing to BitcoindService
  • Added test coverage for the wallet parameter configuration
  • TypeScript downgraded from 5.5.4 to 5.3.3 (unexplained in description)

Critical Issues Found:

  • lndDefaults.ts:144-147 - duplicate property definitions cause hardcoded values to always overwrite nullish coalescing defaults
  • tapdDefaults.ts:28-31 - unconfirmedTransfers assigned three times with conflicting logic
  • network.ts:1145 - unsafe type assertion {} as TapdNode | LitdNode bypasses type checking and will cause runtime errors when the empty object is accessed

Confidence Score: 1/5

  • This PR has critical logical errors that will cause bugs in production
  • While the primary wallet RPC fix is sound, three files contain critical logical errors: duplicate property definitions in lndDefaults.ts will always use hardcoded values instead of incoming data, triple assignment in tapdDefaults.ts creates confusion, and unsafe type assertion in network.ts will cause runtime crashes when accessing the empty object. These issues indicate the "environment stability" fixes mentioned in the PR description introduced new bugs.
  • src/shared/lndDefaults.ts, src/shared/tapdDefaults.ts, and src/utils/network.ts require immediate fixes before merging

Important Files Changed

Filename Overview
src/lib/bitcoin/bitcoind/bitcoindService.ts added wallet: '' parameter to fix multi-wallet RPC routing issue
src/shared/lndDefaults.ts duplicate property definitions will cause hardcoded values to always overwrite nullish coalescing logic
src/shared/tapdDefaults.ts triple assignment of unconfirmedTransfers with conflicting logic
src/utils/network.ts unsafe type assertion bypasses type checking, will cause runtime errors when accessing empty object
package.json TypeScript downgraded from 5.5.4 to 5.3.3 without explanation

Sequence Diagram

sequenceDiagram
    participant UI as Polar UI
    participant Service as BitcoindService
    participant Client as BitcoinCore Client
    participant Node as Bitcoin Node

    Note over UI,Node: Multi-Wallet RPC Fix Flow

    UI->>Service: createClient(node)
    Service->>Client: new BitcoinCore({<br/>host, username, password,<br/>wallet: '' <-- DEFAULT WALLET<br/>})
    Note over Client: Client now routes all<br/>requests to default wallet

    UI->>Service: getWalletInfo(node)
    Service->>Client: getWalletInfo()
    Client->>Node: RPC: /wallet/ endpoint<br/>(targets default wallet)
    Node-->>Client: wallet info response
    Client-->>Service: wallet data
    Service-->>UI: formatted wallet info

    Note over UI,Node: Even with Multiple Wallets Present
    
    UI->>Service: mine(blocks, node)
    Service->>Client: generateToAddress(blocks, addr)
    Client->>Node: RPC: /wallet/ endpoint<br/>(still uses default wallet)
    Node-->>Client: block hashes
    Client-->>Service: mining result
    Service-->>UI: success
Loading

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 files reviewed, 4 comments

Edit Code Review Agent Settings | Greptile

Comment thread src/shared/lndDefaults.ts
Comment on lines +144 to 147
confirmationsUntilActive: rest.confirmationsUntilActive ?? 0,
confirmationHeight: rest.confirmationHeight ?? 0,
confirmationsUntilActive: 6,
confirmationHeight: 1234,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate property definitions - lines 144-145 set these properties using nullish coalescing, then lines 146-147 overwrite them with hardcoded values. The hardcoded values on 146-147 will always win.

Suggested change
confirmationsUntilActive: rest.confirmationsUntilActive ?? 0,
confirmationHeight: rest.confirmationHeight ?? 0,
confirmationsUntilActive: 6,
confirmationHeight: 1234,
// Use the nullish coalescing operator (??) to provide 0 if the value is missing
confirmationsUntilActive: rest.confirmationsUntilActive ?? 6,
confirmationHeight: rest.confirmationHeight ?? 1234,

Comment on lines 28 to +31
unconfirmedTransfers: '0',
...value,
// Force unconfirmedTransfers to be a string at the end
unconfirmedTransfers: value.unconfirmedTransfers ?? '',

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unconfirmedTransfers is set three times with conflicting logic:

  1. Line 28: '0'
  2. Line 29: spread operator potentially overwrites with value.unconfirmedTransfers
  3. Line 31: value.unconfirmedTransfers ?? ''

This will always result in a string (either from value or empty string), making line 28 pointless.

Suggested change
unconfirmedTransfers: '0',
...value,
// Force unconfirmedTransfers to be a string at the end
unconfirmedTransfers: value.unconfirmedTransfers ?? '',
assetBalances: {},
assetGroupBalances: {},
...value,
// Ensure unconfirmedTransfers is always a string
unconfirmedTransfers: value.unconfirmedTransfers ?? '0',

Comment thread src/utils/network.ts

let tapNode: TapdNode | LitdNode | undefined = undefined;
// Initializing tapNode from undefined to empty Tapdnode / LitdNode object
let tapNode: TapdNode | LitdNode = {} as TapdNode | LitdNode;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unsafe type assertion bypasses type checking. If tapNode is accessed when it's an empty object (lines 1154-1156), it will cause runtime errors because required properties like implementation and lndName won't exist.

Suggested change
let tapNode: TapdNode | LitdNode = {} as TapdNode | LitdNode;
let tapNode: TapdNode | LitdNode | undefined = undefined;

Comment thread package.json
"testcafe-react-selectors": "5.0.3",
"ts-node": "10.9.2",
"typescript": "5.5.4",
"typescript": "5.3.3",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

downgrading TypeScript from 5.5.4 to 5.3.3 isn't explained in the PR description - check if this is necessary or if the root issues can be fixed without downgrading

@jamaljsr

jamaljsr commented Feb 8, 2026

Copy link
Copy Markdown
Owner

Sir @jamaljsr please have a look at the PR.

This PR is still touching too many unrelated files and the Typescript downgrade is breaking the CI checks.

Please revert most of the changes. Only include the minimum necessary to resolve the problem, which to me seems to only be the update to bitcoindService.

@TomLucasakaTGeek

Copy link
Copy Markdown
Author

ok sir

@jamaljsr

jamaljsr commented Feb 8, 2026

Copy link
Copy Markdown
Owner

Replaced by #1360

@jamaljsr jamaljsr closed this Feb 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Use default wallet for rpc commands when multiple wallets are loaded

2 participants