Bitcoin Core 28.99.0
P2P Digital Currency
mining.cpp
Go to the documentation of this file.
1// Copyright (c) 2024 The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
6#include <ipc/capnp/mining.capnp.proxy-types.h>
7
8#include <mp/proxy-types.h>
9
10namespace mp {
11void CustomBuildMessage(InvokeContext& invoke_context,
12 const BlockValidationState& src,
13 ipc::capnp::messages::BlockValidationState::Builder&& builder)
14{
15 if (src.IsValid()) {
16 builder.setMode(0);
17 } else if (src.IsInvalid()) {
18 builder.setMode(1);
19 } else if (src.IsError()) {
20 builder.setMode(2);
21 } else {
22 assert(false);
23 }
24 builder.setResult(static_cast<int>(src.GetResult()));
25 builder.setRejectReason(src.GetRejectReason());
26 builder.setDebugMessage(src.GetDebugMessage());
27}
28
29void CustomReadMessage(InvokeContext& invoke_context,
30 const ipc::capnp::messages::BlockValidationState::Reader& reader,
32{
33 if (reader.getMode() == 0) {
34 assert(reader.getResult() == 0);
35 assert(reader.getRejectReason().size() == 0);
36 assert(reader.getDebugMessage().size() == 0);
37 } else if (reader.getMode() == 1) {
38 dest.Invalid(static_cast<BlockValidationResult>(reader.getResult()), reader.getRejectReason(), reader.getDebugMessage());
39 } else if (reader.getMode() == 2) {
40 assert(reader.getResult() == 0);
41 dest.Error(reader.getRejectReason());
42 assert(reader.getDebugMessage().size() == 0);
43 } else {
44 assert(false);
45 }
46}
47} // namespace mp
bool IsValid() const
Definition: validation.h:106
std::string GetRejectReason() const
Definition: validation.h:110
std::string GetDebugMessage() const
Definition: validation.h:111
bool Error(const std::string &reject_reason)
Definition: validation.h:99
bool Invalid(Result result, const std::string &reject_reason="", const std::string &debug_message="")
Definition: validation.h:89
bool IsError() const
Definition: validation.h:108
Result GetResult() const
Definition: validation.h:109
bool IsInvalid() const
Definition: validation.h:107
BlockValidationResult
A "reason" why a block was invalid, suitable for determining whether the provider of the block should...
Definition: validation.h:57
Functions to serialize / deserialize common bitcoin types.
Definition: common-types.h:44
void CustomReadMessage(InvokeContext &invoke_context, const ipc::capnp::messages::BlockValidationState::Reader &reader, BlockValidationState &dest)
Definition: mining.cpp:29
void CustomBuildMessage(InvokeContext &invoke_context, const BlockValidationState &src, ipc::capnp::messages::BlockValidationState::Builder &&builder)
Definition: mining.cpp:11
assert(!tx.IsCoinBase())