This document defines the protocol that handler binaries must implement to be compatible with the conformance test runner.
Handlers communicate with the test runner via stdin/stdout:
- Input: JSON requests on stdin (one per line)
- Output: JSON responses on stdout (one per line)
- Lifecycle: Handler starts, processes requests until stdin closes, then exits
{
"id": "unique-request-id",
"method": "method_name",
"params": { /* method-specific parameters */ },
"ref": "reference-name"
}Fields:
id(string, required): Unique identifier for this requestmethod(string, required): The operation to perform. Each unique method must be implemented by the handler to exercise the corresponding binding API operation.params(object, optional): Method-specific parametersref(string, optional): Reference name for storing the returned object. Required for methods that return object references (see Object References and Registry)
{
"result": null,
"error": {
"code": {
"type": "error_type",
"member": "ERROR_MEMBER_NAME"
}
}
}Fields:
result(any, optional): The return value, ornullfor void/nullptr operations. Must benullon error. For methods that return object references, the result is a reference type object (see Reference Type)error(object, optional): Error details. Must benullon success. An empty object{}is used to indicate an error is raised without further details, it is NOT equivalent tonullcode(object, optional): Error code detailstype(string, required): Error type (e.g., "btck_ScriptVerifyStatus")member(string, required): Specific error member (e.g., "ERROR_INVALID_FLAGS_COMBINATION")
For methods that return object references, the result is an object containing the reference name:
{
"ref": "reference-name"
}Fields:
ref(string, required): The reference name from the request'sreffield
Note: Throughout this protocol, an omitted field is semantically equivalent to null.
- Input Processing: Read JSON requests line-by-line from stdin
- Response Order: Responses must match request order (process sequentially)
- Error Handling: Return error responses for invalid requests or failed operations
- Exit Behavior: Exit cleanly when stdin closes
Many operations return objects (contexts, blocks, chains, etc.) that must persist across requests. The protocol uses named references and a registry pattern:
Creating Objects: Methods that return objects require a ref field in the request. The handler stores the object in a registry under that name and returns a reference type object containing the reference name.
// Request
{"id": "1", "method": "btck_context_create", "params": {...}, "ref": "$ctx1"}
// Response
{"id": "1", "result": {"ref": "$ctx1"}, "error": null}
// Handler action: registry["$ctx1"] = created_context_ptrUsing Objects: When a parameter is marked as (reference, required), the runner passes a reference type object and the handler extracts the reference name to look it up:
// Request
{"id": "2", "method": "btck_chainstate_manager_create", "params": {"context": {"ref": "$ctx1"}}, "ref": "$csm1"}
// Response
{"id": "2", "result": {"ref": "$csm1"}, "error": null}
// Handler action: Extract ref from params.context, look up registry["$ctx1"], create manager, store as registry["$csm1"]Implementation: Handlers must maintain a registry (map of reference names to object pointers) throughout their lifetime. Objects remain alive until explicitly destroyed or handler exit.
The conformance tests are organized into suites, each testing a specific aspect of the Bitcoin Kernel bindings. Test files are located in ../testdata/.
File: script_verify_success.json
Test cases where the script verification operation executes successfully and returns a boolean result (true for valid scripts, false for invalid scripts).
File: script_verify_errors.json
Test cases where the verification operation fails to determine validity of the script due to bad user input.
File: chain.json
Sets up blocks, checks chain state, and verifies that the chain tip changes as expected after a reorg scenario.
Methods are grouped by functional area. Each method documents its parameters, return values, and possible errors.
Creates a context with specified chain parameters.
Parameters:
chain_parameters(object, required):chain_type(string, required): Chain type ("btck_ChainType_MAINNET", "btck_ChainType_TESTNET", "btck_ChainType_TESTNET_4", "btck_ChainType_SIGNET", "btck_ChainType_REGTEST")
Result: Reference type - Object containing the reference name from the request ref field (e.g., {"ref": "$context"})
Error: {} when operation fails (C API returned null)
Destroys a context and frees associated resources.
Parameters:
context(reference, required): Context reference to destroy
Result: null (void operation)
Error: null (cannot return error)
Creates a chainstate manager from a context.
Parameters:
context(reference, required): Context reference frombtck_context_create
Result: Reference type - Object containing the reference name from the request ref field (e.g., {"ref": "$chainstate_manager"})
Error: {} when operation fails (C API returned null)
Retrieves the currently active chain from the chainstate manager.
Parameters:
chainstate_manager(reference, required): Chainstate manager reference
Result: Reference type - Object containing the reference name from the request ref field (e.g., {"ref": "$chain"})
Error: null (cannot return error)
Processes a block through validation checks, disk storage, and UTXO set validation; successful processing does not indicate block validity.
Parameters:
chainstate_manager(reference, required): Chainstate manager referenceblock(reference, required): Block reference frombtck_block_create
Result: Object containing:
new_block(boolean):trueif this block was not processed before,falseotherwise
Error: {} when processing fails
Destroys a chainstate manager and frees associated resources.
Parameters:
chainstate_manager(reference, required): Chainstate manager reference to destroy
Result: null (void operation)
Error: null (cannot return error)
Gets the current height of the active chain.
Parameters:
chain(reference, required): Chain reference frombtck_chainstate_manager_get_active_chain
Result: Integer - The chain height (0 = genesis)
Error: null (cannot return error)
Retrieves a block tree entry at a specific height in the chain.
Parameters:
chain(reference, required): Chain referenceblock_height(integer, required): Height to query
Result: Reference type - Object containing the reference name from the request ref field (e.g., {"ref": "$block_tree_entry"})
Error: {} when height is out of bounds (C API returned null)
Checks whether a block tree entry is part of the active chain.
Parameters:
chain(reference, required): Chain referenceblock_tree_entry(reference, required): Block tree entry reference to check
Result: Boolean - true if block is in the active chain, false otherwise
Error: null (cannot return error)
Creates a block object from raw block data.
Parameters:
raw_block(string, required): Hex-encoded raw block data
Result: Reference type - Object containing the reference name from the request ref field (e.g., {"ref": "$block"})
Error: {} when operation fails (C API returned null)
Gets the block hash from a block tree entry.
Parameters:
block_tree_entry(reference, required): Block tree entry reference frombtck_chain_get_by_height
Result: String - The block hash (hex-encoded, 64 characters)
Error: null (cannot return error)
Verifies a script pubkey against spending conditions.
Parameters:
script_pubkey(string): Hex-encoded script pubkey to be spentamount(number): Amount of the script pubkey's associated output. May be zero if the witness flag is not settx_to(string): Hex-encoded transaction spending the script_pubkeyinput_index(number): Index of the input in tx_to spending the script_pubkeyflags(array of strings): Script verification flags controlling validation constraints. Valid flags include:btck_ScriptVerificationFlags_P2SHbtck_ScriptVerificationFlags_DERSIGbtck_ScriptVerificationFlags_NULLDUMMYbtck_ScriptVerificationFlags_CHECKLOCKTIMEVERIFYbtck_ScriptVerificationFlags_CHECKSEQUENCEVERIFYbtck_ScriptVerificationFlags_WITNESSbtck_ScriptVerificationFlags_TAPROOT
spent_outputs(array of objects): Array of outputs spent by the transaction. May be empty if the taproot flag is not set. Each object contains:script_pubkey(string): Hex-encoded script pubkey of the spent outputamount(number): Amount in satoshis of the spent output
Result: Boolean - true if script is valid, false if invalid
Error: On error, returns error code with type btck_ScriptVerifyStatus and member can be one of:
ERROR_INVALID_FLAGS_COMBINATION- Invalid or inconsistent verification flags were provided. This occurs when the suppliedscript_verify_flagscombination violates internal consistency rules.ERROR_SPENT_OUTPUTS_REQUIRED- Spent outputs are required but were not provided (e.g., for Taproot verification).