mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-11 15:19:19 +02:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user