kernel: Add notifications context option to C header

The notifications are used for notifying on connected blocks and on
warning and fatal error conditions.

The user of the C header may define callbacks that gets passed to the
internal notification object in the
`kernel_NotificationInterfaceCallbacks` struct.

Each of the callbacks take a `user_data` argument that gets populated
from the `user_data` value in the struct. It can be used to recreate the
structure containing the callbacks on the user's side, or to give the
callbacks additional contextual information.
This commit is contained in:
TheCharlatan
2024-06-03 14:51:29 +02:00
parent 9e1bac4585
commit c62f657ba3
4 changed files with 270 additions and 3 deletions

View File

@@ -60,6 +60,35 @@ public:
}
};
class TestKernelNotifications : public KernelNotifications
{
public:
void HeaderTipHandler(SynchronizationState state, int64_t height, int64_t timestamp, bool presync) override
{
BOOST_CHECK_GT(timestamp, 0);
}
void WarningSetHandler(Warning warning, std::string_view message) override
{
std::cout << "Kernel warning is set: " << message << std::endl;
}
void WarningUnsetHandler(Warning warning) override
{
std::cout << "Kernel warning was unset." << std::endl;
}
void FlushErrorHandler(std::string_view error) override
{
std::cout << error << std::endl;
}
void FatalErrorHandler(std::string_view error) override
{
std::cout << error << std::endl;
}
};
void run_verify_test(
const ScriptPubkey& spent_script_pubkey,
const Transaction& spending_tx,
@@ -401,6 +430,7 @@ BOOST_AUTO_TEST_CASE(btck_context_tests)
ChainParams regtest_params{ChainType::REGTEST};
CheckHandle(params, regtest_params);
options.SetChainParams(params);
options.SetNotifications(std::make_shared<TestKernelNotifications>());
Context context{options};
}
}