xrpld
Loading...
Searching...
No Matches
xrpld/rpc/handlers/ledger/LedgerHeader.cpp
1#include <xrpl/protocol/LedgerHeader.h>
2
3#include <xrpld/app/ledger/LedgerToJson.h>
4#include <xrpld/rpc/detail/RPCLedgerHelpers.h>
5
6#include <xrpl/basics/strHex.h>
7#include <xrpl/json/json_value.h>
8#include <xrpl/ledger/ReadView.h>
9#include <xrpl/protocol/Serializer.h>
10#include <xrpl/protocol/jss.h>
11
12#include <memory>
13
14namespace xrpl {
15
16// {
17// ledger_hash : <ledger>
18// ledger_index : <ledger_index>
19// }
20json::Value
22{
24 auto jvResult = RPC::lookupLedger(lpLedger, context);
25
26 if (!lpLedger)
27 return jvResult;
28
29 Serializer s;
30 addRaw(lpLedger->header(), s);
31 jvResult[jss::ledger_data] = strHex(s.peekData());
32
33 // This information isn't verified: they should only use it if they trust
34 // us.
35 addJson(jvResult, {*lpLedger, &context, 0});
36
37 return jvResult;
38}
39
40} // namespace xrpl
Blob const & peekData() const
Definition Serializer.h:176
Status lookupLedger(std::shared_ptr< ReadView const > &ledger, JsonContext const &context, json::Value &result)
Looks up a ledger from a request and fills a json::Value with ledger data.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
std::string strHex(FwdIt begin, FwdIt end)
Definition strHex.h:10
void addJson(json::Value &json, LedgerFill const &fill)
Given a Ledger and options, fill a json::Value with a description of the ledger.
void addRaw(LedgerHeader const &, Serializer &, bool includeHash=false)
json::Value doLedgerHeader(RPC::JsonContext &)