Merge bitcoin/bitcoin#34401: kernel: add serialization method for btck_BlockHeader API

577a3e74c8 test: Add check for return type in `HasToBytes` concept (yuvicc)
1ad551281a kernel: Add Block Header serialization method (yuvicc)
86662623ec Add `SpanWriter` class for zero-allocation stream writing (yuvicc)

Pull request description:

  This adds serialization for `btck_BlockHeader` API. Also, updated the `CheckHandle` to compare the byte content instead of size.

  The changes here is done in two commits. First commit adds the `SpanWriter` class and next one moves the block header serialization to `SpanWriter`. See commit message for more details.

  Follow-up to #33822 .

ACKs for top commit:
  stickies-v:
    re-ACK 577a3e74c8
  alexanderwiederin:
    ACK 577a3e74c8
  theStack:
    Code-review ACK 577a3e74c8
  w0xlt:
    ACK 577a3e74c8

Tree-SHA512: 1eda5b204588ccb23e9357f68c5529474e7d248736a371c47d8db71ba6ca95e121869514478ad7a519d190e4c30725f64fd1ef4dd9f97d2627dc4441e51458e0
This commit is contained in:
merge-script
2026-04-15 15:47:33 +01:00
6 changed files with 97 additions and 1 deletions

View File

@@ -1423,6 +1423,16 @@ uint32_t btck_block_header_get_nonce(const btck_BlockHeader* header)
return btck_BlockHeader::get(header).nNonce;
}
int btck_block_header_to_bytes(const btck_BlockHeader* header, unsigned char output[80])
{
try {
SpanWriter{std::as_writable_bytes(std::span{output, 80})} << btck_BlockHeader::get(header);
return 0;
} catch (...) {
return -1;
}
}
void btck_block_header_destroy(btck_BlockHeader* header)
{
delete header;