Skip to content

Commit e21307e

Browse files
committed
Implement protocol_bitcoind::handle_get_best_block_hash().
1 parent 94aed74 commit e21307e

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/protocols/protocol_bitcoind.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,17 +146,29 @@ void protocol_bitcoind::handle_receive_post(const code& ec,
146146
}
147147

148148
// TODO: post-process request.
149+
// github.com/bitcoin/bitcoin/blob/master/doc/JSON-RPC-interface.md
149150
if (const auto code = dispatcher_.notify(request))
150151
stop(code);
151152
}
152153

153154
// Handlers.
154155
// ----------------------------------------------------------------------------
156+
// TODO: precompute size for buffer hints.
155157

158+
// {"jsonrpc": "1.0", "id": "curltest", "method": "getbestblockhash", "params": []}
156159
bool protocol_bitcoind::handle_get_best_block_hash(const code& ec,
157160
interface::get_best_block_hash) NOEXCEPT
158161
{
159-
return !ec;
162+
if (stopped(ec))
163+
return false;
164+
165+
const auto& query = archive();
166+
const auto hash = query.get_header_key(query.to_confirmed(
167+
query.get_top_confirmed()));
168+
169+
const response_t model{ .result = encode_hash(hash) };
170+
send_json(value_from(model), two * system::hash_size);
171+
return true;
160172
}
161173

162174
// method<"getblock", string_t, optional<0_u32>>{ "blockhash", "verbosity" },

0 commit comments

Comments
 (0)