Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cmd/specgen/specgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const (
kindIntegerResponse = "integer-response"
kindHexStringResponse = "hex-string-response"
kindHex64StringResponse = "hex64-string-response"
kindHex160StringResponse = "hex160-string-response"
)

// GenerateMethodReference builds method reference markdown from method schemas in schemaDir.
Expand Down Expand Up @@ -487,7 +488,7 @@ func responseTypeLabel(schema *jsonschema.Schema) string {
return "Boolean"
case kindIntegerResponse:
return "Integer"
case kindHexStringResponse, kindHex64StringResponse:
case kindHexStringResponse, kindHex64StringResponse, kindHex160StringResponse:
return "String"
default:
return ""
Expand Down Expand Up @@ -588,6 +589,8 @@ func schemaKind(schema *jsonschema.Schema) string {
return kindHexStringResponse
case strings.Contains(loc, "#/$defs/Hex64StringResponse"):
return kindHex64StringResponse
case strings.Contains(loc, "#/$defs/Hex160StringResponse"):
return kindHex160StringResponse
default:
return ""
}
Expand Down
2 changes: 1 addition & 1 deletion docs/handler-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ Builds transaction output objects from a script pubkey and amount, verifies amou
#### Block Header Operations
**File:** [`block_header.json`](../testdata/block_header.json)

Parses raw block headers, rejects short inputs, verifies serialization, field getters, and exercises copy and destroy behavior.
Parses raw block headers, verifies serialization, field getters, and exercises copy and destroy behavior.

#### Block Operations
**File:** [`block.json`](../testdata/block.json)
Expand Down
6 changes: 3 additions & 3 deletions docs/methods-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ Copies a block header.
Creates a block header object from raw serialized header data.

**Parameters:**
- `raw_block_header` (string, required): Hex-encoded raw block header data. At least 80 bytes are required; if additional bytes are provided, only the first 80 bytes are used to create the header.
- `raw_block_header` (string, required): Hex-encoded raw block header data. Must be exactly 80 bytes.

**Result:** Reference - Contains the created block header (e.g., `{"ref": "$header"}`)

**Error:** `{}` if fewer than 80 bytes are provided for the serialized block header
**Error:** `{}` when operation fails

---

Expand Down Expand Up @@ -286,7 +286,7 @@ Returns the consensus-serialized block header as a hex string.
**Parameters:**
- `header` (reference, required): Block header reference

**Result:** String - Hex-encoded consensus serialization of the block header
**Result:** String - Hex-encoded 80-byte consensus serialization of the block header

**Error:** `{}` when operation fails

Expand Down
4 changes: 2 additions & 2 deletions docs/schemas/btck_block_header_create.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"additionalProperties": false,
"properties": {
"raw_block_header": {
"type": "string",
"description": "Hex-encoded raw block header data. At least 80 bytes are required; if additional bytes are provided, only the first 80 bytes are used to create the header."
"$ref": "./shared.json#/$defs/Hex160String",
"description": "Hex-encoded raw block header data. Must be exactly 80 bytes."
}
},
"required": [
Expand Down
3 changes: 1 addition & 2 deletions docs/schemas/btck_block_header_create.response.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"description": "Contains the created block header (e.g., `{\"ref\": \"$header\"}`)"
},
{
"$ref": "./shared.json#/$defs/GenericErrorResponse",
"description": "`{}` if fewer than 80 bytes are provided for the serialized block header"
"$ref": "./shared.json#/$defs/GenericErrorResponse"
}
]
}
4 changes: 2 additions & 2 deletions docs/schemas/btck_block_header_to_bytes.response.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"$schema": "https://json-schema.org/draft/2020-12/schema",
"oneOf": [
{
"$ref": "./shared.json#/$defs/HexStringResponse",
"description": "Hex-encoded consensus serialization of the block header"
"$ref": "./shared.json#/$defs/Hex160StringResponse",
"description": "Hex-encoded 80-byte consensus serialization of the block header"
},
{
"$ref": "./shared.json#/$defs/GenericErrorResponse"
Expand Down
13 changes: 13 additions & 0 deletions docs/schemas/shared.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@
"error": { "type": "null" }
}
},
"Hex160String": {
"type": "string",
"pattern": "^[0-9a-f]{160}$"
},
"Hex160StringResponse": {
"type": "object",
"additionalProperties": false,
"required": ["result"],
"properties": {
"result": { "$ref": "#/$defs/Hex160String" },
"error": { "type": "null" }
}
},
"HexString": {
"type": "string",
"pattern": "^[0-9a-f]*$"
Expand Down
68 changes: 20 additions & 48 deletions testdata/block_header.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,13 @@
{
"title": "Block Header Operations",
"description": "Covers block header parsing, invalid-input rejection, serialization, field getters, copy equality, and object cleanup using the mainnet genesis block header",
"description": "Covers block header parsing, serialization, field getters, copy equality, and object cleanup using the mainnet genesis block header",
"stateful": true,
"tests": [
{
"description": "Rejects empty raw block header bytes",
"description": "Creates a header from the mainnet genesis block header bytes",
"request": {
"id": "block_header#1",
"method": "btck_block_header_create",
"params": {
"raw_block_header": ""
},
"ref": "$empty_header"
},
"expected_response": {
"error": {}
}
},
{
"description": "Rejects raw header bytes shorter than the required 80-byte block header",
"request": {
"id": "block_header#2",
"method": "btck_block_header_create",
"params": {
"raw_block_header": "0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a29ab5f49ffff001d1dac2b"
},
"ref": "$short_header"
},
"expected_response": {
"error": {}
}
},
{
"description": "Creates a header from the exact 80-byte mainnet genesis block header",
"request": {
"id": "block_header#3",
"method": "btck_block_header_create",
"params": {
"raw_block_header": "0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a29ab5f49ffff001d1dac2b7c"
},
Expand All @@ -50,7 +22,7 @@
{
"description": "Verifies block header serialization round-trips to the original bytes",
"request": {
"id": "block_header#4",
"id": "block_header#2",
"method": "btck_block_header_to_bytes",
"params": {
"header": {
Expand All @@ -63,9 +35,9 @@
}
},
{
"description": "Gets the hash for the exact genesis block header",
"description": "Gets the hash for the genesis block header",
"request": {
"id": "block_header#5",
"id": "block_header#3",
"method": "btck_block_header_get_hash",
"params": {
"header": {
Expand All @@ -81,9 +53,9 @@
}
},
{
"description": "Verifies the serialized exact header hash matches the mainnet genesis block hash",
"description": "Verifies the serialized header hash matches the mainnet genesis block hash",
"request": {
"id": "block_header#6",
"id": "block_header#4",
"method": "btck_block_hash_to_bytes",
"params": {
"block_hash": {
Expand All @@ -98,7 +70,7 @@
{
"description": "Gets the previous block hash from the genesis block header",
"request": {
"id": "block_header#7",
"id": "block_header#5",
"method": "btck_block_header_get_prev_hash",
"params": {
"header": {
Expand All @@ -116,7 +88,7 @@
{
"description": "Verifies the genesis previous block hash is all zero bytes",
"request": {
"id": "block_header#8",
"id": "block_header#6",
"method": "btck_block_hash_to_bytes",
"params": {
"block_hash": {
Expand All @@ -131,7 +103,7 @@
{
"description": "Verifies the genesis block header version",
"request": {
"id": "block_header#9",
"id": "block_header#7",
"method": "btck_block_header_get_version",
"params": {
"header": {
Expand All @@ -146,7 +118,7 @@
{
"description": "Verifies the genesis block header timestamp",
"request": {
"id": "block_header#10",
"id": "block_header#8",
"method": "btck_block_header_get_timestamp",
"params": {
"header": {
Expand All @@ -161,7 +133,7 @@
{
"description": "Verifies the genesis block header proof-of-work bits",
"request": {
"id": "block_header#11",
"id": "block_header#9",
"method": "btck_block_header_get_bits",
"params": {
"header": {
Expand All @@ -176,7 +148,7 @@
{
"description": "Verifies the genesis block header nonce",
"request": {
"id": "block_header#12",
"id": "block_header#10",
"method": "btck_block_header_get_nonce",
"params": {
"header": {
Expand All @@ -191,7 +163,7 @@
{
"description": "Copies the parsed genesis block header",
"request": {
"id": "block_header#13",
"id": "block_header#11",
"method": "btck_block_header_copy",
"params": {
"header": {
Expand All @@ -209,7 +181,7 @@
{
"description": "Destroys the original header after the copy has been created",
"request": {
"id": "block_header#14",
"id": "block_header#12",
"method": "btck_block_header_destroy",
"params": {
"header": {
Expand All @@ -222,7 +194,7 @@
{
"description": "Gets the hash from the copied header after the original header is destroyed",
"request": {
"id": "block_header#15",
"id": "block_header#13",
"method": "btck_block_header_get_hash",
"params": {
"header": {
Expand All @@ -240,7 +212,7 @@
{
"description": "Destroys the copied header after deriving its hash",
"request": {
"id": "block_header#16",
"id": "block_header#14",
"method": "btck_block_header_destroy",
"params": {
"header": {
Expand All @@ -253,7 +225,7 @@
{
"description": "Verifies the copied header hash equals the original header hash",
"request": {
"id": "block_header#17",
"id": "block_header#15",
"method": "btck_block_hash_equals",
"params": {
"hash1": {
Expand All @@ -271,7 +243,7 @@
{
"description": "Destroys the original header hash after comparison",
"request": {
"id": "block_header#18",
"id": "block_header#16",
"method": "btck_block_hash_destroy",
"params": {
"block_hash": {
Expand All @@ -284,7 +256,7 @@
{
"description": "Destroys the hash returned for the copied header",
"request": {
"id": "block_header#19",
"id": "block_header#17",
"method": "btck_block_hash_destroy",
"params": {
"block_hash": {
Expand Down
Loading