Open Legend101Zz opened 1 week ago
caravan-clients
[ ] Centralize Type Definitions
types.ts
[ ] Improve RPC Parameter Handling
RPCParams
type for flexible handling BitcoindWalletParams
interface typing [ ] Standardize Response Types
RPCMethodResponseMap
[ ] Normalize Backend Responses
[ ] Make Core Functions Generic
callBitcoindWallet
to be generic [ ] Replace any
with Type Guards
any
with unknown
in error handling [ ] Documentation & Maintenance )
🔗 Issue remains open until all tasks are completed.
Note: The above changes are temporary and should be adjusted based on needs and requirements.
cc: @bucko13 for visibility.
I have completed the first two parts of the issue, mentioning the PR https://github.com/caravan-bitcoin/caravan/pull/200.
cc @Legend101Zz, @bucko13 for reviews
Summary
After digging through the codebase, I've noticed our type system in the
caravan-clients
package has several inconsistencies that make development harder than it needs to be. I'd like to propose a series of improvements to make our types more consistent, reduceany
usage, and better align with Bitcoin RPC responses.The Problems
Looking at the code, I've noticed a few issues:
any
types - We're usingany
in a lot of places witheslint-disable
comments and@ts-expect-error
workarounds.[imports, { rescan }]
, other times objects like{ minconf: 0, maxconf: 9999999, addresses: addressParam }
.bitcoind
,blockstream
, andmempool
all return different structures, making it hard to work with.Proposed Approach
I think we should tackle this in stages through several PRs:
Tasks
1. Centralize Type Definitions
types.ts
.2. Improve RPC Parameter Handling
RPCParams
type that can handle both array and object formats:BitcoindWalletParams
interface to use better typing.3. Create Response Type Mapping
getwalletinfo
WalletInfoResponse
wallet.ts
listunspent
ListUnspentResponse[]
wallet.ts
4. Make Core Functions Generic
callBitcoindWallet
to be generic (similar tocallBitcoind
):@ts-expect-error
annotations in various functions.5. Create Type Hierarchies for Complex Types
6. Implement Response Normalization Pattern
7. Replace
any
with Proper Type Guardsany
withunknown
in error handling.eslint-disable
comments where possible.8. Documentation and Maintenance Strategy
Implementation Plan
I suggest we tackle this incrementally to avoid disrupting current development:
any
).any
).Why This Matters
These changes will:
I'm happy to tackle the first PR to get things started. What do you all think :)