mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-15 18:17:43 +02:00
kernel: Expose context-free block validation
This introduces a context-free validation entry point for full blocks in the kernel C and C++ APIs. * Add `btck_block_check`, a C function that wraps `CheckBlock` and runs header and body checks for a `btck_Block` using `btck_ConsensusParams`. Callers provide a `btck_BlockValidationState` to receive the result and supply a `btck_BlockCheckFlags` bitmask to control POW and merkle-root verification. * Add `btck_BlockCheckFlags` in the C API, plus the corresponding `BlockCheckFlags` scoped enum in the C++ wrapper, including a `*_ALL` convenience value. * Add `Block::Check()` to the C++ wrapper to mirror the new C function and return a bool while filling a `BlockValidationState`. * Add a test `(btck_check_block_context_free)` that verifies a known valid mainnet block passes with `BlockCheckFlags::ALL` and that truncated block data fails deserialization. Co-authored-by: yuvicc <yuvichh01@gmail.com>
This commit is contained in:
@@ -1129,6 +1129,19 @@ btck_Block* btck_block_copy(const btck_Block* block)
|
||||
return btck_Block::copy(block);
|
||||
}
|
||||
|
||||
int btck_block_check(const btck_Block* block, const btck_ConsensusParams* consensus_params, btck_BlockCheckFlags flags, btck_BlockValidationState* validation_state)
|
||||
{
|
||||
auto& state = btck_BlockValidationState::get(validation_state);
|
||||
state = BlockValidationState{};
|
||||
|
||||
const bool check_pow = (flags & btck_BlockCheckFlags_POW) != 0;
|
||||
const bool check_merkle = (flags & btck_BlockCheckFlags_MERKLE) != 0;
|
||||
|
||||
const bool result = CheckBlock(*btck_Block::get(block), state, btck_ConsensusParams::get(consensus_params), /*fCheckPOW=*/check_pow, /*fCheckMerkleRoot=*/check_merkle);
|
||||
|
||||
return result ? 1 : 0;
|
||||
}
|
||||
|
||||
size_t btck_block_count_transactions(const btck_Block* block)
|
||||
{
|
||||
return btck_Block::get(block)->vtx.size();
|
||||
|
||||
Reference in New Issue
Block a user