OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
http_server.hpp
Go to the documentation of this file.
1// Copyright (c) 2021 MIT Digital Currency Initiative,
2// Federal Reserve Bank of Boston
3// Distributed under the MIT software license, see the accompanying
4// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6#ifndef OPENCBDC_TX_SRC_PARSEC_AGENT_HTTP_SERVER_H_
7#define OPENCBDC_TX_SRC_PARSEC_AGENT_HTTP_SERVER_H_
8
9#include "messages.hpp"
10#include "parsec/agent/impl.hpp"
18
19#include <atomic>
20#include <secp256k1.h>
21#include <thread>
22
27 public:
30
37 http_server(std::unique_ptr<server_type> srv,
38 std::shared_ptr<broker::interface> broker,
39 std::shared_ptr<logging::log> log,
40 const cbdc::parsec::config& cfg);
41
44 ~http_server() override;
45
48 auto init() -> bool override;
49
50 http_server(const http_server&) = delete;
51 auto operator=(const http_server&) -> http_server& = delete;
53 auto operator=(http_server&&) -> http_server& = delete;
54
55 private:
56 std::unique_ptr<server_type> m_srv;
57
58 enum error_code : int {
59 wallet_not_supported = -32001,
60 mining_not_supported = -32002,
61 time_travel_not_supported = -32003,
62 compiler_not_supported = -32004,
63 coinbase_not_supported = -32005,
64 uncles_not_supported = -32006,
65 unknown_method = -32099,
66 internal_error = -32603,
67 not_found = -32014,
68 invalid_address = -32015,
69 invalid_topic = -32016,
70 from_block_after_to = -32022,
71 invalid_block_parameter = -32017,
72 block_range_too_large = -32024,
73 invalid_transaction_index = -32018,
74 invalid_block_identifier = -32019,
75 execution_error = -32088,
76 };
77
78 auto request_handler(const std::string& method,
79 const Json::Value& params,
81 -> bool;
82
83 auto handle_send_raw_transaction(
84 Json::Value params,
85 const server_type::result_callback_type& callback) -> bool;
86
87 auto handle_get_transaction_count(
88 Json::Value params,
89 const server_type::result_callback_type& callback) -> bool;
90
91 static auto
92 handle_chain_id(const Json::Value& params,
94 -> bool;
95
96 auto handle_call(Json::Value params,
98 -> bool;
99
100 auto handle_send_transaction(
101 Json::Value params,
102 const server_type::result_callback_type& callback) -> bool;
103
104 static auto
105 handle_estimate_gas(const Json::Value& params,
106 const server_type::result_callback_type& callback)
107 -> bool;
108
109 static auto handle_client_version(
110 const Json::Value& params,
111 const server_type::result_callback_type& callback) -> bool;
112 static auto
113 handle_gas_price(const Json::Value& params,
114 const server_type::result_callback_type& callback)
115 -> bool;
116
117 auto handle_get_code(Json::Value params,
118 const server_type::result_callback_type& callback)
119 -> bool;
120 auto
121 handle_get_balance(Json::Value params,
122 const server_type::result_callback_type& callback)
123 -> bool;
124 static auto
125 handle_accounts(const Json::Value& params,
126 const server_type::result_callback_type& callback)
127 -> bool;
128
129 auto handle_get_transaction_by_hash(
130 Json::Value params,
131 const server_type::result_callback_type& callback) -> bool;
132
133 auto handle_get_transaction_receipt(
134 Json::Value params,
135 const server_type::result_callback_type& callback) -> bool;
136
137 auto
138 handle_not_supported(Json::Value params,
139 const server_type::result_callback_type& callback)
140 -> bool;
141
142 auto
143 handle_block_number(const Json::Value& params,
144 const server_type::result_callback_type& callback)
145 -> bool;
146 auto
147 handle_get_block(Json::Value params,
148 const server_type::result_callback_type& callback)
149 -> bool;
150 auto handle_get_block_txcount(
151 Json::Value params,
152 const server_type::result_callback_type& callback) -> bool;
153 auto
154 handle_get_block_tx(Json::Value params,
155 const server_type::result_callback_type& callback)
156 -> bool;
157 auto
158 handle_fee_history(Json::Value params,
159 const server_type::result_callback_type& callback)
160 -> bool;
161 auto handle_get_logs(Json::Value params,
162 const server_type::result_callback_type& callback)
163 -> bool;
164 auto handle_get_storage_at(
165 Json::Value params,
166 const server_type::result_callback_type& callback) -> bool;
167
168 auto handle_sha3(Json::Value params,
169 const server_type::result_callback_type& callback)
170 -> bool;
171
172 static auto
173 handle_error(const Json::Value& params,
174 const server_type::result_callback_type& callback,
175 int code,
176 const std::string& message) -> bool;
177
178 static auto
179 handle_number(const Json::Value& params,
180 const server_type::result_callback_type& callback,
181 uint64_t number) -> bool;
182
183 static auto
184 handle_boolean(const Json::Value& params,
185 const server_type::result_callback_type& callback,
186 bool result) -> bool;
187
188 auto handle_decode_raw_transaction(
189 Json::Value params,
190 const server_type::result_callback_type& callback) -> bool;
191
192 auto
193 parse_evm_log_query(const Json::Value& params,
194 const server_type::result_callback_type& callback)
195 -> std::optional<parsec::agent::runner::evm_log_query>;
196
197 auto fetch_block(Json::Value params,
198 const server_type::result_callback_type& callback,
199 const std::function<void(interface::exec_return_type,
200 cbdc::buffer)>& res_cb)
201 -> bool;
202
203 auto
204 exec_tx(const server_type::result_callback_type& json_ret_callback,
206 cbdc::buffer& runner_params,
207 bool is_readonly_run,
208 const std::function<void(interface::exec_return_type)>&
209 res_success_cb) -> bool;
210
211 auto
212 handle_unsupported(const std::string& method,
213 const Json::Value& params,
214 const server_type::result_callback_type& callback)
215 -> bool;
216
217 auto
218 handle_supported(const std::string& method,
219 const Json::Value& params,
220 const server_type::result_callback_type& callback)
221 -> std::optional<bool>;
222
223 auto handle_static(const std::string& method,
224 const Json::Value& params,
225 const server_type::result_callback_type& callback)
226 -> std::optional<bool>;
227
228 static auto extract_evm_log_query_addresses(
229 Json::Value params,
230 const server_type::result_callback_type& callback,
231 runner::evm_log_query& qry) -> bool;
232
233 static auto extract_evm_log_query_topics(
234 Json::Value params,
235 const server_type::result_callback_type& callback,
236 runner::evm_log_query& qry) -> bool;
237
238 auto extract_evm_log_query_block(
239 Json::Value params,
240 const server_type::result_callback_type& callback,
241 runner::evm_log_query& qry) -> bool;
242
243 static void handle_get_logs_result(
244 const server_type::result_callback_type& callback,
245 const cbdc::buffer& runner_params,
246 const runner::evm_log_query& qry,
248 };
249}
250
251#endif
Buffer to store and retrieve byte data.
Definition buffer.hpp:15
std::variant< return_type, error_code > exec_return_type
Return type from function execution.
auto operator=(http_server &&) -> http_server &=delete
~http_server() override
Stops listening for incoming connections, waits for existing connections to drain.
http_server(http_server &&)=delete
http_server(const http_server &)=delete
auto init() -> bool override
Starts listening for incoming connections and processing requests.
auto operator=(const http_server &) -> http_server &=delete
Asynchrounous HTTP JSON-RPC server implemented using libmicrohttpd and libjsoncpp.
std::function< void(std::optional< Json::Value >)> result_callback_type
Type alias for the callback function for returning response values to the server.
evm_runner_function
Commands accepted by the EVM contract runner.
Describes the parameters of a query on EVM logs - used to transfer these parameters from the getLogs ...
Configuration parameters for a phase two system.