1818#define SILKRPC_ETHBACKEND_BACKEND_HPP_
1919
2020#include < memory>
21+ #include < string>
2122
2223#include < silkrpc/config.hpp>
2324
@@ -52,13 +53,35 @@ using ProtocolVersionClient = AsyncUnaryClient<
5253 &::remote::ETHBACKEND::Stub::PrepareAsyncProtocolVersion
5354>;
5455
56+ using NetVersionClient = AsyncUnaryClient<
57+ ::remote::ETHBACKEND::Stub,
58+ ::remote::ETHBACKEND::NewStub,
59+ ::remote::NetVersionRequest,
60+ ::remote::NetVersionReply,
61+ &::remote::ETHBACKEND::Stub::PrepareAsyncNetVersion
62+ >;
63+
64+ using ClientVersionClient = AsyncUnaryClient<
65+ ::remote::ETHBACKEND::Stub,
66+ ::remote::ETHBACKEND::NewStub,
67+ ::remote::ClientVersionRequest,
68+ ::remote::ClientVersionReply,
69+ &::remote::ETHBACKEND::Stub::PrepareAsyncClientVersion
70+ >;
71+
72+
5573using EtherbaseAwaitable = unary_awaitable<asio::io_context::executor_type, EtherbaseClient, ::remote::EtherbaseReply>;
5674using ProtocolVersionAwaitable = unary_awaitable<asio::io_context::executor_type, ProtocolVersionClient, ::remote::ProtocolVersionReply>;
75+ using NetVersionAwaitable = unary_awaitable<asio::io_context::executor_type, NetVersionClient, ::remote::NetVersionReply>;
76+ using ClientVersionAwaitable = unary_awaitable<asio::io_context::executor_type, ClientVersionClient, ::remote::ClientVersionReply>;
5777
5878class BackEnd final {
5979public:
6080 explicit BackEnd (asio::io_context& context, std::shared_ptr<grpc::Channel> channel, grpc::CompletionQueue* queue)
61- : eb_awaitable_{context.get_executor (), channel, queue}, pv_awaitable_{context.get_executor (), channel, queue} {
81+ : eb_awaitable_{context.get_executor (), channel, queue},
82+ pv_awaitable_{context.get_executor (), channel, queue},
83+ nv_awaitable_{context.get_executor (), channel, queue},
84+ cv_awaitable_{context.get_executor (), channel, queue} {
6285 SILKRPC_TRACE << " BackEnd::ctor " << this << " \n " ;
6386 }
6487
@@ -83,6 +106,24 @@ class BackEnd final {
83106 co_return pv;
84107 }
85108
109+ asio::awaitable<uint64_t > get_net_version () {
110+ const auto start_time = clock_time::now ();
111+ const auto reply = co_await nv_awaitable_.async_call (asio::use_awaitable);
112+ const auto nv = reply.id ();
113+ SILKRPC_DEBUG << " BackEnd::get_net_version version=" << nv << " t=" << clock_time::since (start_time) << " \n " ;
114+ co_return nv;
115+ }
116+
117+ asio::awaitable<std::string> get_client_version () {
118+ const auto start_time = clock_time::now ();
119+ const auto reply = co_await cv_awaitable_.async_call (asio::use_awaitable);
120+ const auto cv = reply.nodename ();
121+ SILKRPC_DEBUG << " BackEnd::get_client_version version=" << cv << " t=" << clock_time::since (start_time) << " \n " ;
122+ co_return cv;
123+ }
124+
125+
126+
86127private:
87128 evmc::address address_from_H160 (const types::H160& h160) {
88129 uint64_t hi_hi = h160.hi ().hi ();
@@ -97,6 +138,8 @@ class BackEnd final {
97138
98139 EtherbaseAwaitable eb_awaitable_;
99140 ProtocolVersionAwaitable pv_awaitable_;
141+ NetVersionAwaitable nv_awaitable_;
142+ ClientVersionAwaitable cv_awaitable_;
100143};
101144
102145} // namespace silkrpc::ethbackend
0 commit comments