Designing Bitcoin SDK Error Handling and Failure Recovery
Research status: Theoretical SDK design. Examples are illustrative and have not been built or tested against the live engine.
Failure semantics
A transport failure is not a business rejection. Distinguish DNS or connection failure, HTTP failure, malformed JSON, an application envelope with ok=false, and an accepted operation whose response was lost. An HTTP success status alone cannot establish a successful wallet operation. Preserve the documented request identifier and sanitized error details. Do not map an unknown balance to zero or treat a warming balance as spendable.
Conceptual Python result model
from dataclasses import dataclass
from typing import Literal
@dataclass(frozen=True)
class Outcome:
state: Literal['accepted', 'rejected', 'unknown']
operation_id: str
detail: strThis is a local SDK abstraction, not an engine response schema. Persist the operation intent before dispatch. An ambiguous SEND outcome must remain unknown until reconciled through documented status and wallet evidence. Retry with the same request identifier only when the documented idempotency contract permits it; never create a fresh identifier merely because a timeout occurred. If no reliable correlation is available, escalate to an operator rather than guessing from a balance delta.
Recovery policy
Read operations may use bounded exponential backoff with jitter and a deadline. Mutating operations need separate policies: creation, restoration, removal and sending are not interchangeable. Do not automatically restore or remove a wallet to repair a transient network failure. Circuit breakers may prevent repeated calls but cannot determine whether an earlier transaction was broadcast. Keep unresolved operations durable across process restarts. Redact credentials and raw authorization headers from logs, including exceptions raised by HTTP libraries.
Acceptance plan
Inject a timeout before dispatch and another after a simulated accepted response. Verify that the latter does not trigger a new payment. Test malformed JSON, application rejection inside HTTP 200, unavailable status evidence and process restart. Confirm that cancellation stops local waiting rather than claiming to cancel a Bitcoin transaction. Repeat on an isolated Testnet wallet with a controlled proxy before enabling spending.
Primary reference
https://thamer.org/api
Related reading
https://thamer.org/docs/wab-sdk-idempotency-retry-strategies
https://thamer.org/docs/wab-sdk-typed-json-contracts
https://thamer.org/docs/wab-sdk-transaction-execution
