Fabcoin Core  0.16.2
P2P Digital Currency
JsonHelper.h
Go to the documentation of this file.
1 /*
2  This file is part of cpp-ethereum.
3 
4  cpp-ethereum is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  cpp-ethereum is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
16 */
22 #pragma once
23 
24 #include <json/json.h>
25 #include <libethcore/Common.h>
26 #include <libethcore/BlockHeader.h>
27 #include <libethereum/LogFilter.h>
28 #include <libwhisper/Message.h>
29 
30 namespace dev
31 {
32 
33 Json::Value toJson(std::map<h256, std::pair<u256, u256>> const& _storage);
34 Json::Value toJson(std::unordered_map<u256, u256> const& _storage);
35 Json::Value toJson(Address const& _address);
36 
37 namespace p2p
38 {
39 
40 Json::Value toJson(PeerSessionInfo const& _p);
41 
42 }
43 
44 namespace eth
45 {
46 
47 class Transaction;
48 class LocalisedTransaction;
49 class SealEngineFace;
50 struct BlockDetails;
51 class Interface;
52 using Transactions = std::vector<Transaction>;
53 using UncleHashes = h256s;
54 using TransactionHashes = h256s;
55 
56 Json::Value toJson(BlockHeader const& _bi, SealEngineFace* _face = nullptr);
57 //TODO: wrap these params into one structure eg. "LocalisedTransaction"
58 Json::Value toJson(Transaction const& _t, std::pair<h256, unsigned> _location, BlockNumber _blockNumber);
59 Json::Value toJson(BlockHeader const& _bi, BlockDetails const& _bd, UncleHashes const& _us, Transactions const& _ts, SealEngineFace* _face = nullptr);
60 Json::Value toJson(BlockHeader const& _bi, BlockDetails const& _bd, UncleHashes const& _us, TransactionHashes const& _ts, SealEngineFace* _face = nullptr);
61 Json::Value toJson(TransactionSkeleton const& _t);
62 Json::Value toJson(Transaction const& _t);
63 Json::Value toJson(LocalisedTransaction const& _t);
64 Json::Value toJson(TransactionReceipt const& _t);
65 Json::Value toJson(LocalisedTransactionReceipt const& _t);
66 Json::Value toJson(LocalisedLogEntry const& _e);
67 Json::Value toJson(LogEntry const& _e);
68 Json::Value toJson(std::unordered_map<h256, LocalisedLogEntries> const& _entriesByBlock);
70 TransactionSkeleton toTransactionSkeleton(Json::Value const& _json);
71 LogFilter toLogFilter(Json::Value const& _json);
72 LogFilter toLogFilter(Json::Value const& _json, Interface const& _client); // commented to avoid warning. Uncomment once in use @ PoC-7.
73 
75 {
76 public:
77  static Address fromJS(std::string const& _address);
78 };
79 
80 }
81 
82 namespace shh
83 {
84 
85 Json::Value toJson(h256 const& _h, Envelope const& _e, Message const& _m);
86 Message toMessage(Json::Value const& _json);
87 Envelope toSealed(Json::Value const& _json, Message const& _m, Secret const& _from);
88 std::pair<Topics, Public> toWatch(Json::Value const& _json);
89 
90 }
91 
92 namespace rpc
93 {
94 h256 h256fromHex(std::string const& _s);
95 }
96 
97 template <class T>
98 Json::Value toJson(std::vector<T> const& _es)
99 {
100  Json::Value res(Json::arrayValue);
101  for (auto const& e: _es)
102  res.append(toJson(e));
103  return res;
104 }
105 
106 template <class T>
107 Json::Value toJson(std::unordered_set<T> const& _es)
108 {
109  Json::Value res(Json::arrayValue);
110  for (auto const& e: _es)
111  res.append(toJson(e));
112  return res;
113 }
114 
115 template <class T>
116 Json::Value toJson(std::set<T> const& _es)
117 {
118  Json::Value res(Json::arrayValue);
119  for (auto const& e: _es)
120  res.append(toJson(e));
121  return res;
122 }
123 
124 }
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
Json::Value toJson(p2p::PeerSessionInfo const &_p)
Definition: JsonHelper.cpp:68
h256s TransactionHashes
Definition: BlockChain.h:81
pair< shh::Topics, Public > toWatch(Json::Value const &_json)
Definition: JsonHelper.cpp:522
h160 Address
An Ethereum address: 20 bytes.
Definition: Common.h:62
std::vector< Transaction > Transactions
Nice name for vector of Transaction.
Definition: Transaction.h:121
TransactionSkeleton toTransactionSkeleton(Json::Value const &_json)
Definition: JsonHelper.cpp:354
unsigned BlockNumber
Definition: Common.h:72
std::vector< LocalisedLogEntry > LocalisedLogEntries
Definition: ExtVMFace.h:156
h256s UncleHashes
Definition: BlockChain.h:82
Config::Value_type Value
dev::eth::LogFilter toLogFilter(Json::Value const &_json)
Definition: JsonHelper.cpp:387
Fixed-size raw-byte array container type, with an API optimised for storing hashes.
Definition: FixedHash.h:47
FixedHash< 32 > h256
Definition: FixedHash.h:340
Json::Value toJsonByBlock(LocalisedLogEntries const &_entries)
Definition: JsonHelper.cpp:332
Json::Value toJson(unordered_map< u256, u256 > const &_storage)
Definition: JsonHelper.cpp:41
h256 h256fromHex(std::string const &_s)
#define e(i)
Definition: sha.cpp:733
shh::Message toMessage(Json::Value const &_json)
Definition: JsonHelper.cpp:482
shh::Envelope toSealed(Json::Value const &_json, shh::Message const &_m, Secret const &_from)
Definition: JsonHelper.cpp:494
std::vector< h256 > h256s
Definition: FixedHash.h:345