rippled
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 <ripple/app/ledger/LedgerToJson.h>
21 #include <ripple/basics/strHex.h>
22 #include <ripple/ledger/ReadView.h>
23 #include <ripple/protocol/jss.h>
24 #include <ripple/rpc/impl/RPCHelpers.h>
25 
26 namespace ripple {
27 
28 // {
29 // ledger_hash : <ledger>
30 // ledger_index : <ledger_index>
31 // }
34 {
36  auto jvResult = RPC::lookupLedger(lpLedger, context);
37 
38  if (!lpLedger)
39  return jvResult;
40 
41  Serializer s;
42  addRaw(lpLedger->info(), s);
43  jvResult[jss::ledger_data] = strHex(s.peekData());
44 
45  // This information isn't verified: they should only use it if they trust
46  // us.
47  addJson(jvResult, {*lpLedger, &context, 0});
48 
49  return jvResult;
50 }
51 
52 } // namespace ripple
ripple::ReadView::info
virtual LedgerInfo const & info() const =0
Returns information about the ledger.
ripple::RPC::JsonContext
Definition: Context.h:53
std::shared_ptr
STL class.
ripple::addRaw
void addRaw(LedgerInfo const &info, Serializer &s, bool includeHash)
Definition: View.cpp:162
ripple::RPC::lookupLedger
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.
Definition: RPCHelpers.cpp:675
ripple::Serializer
Definition: Serializer.h:39
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::Serializer::peekData
Blob const & peekData() const
Definition: Serializer.h:168
ripple::addJson
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.
Definition: LedgerToJson.cpp:286
ripple::strHex
std::string strHex(FwdIt begin, FwdIt end)
Definition: strHex.h:30
ripple::doLedgerHeader
Json::Value doLedgerHeader(RPC::JsonContext &)
Definition: LedgerHeader.cpp:33
Json::Value
Represents a JSON value.
Definition: json_value.h:145