rippled
Loading...
Searching...
No Matches
xrpld/rpc/handlers/LedgerHeader.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012-2014 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <xrpld/app/ledger/LedgerToJson.h>
21#include <xrpld/rpc/detail/RPCHelpers.h>
22
23#include <xrpl/basics/strHex.h>
24#include <xrpl/ledger/ReadView.h>
25#include <xrpl/protocol/jss.h>
26
27namespace ripple {
28
29// {
30// ledger_hash : <ledger>
31// ledger_index : <ledger_index>
32// }
35{
37 auto jvResult = RPC::lookupLedger(lpLedger, context);
38
39 if (!lpLedger)
40 return jvResult;
41
42 Serializer s;
43 addRaw(lpLedger->info(), s);
44 jvResult[jss::ledger_data] = strHex(s.peekData());
45
46 // This information isn't verified: they should only use it if they trust
47 // us.
48 addJson(jvResult, {*lpLedger, &context, 0});
49
50 return jvResult;
51}
52
53} // namespace ripple
Represents a JSON value.
Definition json_value.h:149
Blob const & peekData() const
Definition Serializer.h:202
Status lookupLedger(std::shared_ptr< ReadView const > &ledger, JsonContext &context, Json::Value &result)
Look up a ledger from a request and fill a Json::Result with the data representing a ledger.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
void addJson(Json::Value &json, LedgerFill const &fill)
Given a Ledger and options, fill a Json::Object or Json::Value with a description of the ledger.
std::string strHex(FwdIt begin, FwdIt end)
Definition strHex.h:30
Json::Value doLedgerHeader(RPC::JsonContext &)
void addRaw(LedgerHeader const &, Serializer &, bool includeHash=false)