blob: 0f9533c1c732aec5e8ee307f5f6debb313345572 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
// Copyright (c) 2024 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <ipc/capnp/mining-types.h>
#include <ipc/capnp/mining.capnp.proxy-types.h>
#include <mp/proxy-types.h>
namespace mp {
void CustomBuildMessage(InvokeContext& invoke_context,
const BlockValidationState& src,
ipc::capnp::messages::BlockValidationState::Builder&& builder)
{
if (src.IsValid()) {
builder.setMode(0);
} else if (src.IsInvalid()) {
builder.setMode(1);
} else if (src.IsError()) {
builder.setMode(2);
} else {
assert(false);
}
builder.setResult(static_cast<int>(src.GetResult()));
builder.setRejectReason(src.GetRejectReason());
builder.setDebugMessage(src.GetDebugMessage());
}
void CustomReadMessage(InvokeContext& invoke_context,
const ipc::capnp::messages::BlockValidationState::Reader& reader,
BlockValidationState& dest)
{
if (reader.getMode() == 0) {
assert(reader.getResult() == 0);
assert(reader.getRejectReason().size() == 0);
assert(reader.getDebugMessage().size() == 0);
} else if (reader.getMode() == 1) {
dest.Invalid(static_cast<BlockValidationResult>(reader.getResult()), reader.getRejectReason(), reader.getDebugMessage());
} else if (reader.getMode() == 2) {
assert(reader.getResult() == 0);
dest.Error(reader.getRejectReason());
assert(reader.getDebugMessage().size() == 0);
} else {
assert(false);
}
}
} // namespace mp
|