Skip to content

Commit e373642

Browse files
committed
Add capnp mining interface
1 parent 513a033 commit e373642

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

src/ipc/capnp/common-types.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,24 @@ void CustomBuildField(
222222
auto result = output.init(data.size());
223223
memcpy(result.begin(), data.data(), data.size());
224224
}
225+
226+
//! Overload CustomBuildField and CustomReadField to serialize std::chrono
227+
//! parameters and return values as numbers.
228+
//! TODO: Could add compile time checks to make sure types are compatible and
229+
//! precision is not lost.
230+
template <class Rep, class Period, typename Value, typename Output>
231+
void CustomBuildField(TypeList<std::chrono::duration<Rep, Period>>, Priority<1>, InvokeContext& invoke_context, Value&& value,
232+
Output&& output)
233+
{
234+
output.set(value.count());
235+
}
236+
237+
template <class Rep, class Period, typename Input, typename ReadDest>
238+
decltype(auto) CustomReadField(TypeList<std::chrono::duration<Rep, Period>>, Priority<1>, InvokeContext& invoke_context,
239+
Input&& input, ReadDest&& read_dest)
240+
{
241+
return read_dest.construct(input.get());
242+
}
225243
} // namespace mp
226244

227245
#endif // BITCOIN_IPC_CAPNP_COMMON_TYPES_H

src/ipc/capnp/mining.capnp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,25 @@ interface Mining $Proxy.wrap("interfaces::Mining") {
1717
isTestChain @0 (context :Proxy.Context) -> (result: Bool);
1818
isInitialBlockDownload @1 (context :Proxy.Context) -> (result: Bool);
1919
getTipHash @2 (context :Proxy.Context) -> (result: Data);
20-
createNewBlock @3 (context :Proxy.Context, scriptPubKey: Data, useMempool: Bool) -> (result: CBlockTemplate);
20+
createNewBlock @3 (scriptPubKey: Data, options: BlockCreateOptions) -> (result: BlockTemplate);
2121
processNewBlock @4 (context :Proxy.Context, block: Data) -> (newBlock: Bool, result: Bool);
2222
getTransactionsUpdated @5 (context :Proxy.Context) -> (result: UInt32);
2323
testBlockValidity @6 (context :Proxy.Context, block: Data, checkMerkleRoot: Bool) -> (state: BlockValidationState, result: Bool);
24+
getTipHeight @7 (context :Proxy.Context) -> (hasResult: Bool, result: Int32);
25+
waitTipChanged @8 (timeout: Float64) -> (result: BlockInfo);
26+
waitFeesChanged @9 (timeout: Float64, tip: Data, feeDelta: Int64, feesBefore: Int64) -> (result: Bool);
27+
}
28+
29+
interface BlockTemplate $Proxy.wrap("interfaces::BlockTemplate") {
30+
getBlockHeader @0 (context: Proxy.Context) -> (result: Data);
31+
getBlock @1 (context: Proxy.Context) -> (result: Data);
32+
getTxFees @2 (context: Proxy.Context) -> (result: List(Int64));
33+
getTxSigops @3 (context: Proxy.Context) -> (result: List(Int64));
34+
getCoinbaseTx @4 (context: Proxy.Context) -> (result: Data);
35+
getCoinbaseCommitment @5 (context: Proxy.Context) -> (result: Data);
36+
getWitnessCommitmentIndex @6 (context: Proxy.Context) -> (result: Int32);
37+
getCoinbaseMerklePath @7 (context: Proxy.Context) -> (result: List(Data));
38+
submitSolution @8 (context: Proxy.Context, version: UInt32, timestamp: UInt32, nonce: UInt32, coinbase :Data) -> (result: Bool);
2439
}
2540

2641
struct CBlockTemplate $Proxy.wrap("node::CBlockTemplate")
@@ -37,3 +52,14 @@ struct BlockValidationState {
3752
rejectReason @2 :Text;
3853
debugMessage @3 :Text;
3954
}
55+
56+
struct BlockInfo {
57+
hash @0 :Data;
58+
height @1 :Int32;
59+
}
60+
61+
struct BlockCreateOptions $Proxy.wrap("node::BlockCreateOptions") {
62+
useMempool @0 :Bool $Proxy.name("use_mempool");
63+
coinbaseMaxAdditionalWeight @1 :UInt64 $Proxy.name("coinbase_max_additional_weight");
64+
coinbaseOutputMaxAdditionalSigops @2 :UInt64 $Proxy.name("coinbase_output_max_additional_sigops");
65+
}

0 commit comments

Comments
 (0)