rippled
LedgerToJson.h
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012, 2013 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 #ifndef RIPPLE_APP_LEDGER_LEDGERTOJSON_H_INCLUDED
21 #define RIPPLE_APP_LEDGER_LEDGERTOJSON_H_INCLUDED
22 
23 #include <ripple/app/ledger/Ledger.h>
24 #include <ripple/app/misc/TxQ.h>
25 #include <ripple/basics/StringUtilities.h>
26 #include <ripple/json/Object.h>
27 #include <ripple/protocol/STTx.h>
28 #include <ripple/protocol/jss.h>
29 #include <ripple/rpc/Context.h>
30 
31 namespace ripple {
32 
33 struct LedgerFill
34 {
36  ReadView const& l,
37  RPC::Context* ctx,
38  int o = 0,
41  : ledger(l), options(o), txQueue(std::move(q)), type(t), context(ctx)
42  {
43  }
44 
45  enum Options {
46  dumpTxrp = 1,
47  dumpState = 2,
48  expand = 4,
49  full = 8,
50  binary = 16,
51  ownerFunds = 32,
52  dumpQueue = 64
53  };
54 
55  ReadView const& ledger;
56  int options;
60 };
61 
66 void
68 
71 getJson(LedgerFill const&);
72 
74 template <class Object>
75 Blob
76 serializeBlob(Object const& o)
77 {
78  Serializer s;
79  o.add(s);
80  return s.peekData();
81 }
82 
84 inline std::string
86 {
87  return strHex(serializeBlob(o));
88 }
89 } // namespace ripple
90 
91 #endif
ripple::LedgerFill::dumpTxrp
@ dumpTxrp
Definition: LedgerToJson.h:46
std::string
STL class.
ripple::ltANY
@ ltANY
A special type, matching any ledger entry type.
Definition: LedgerFormats.h:176
ripple::serializeBlob
Blob serializeBlob(Object const &o)
Serialize an object to a blob.
Definition: LedgerToJson.h:76
std::vector
STL class.
ripple::LedgerFill::dumpQueue
@ dumpQueue
Definition: LedgerToJson.h:52
ripple::LedgerFill::type
LedgerEntryType type
Definition: LedgerToJson.h:58
ripple::LedgerFill::ledger
ReadView const & ledger
Definition: LedgerToJson.h:55
ripple::LedgerFill::LedgerFill
LedgerFill(ReadView const &l, RPC::Context *ctx, int o=0, std::vector< TxQ::TxDetails > q={}, LedgerEntryType t=ltANY)
Definition: LedgerToJson.h:35
ripple::LedgerFill::expand
@ expand
Definition: LedgerToJson.h:48
ripple::serializeHex
std::string serializeHex(STObject const &o)
Serialize an object to a hex string.
Definition: LedgerToJson.h:85
ripple::LedgerFill::context
RPC::Context * context
Definition: LedgerToJson.h:59
ripple::LedgerFill::full
@ full
Definition: LedgerToJson.h:49
ripple::LedgerFill::Options
Options
Definition: LedgerToJson.h:45
ripple::LedgerFill::txQueue
std::vector< TxQ::TxDetails > txQueue
Definition: LedgerToJson.h:57
ripple::Serializer
Definition: Serializer.h:39
ripple::LedgerFill::binary
@ binary
Definition: LedgerToJson.h:50
ripple::getJson
Json::Value getJson(LedgerFill const &fill)
Return a new Json::Value representing the ledger with given options.
Definition: LedgerToJson.cpp:296
ripple::STObject
Definition: STObject.h:51
ripple::ReadView
A view into a ledger.
Definition: ReadView.h:125
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::LedgerFill::ownerFunds
@ ownerFunds
Definition: LedgerToJson.h:51
ripple::LedgerEntryType
LedgerEntryType
Identifiers for on-ledger objects.
Definition: LedgerFormats.h:53
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::LedgerFill::dumpState
@ dumpState
Definition: LedgerToJson.h:47
ripple::LedgerFill
Definition: LedgerToJson.h:33
ripple::LedgerFill::options
int options
Definition: LedgerToJson.h:56
ripple::RPC::Context
The context of information needed to call an RPC.
Definition: Context.h:39
Json::Value
Represents a JSON value.
Definition: json_value.h:145