Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
251//! Note: The class definition here is just the fallback definition used when252//! the other specialization below doesn't match. The fallback is only used for253//! capnp methods which do not have corresponding C++ methods, which in practice254//! is just the two special construct() and destroy() methods described in \ref255//! ProxyClientBase. These methods don't have any C++ parameters or return256//! types, so the trait information below reflects that.257template <typename MethodParams, typename Enable = void>258struct ProxyMethodTraits259{260using Params = TypeList<>;261using Result = void;262using Fields = Params;264template <typename ServerContext>265static void invoke(ServerContext&)266{267}268};270//! Specialization of above for proxy methods that have a271//! ProxyMethod<InterfaceName::MethodNameParams>::impl pointer-to-method272//! constant defined by generated code. This includes all functions defined in273//! the capnp interface except any construct() or destroy() methods, that are274//! assumed not to correspond to real member functions in the C++ class, and275//! will use the fallback traits definition above. The generated code this276//! specialization relies on looks like:277//!278//! struct ProxyMethod<InterfaceName::MethodNameParams>279//! {280//! static constexpr auto impl = &ClassName::methodName;281//! };282template <typename MethodParams>283struct ProxyMethodTraits<MethodParams, Require<decltype(ProxyMethod<MethodParams>::impl)>>284: public FunctionTraits<decltype(ProxyMethod<MethodParams>::impl)>285{286template <typename ServerContext, typename... Args>287static decltype(auto) invoke(ServerContext& server_context, Args&&... args)288{289return (server_context.proxy_server.m_impl.get()->*ProxyMethod<MethodParams>::impl)(std::forward<Args>(args)...);290}291};293//! Customizable (through template specialization) traits class used in generated ProxyClient implementations from294//! proxy-codegen.cpp.295template <typename MethodParams>296struct ProxyClientMethodTraits : public ProxyMethodTraits<MethodParams>297{298};300//! Customizable (through template specialization) traits class used in generated ProxyServer implementations from301//! proxy-codegen.cpp.302template <typename MethodParams>303struct ProxyServerMethodTraits : public ProxyMethodTraits<MethodParams>304{305};307static constexpr int FIELD_IN = 1; //!< See Accessor::in.308static constexpr int FIELD_OUT = 2; //!< See Accessor::out.309static constexpr int FIELD_OPTIONAL = 4; //!< See Accessor::optional.310static constexpr int FIELD_REQUESTED = 8; //!< See Accessor::requested.311static constexpr int FIELD_BOXED = 16; //!< See Accessor::boxed.313//! Accessor type holding flags that determine how to access a message field.314template <typename Field, int flags>315struct Accessor : public Field316{317//! Field is present from the Cap'n Proto Params struct (client -> server).318static const bool in = flags & FIELD_IN;319//! Field is present from the Cap'n Proto Results struct (server -> client).320static const bool out = flags & FIELD_OUT;321//! Field has a companion has{Name} boolean field in the Cap'n Proto struct.322//! This is used to represent optional primitive values (e.g. C++323//! std::optional<int>) because Cap'n Proto doesn't allow primitive fields to324//! be unset.325static const bool optional = flags & FIELD_OPTIONAL;326//! Results field has a companion want{Name} boolean field in the Params327//! struct. Used for optional output parameters (e.g. C++ int*) and set to328//! true if the caller passed a non-null pointer and wants the result.329static const bool requested = flags & FIELD_REQUESTED;330//! Field is a Cap'n Proto pointer type (struct, list, text, data,331//! interface) as opposed to a primitive type (bool, int, float, enum).332static const bool boxed = flags & FIELD_BOXED;333};335//! Wrapper around std::function for passing std::function objects between client and servers.336template <typename Fn>337class ProxyCallback;339//! Specialization of above to separate Result and Arg types.340template <typename Result, typename... Args>341class ProxyCallback<std::function<Result(Args...)>>342{343public:344virtual Result call(Args&&... args) = 0;345};347} // namespace mp349#endif // MP_PROXY_H
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.