Typed Bitcoin API Requests and JSON Response Handling
Research status: Theoretical SDK design. Examples are illustrative and have not been built or tested against the live engine.
Two layers of success
An HTTP response can arrive successfully while the requested wallet operation is rejected. Conversely, a connection failure may leave the outcome of an operation unknown. Decode transport and application outcomes separately. Earlier laboratory observations include application-level rejection on HTTP 200; this is why status-code checks alone are insufficient.
Conceptual decoder
from dataclasses import dataclass
from typing import Any
@dataclass
class Outcome:
ok: bool
request_id: str | None
result: Any
def decode(payload):
if not isinstance(payload, dict) or type(payload.get("ok")) is not bool:
raise ValueError("Unexpected operation envelope")
rid = payload.get("request_id")
if rid is not None and not isinstance(rid, str):
raise ValueError("Invalid request identifier")
return Outcome(payload["ok"], rid, payload.get("result"))This sketch models the observed wallet-operation envelope only. It is not a universal parser for factory, discovery or health responses. A real client should preserve structured error details, validate operation-specific result fields on success, and avoid exposing sensitive raw payloads through exceptions.
Request validation
Use explicit network and address-type enumerations. Validate positive integer spending amounts, destination addresses and expected watch amounts before transport. Address-prefix checks alone are not sufficient validation. The engine remains authoritative and may reject a locally valid request. Keep transaction lookup models separate from wallet scopes where their fields differ.
Evolving responses
Accept additional unknown fields unless the operation requires strict validation for safety. Reject missing required success fields rather than substitute a fabricated balance or address. Preserve a distinction between unavailable, pending and confirmed values. Decode numeric fields according to the verified schema, and test boundary values before claiming cross-language compatibility.
Acceptance plan
Capture sanitized response fixtures from the real engine, including a rejected operation and a warming wallet. Test invalid JSON, unexpected types, missing result fields, HTTP errors and transport failures. For SEND, treat an unparseable response after dispatch as potentially executed. Recovery requires reconciliation, not merely a second call.
Primary reference
https://thamer.org/api
Related reading in this stage
https://thamer.org/docs/wab-sdk-designing-bitcoin-sdk
https://thamer.org/docs/wab-sdk-api-engine-application-boundaries
https://thamer.org/docs/wab-sdk-wallet-identity-management
https://thamer.org/docs/wab-sdk-cross-language-interfaces
https://thamer.org/docs/wab-sdk-authentication-credential-management
