Default wallet rpc polar patch1 - #1356
Conversation
…coincore to use default wallet
…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
Greptile OverviewGreptile SummaryThis PR addresses a multi-wallet compatibility issue in Bitcoin Core by explicitly targeting the default wallet in RPC calls. The core fix (adding Key Changes:
Critical Issues Found:
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
|
| 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
| // 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, |
There was a problem hiding this comment.
duplicate property definitions - these properties are defined twice with different values
| // 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.| // Spread the incoming values first | ||
| unconfirmedTransfers: '0', | ||
| ...value, | ||
| // Force unconfirmedTransfers to be a string at the end | ||
| unconfirmedTransfers: value.unconfirmedTransfers ?? '', |
There was a problem hiding this comment.
unconfirmedTransfers is being set three times with conflicting logic - this will always result in a string (or empty string)
| // 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.| // Initializing tapNode from undefined to empty Tapdnode / LitdNode object | ||
| let tapNode: TapdNode | LitdNode = {} as TapdNode | LitdNode; |
There was a problem hiding this 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
| // 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.| "testcafe-react-selectors": "5.0.3", | ||
| "ts-node": "10.9.2", | ||
| "typescript": "5.5.4", | ||
| "typescript": "5.3.3", |
There was a problem hiding this 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
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.|
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. |
|
Sir @jamaljsr please have a look at the PR. |
Greptile OverviewGreptile SummaryThis PR fixes the multi-wallet RPC routing issue (#1096) by explicitly targeting the default wallet in Bitcoin Core RPC calls. The core fix in Key Changes:
Critical Issues Found:
Confidence Score: 1/5
|
| 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
| confirmationsUntilActive: rest.confirmationsUntilActive ?? 0, | ||
| confirmationHeight: rest.confirmationHeight ?? 0, | ||
| confirmationsUntilActive: 6, | ||
| confirmationHeight: 1234, |
There was a problem hiding this comment.
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.
| 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, |
| unconfirmedTransfers: '0', | ||
| ...value, | ||
| // Force unconfirmedTransfers to be a string at the end | ||
| unconfirmedTransfers: value.unconfirmedTransfers ?? '', |
There was a problem hiding this comment.
unconfirmedTransfers is set three times with conflicting logic:
- Line 28:
'0' - Line 29: spread operator potentially overwrites with
value.unconfirmedTransfers - Line 31:
value.unconfirmedTransfers ?? ''
This will always result in a string (either from value or empty string), making line 28 pointless.
| 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', |
|
|
||
| let tapNode: TapdNode | LitdNode | undefined = undefined; | ||
| // Initializing tapNode from undefined to empty Tapdnode / LitdNode object | ||
| let tapNode: TapdNode | LitdNode = {} as TapdNode | LitdNode; |
There was a problem hiding this comment.
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.
| let tapNode: TapdNode | LitdNode = {} as TapdNode | LitdNode; | |
| let tapNode: TapdNode | LitdNode | undefined = undefined; |
| "testcafe-react-selectors": "5.0.3", | ||
| "ts-node": "10.9.2", | ||
| "typescript": "5.5.4", | ||
| "typescript": "5.3.3", |
There was a problem hiding this comment.
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
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 |
|
ok sir |
|
Replaced by #1360 |
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
Screenshots