@@ -40,9 +40,81 @@ BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
4040// ----------------------------------------------------------------------------
4141// TODO: performance timing header.
4242// TODO: formatted error responses.
43- // TODO: priority sort and dispatch.
43+ // TODO: formatted error responses.
44+ // TODO: priority accept media type sort and dispatch.
4445// TODO: URI path parse (see API doc).
4546
47+ // / TODO: move to own source.
48+ // / Pagination and filtering are via query string.
49+ enum targets
50+ {
51+ // / /v[]/block/hash/[bkhash] {1}
52+ // / /v[]/block/height/[height] {1}
53+ block,
54+
55+ // / /v[]/block/hash/[bkhash]/filter {1}
56+ // / /v[]/block/height/[height]/filter {1}
57+ filter,
58+
59+ // / /v[]/block/hash/[bkhash]/header {1}
60+ // / /v[]/block/height/[height]/header {1}
61+ header,
62+
63+ // / /v[]/transaction/hash/[txhash] {1}
64+ // / /v[]/block/hash/[bkhash]/transaction/position/[position] {1}
65+ // / /v[]/block/height/[height]/transaction/position/[position] {1}
66+ transaction,
67+
68+ // / /v[]/block/hash/[bkhash]/transactions {all txs in the block}
69+ // / /v[]/block/height/[height]/transactions {all txs in the block}
70+ transactions,
71+
72+ // --------------------------------------------------------------------
73+
74+ // / /v[]/input/[txhash]/[index] {1}
75+ input,
76+
77+ // / /v[]/inputs/[txhash] {all inputs in the tx}
78+ inputs,
79+
80+ // / /v[]/input/[txhash]/[index]/script {1}
81+ input_script,
82+
83+ // / /v[]/input/[txhash]/scripts {all input scripts in the tx}
84+ input_scripts,
85+
86+ // / /v[]/input/[txhash]/[index]/witness {1}
87+ input_witness,
88+
89+ // / /v[]/input/[txhash]/witnesses {all witnesses in the tx}
90+ input_witnesses,
91+
92+ // --------------------------------------------------------------------
93+
94+ // / /v[]/output/[txhash]/[index] {1}
95+ output,
96+
97+ // / /v[]/outputs/[txhash] {all outputs in the tx}
98+ outputs,
99+
100+ // / /v[]/output/[txhash]/[index]/script {1}
101+ output_script,
102+
103+ // / /v[]/output/[txhash]/scripts {all output scripts in the tx}
104+ output_scripts,
105+
106+ // / /v[]/output/[txhash]/[index]/spender {1 - confirmed}
107+ output_spender,
108+
109+ // / /v[]/output/[txhash]/spenders {all}
110+ output_spenders,
111+
112+ // --------------------------------------------------------------------
113+
114+ // / /v[]/address/[output-script-hash] {all}
115+ address
116+ };
117+
46118void protocol_explore::handle_receive_get (const code& ec,
47119 const method::get& request) NOEXCEPT
48120{
@@ -80,12 +152,7 @@ void protocol_explore::handle_receive_get(const code& ec,
80152 }
81153
82154 if (const auto parts = split (uri.path (), " /" );
83- !parts.empty () && parts.size () != two)
84- {
85- send_bad_target (*request);
86- return ;
87- }
88- else
155+ parts.size () == two)
89156 {
90157 const auto hd = parts.front () == " header" || parts.front () == " hd" ;
91158 const auto bk = parts.front () == " block" || parts.front () == " bk" ;
@@ -120,23 +187,23 @@ void protocol_explore::handle_receive_get(const code& ec,
120187 {
121188 if (const auto ptr = query.get_header (query.to_header (hash)))
122189 {
123- send_json (*request, value_from (ptr));
190+ send_json (*request, value_from (ptr), ptr-> serialized_size () );
124191 return ;
125192 }
126193 }
127194 else if (bk)
128195 {
129196 if (const auto ptr = query.get_block (query.to_header (hash), wit))
130197 {
131- send_json (*request, value_from (ptr));
198+ send_json (*request, value_from (ptr), ptr-> serialized_size (wit) );
132199 return ;
133200 }
134201 }
135202 else
136203 {
137204 if (const auto ptr = query.get_transaction (query.to_tx (hash), wit))
138205 {
139- send_json (*request, value_from (ptr));
206+ send_json (*request, value_from (ptr), ptr-> serialized_size (wit) );
140207 return ;
141208 }
142209 }
@@ -241,13 +308,13 @@ void protocol_explore::handle_receive_get(const code& ec,
241308// TODO: buffer should be reused, so set at the channel.
242309// json_value is not a sized body, so this sets chunked encoding.
243310void protocol_explore::send_json (const request& request,
244- boost::json::value&& model) NOEXCEPT
311+ boost::json::value&& model, size_t size_hint ) NOEXCEPT
245312{
246313 BC_ASSERT_MSG (stranded (), " strand" );
247314 response response{ status::ok, request.version () };
248315 add_common_headers (response, request);
249316 response.set (field::content_type, from_mime_type (json));
250- response.body () = { std::move (model), std::make_shared<flat_buffer>( 10 * 1024 * 1024 ) };
317+ response.body () = { std::move (model), size_hint };
251318 response.prepare_payload ();
252319 SEND (std::move (response), handle_complete, _1, error::success);
253320}
0 commit comments