forked from bcosorg/bcos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJsonHelper.h
126 lines (104 loc) · 3.8 KB
/
JsonHelper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file JsonHelper.h
* @authors:
* Gav Wood <i@gavwood.com>
* @date 2015
*/
#pragma once
#include <json/json.h>
#include <libethcore/Common.h>
#include <libethcore/BlockHeader.h>
#include <libethereum/LogFilter.h>
#include <libwhisper/Message.h>
namespace dev
{
Json::Value toJson(std::map<h256, std::pair<u256, u256>> const& _storage);
Json::Value toJson(std::unordered_map<u256, u256> const& _storage);
Json::Value toJson(Address const& _address);
namespace p2p
{
Json::Value toJson(PeerSessionInfo const& _p);
}
namespace eth
{
class Transaction;
class LocalisedTransaction;
class SealEngineFace;
class NodeConnParams;
struct BlockDetails;
class Interface;
using Transactions = std::vector<Transaction>;
using UncleHashes = h256s;
using TransactionHashes = h256s;
Json::Value toJson(BlockHeader const& _bi, SealEngineFace* _face = nullptr);
//TODO: wrap these params into one structure eg. "LocalisedTransaction"
Json::Value toJson(Transaction const& _t, std::pair<h256, unsigned> _location, BlockNumber _blockNumber);
Json::Value toJson(BlockHeader const& _bi, BlockDetails const& _bd, UncleHashes const& _us, Transactions const& _ts, SealEngineFace* _face = nullptr);
Json::Value toJson(BlockHeader const& _bi, BlockDetails const& _bd, UncleHashes const& _us, TransactionHashes const& _ts, SealEngineFace* _face = nullptr);
Json::Value toJson(TransactionSkeleton const& _t);
Json::Value toJson(Transaction const& _t);
Json::Value toJson(LocalisedTransaction const& _t);
Json::Value toJson(NodeConnParams const& _t);
Json::Value toJson(TransactionReceipt const& _t);
Json::Value toJson(LocalisedTransactionReceipt const& _t);
Json::Value toJson(LocalisedLogEntry const& _e);
Json::Value toJson(LogEntry const& _e);
Json::Value toJson(std::unordered_map<h256, LocalisedLogEntries> const& _entriesByBlock);
Json::Value toJsonByBlock(LocalisedLogEntries const& _entries);
TransactionSkeleton toTransactionSkeleton(Json::Value const& _json);
LogFilter toLogFilter(Json::Value const& _json);
LogFilter toLogFilter(Json::Value const& _json, Interface const& _client); // commented to avoid warning. Uncomment once in use @ PoC-7.
class AddressResolver
{
public:
static Address fromJS(std::string const& _address);
};
}
namespace shh
{
Json::Value toJson(h256 const& _h, Envelope const& _e, Message const& _m);
Message toMessage(Json::Value const& _json);
Envelope toSealed(Json::Value const& _json, Message const& _m, Secret const& _from);
std::pair<Topics, Public> toWatch(Json::Value const& _json);
}
namespace rpc
{
h256 h256fromHex(std::string const& _s);
}
template <class T>
Json::Value toJson(std::vector<T> const& _es)
{
Json::Value res(Json::arrayValue);
for (auto const& e: _es)
res.append(toJson(e));
return res;
}
template <class T>
Json::Value toJson(std::unordered_set<T> const& _es)
{
Json::Value res(Json::arrayValue);
for (auto const& e: _es)
res.append(toJson(e));
return res;
}
template <class T>
Json::Value toJson(std::set<T> const& _es)
{
Json::Value res(Json::arrayValue);
for (auto const& e: _es)
res.append(toJson(e));
return res;
}
}