kernel: Add Block Header serialization method

Add `btck_block_header_to_bytes` serialization method to serialize a
`btck_BlockHeader` into an 80-byte buffer using `SpanWriter` to ensure
zero-allocation serialization.
This commit is contained in:
yuvicc
2026-04-01 20:12:39 +05:30
parent 86662623ec
commit 1ad551281a
4 changed files with 40 additions and 0 deletions

View File

@@ -1390,6 +1390,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;