Repository: bitcoin/bitcoin
File: src/kernel/bitcoinkernel.cpp (C++)

Code before:
    // The KernelNotifications are copy-initialized, so the caller can free them again.
    LOCK(btck_ContextOptions::get(options).m_mutex);
    btck_ContextOptions::get(options).m_notifications = std::make_shared<KernelNotifications>(notifications);
}

void btck_context_options_set_validation_interface(btck_ContextOptions* options, btck_ValidationInterfaceCallbacks vi_cbs)
{
    LOCK(btck_ContextOptions::get(options).m_mutex);
    btck_ContextOptions::get(options).m_validation_interface = std::make_shared<KernelValidationInterface>(vi_cbs);
}

void btck_context_options_destroy(btck_ContextOptions* options)
{
    delete options;
}

btck_Context* btck_context_create(const btck_ContextOptions* options)
{
    bool sane{true};
    const ContextOptions* opts = options ? &btck_ContextOptions::get(options) : nullptr;
    auto context{std::make_shared<const Context>(opts, sane)};
    if (!sane) {
        LogError("Kernel context sanity check failed.");
        return nullptr;
    }
    return btck_Context::create(context);
}

btck_Context* btck_context_copy(const btck_Context* context)
{
    return btck_Context::copy(context);
}

int btck_context_interrupt(btck_Context* context)
{
    return (*btck_Context::get(context)->m_interrupt)() ? 0 : -1;
}

void btck_context_destroy(btck_Context* context)
{
    delete context;
}

const btck_BlockTreeEntry* btck_block_tree_entry_get_previous(const btck_BlockTreeEntry* entry)
{
    if (!btck_BlockTreeEntry::get(entry).pprev) {
        LogInfo("Genesis block has no previous.");
        return nullptr;
    }

    return btck_BlockTreeEntry::ref(btck_BlockTreeEntry::get(entry).pprev);

Review comment (suggestion):
This can be simplified:
```suggestion
    return btck_BlockValidationState::create();
```

Code after:
{
    // The KernelNotifications are copy-initialized, so the caller can free them again.
    LOCK(btck_ContextOptions::get(options).m_mutex);
    btck_ContextOptions::get(options).m_notifications = std::make_shared<KernelNotifications>(notifications);
}

void btck_context_options_set_validation_interface(btck_ContextOptions* options, btck_ValidationInterfaceCallbacks vi_cbs)
{
    LOCK(btck_ContextOptions::get(options).m_mutex);
    btck_ContextOptions::get(options).m_validation_interface = std::make_shared<KernelValidationInterface>(vi_cbs);
}

void btck_context_options_destroy(btck_ContextOptions* options)
{
    delete options;
}

btck_Context* btck_context_create(const btck_ContextOptions* options)
{
    bool sane{true};
    const ContextOptions* opts = options ? &btck_ContextOptions::get(options) : nullptr;
    auto context{std::make_shared<const Context>(opts, sane)};
    if (!sane) {
        LogError("Kernel context sanity check failed.");
        return nullptr;
    }
    return btck_Context::create(context);
}

btck_Context* btck_context_copy(const btck_Context* context)
{
    return btck_Context::copy(context);
}

int btck_context_interrupt(btck_Context* context)
{
    return (*btck_Context::get(context)->m_interrupt)() ? 0 : -1;
}

void btck_context_destroy(btck_Context* context)
{
    delete context;
}

const btck_BlockTreeEntry* btck_block_tree_entry_get_previous(const btck_BlockTreeEntry* entry)
{
    if (!btck_BlockTreeEntry::get(entry).pprev) {
        LogInfo("Genesis block has no previous.");
        return nullptr;
    }