mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-08 22:57:56 +02:00
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:
@@ -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};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user