Electroneum
Loading...
Searching...
No Matches
json_object.cpp
Go to the documentation of this file.
1// Copyright (c) 2016-2019, The Monero Project
2//
3// All rights reserved.
4//
5// Redistribution and use in source and binary forms, with or without modification, are
6// permitted provided that the following conditions are met:
7//
8// 1. Redistributions of source code must retain the above copyright notice, this list of
9// conditions and the following disclaimer.
10//
11// 2. Redistributions in binary form must reproduce the above copyright notice, this list
12// of conditions and the following disclaimer in the documentation and/or other
13// materials provided with the distribution.
14//
15// 3. Neither the name of the copyright holder nor the names of its contributors may be
16// used to endorse or promote products derived from this software without specific
17// prior written permission.
18//
19// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29#include "json_object.h"
30
31#include <boost/range/adaptor/transformed.hpp>
32#include <boost/variant/apply_visitor.hpp>
33#include <limits>
34#include <type_traits>
35#include "string_tools.h"
36
37namespace cryptonote
38{
39
40namespace json
41{
42
43namespace
44{
45 template<typename Source, typename Destination>
46 constexpr bool precision_loss()
47 {
48 return
49 std::numeric_limits<Destination>::is_signed != std::numeric_limits<Source>::is_signed ||
50 std::numeric_limits<Destination>::min() > std::numeric_limits<Source>::min() ||
51 std::numeric_limits<Destination>::max() < std::numeric_limits<Source>::max();
52 }
53
54 template<typename Source, typename Type>
55 void convert_numeric(Source source, Type& i)
56 {
57 static_assert(
58 (std::is_same<Type, char>() && std::is_same<Source, int>()) ||
59 std::numeric_limits<Source>::is_signed == std::numeric_limits<Type>::is_signed,
60 "comparisons below may have undefined behavior"
61 );
62 if (source < std::numeric_limits<Type>::min())
63 {
64 throw WRONG_TYPE{"numeric underflow"};
65 }
66 if (std::numeric_limits<Type>::max() < source)
67 {
68 throw WRONG_TYPE{"numeric overflow"};
69 }
70 i = Type(source);
71 }
72
73 template<typename Type>
74 void to_int(const rapidjson::Value& val, Type& i)
75 {
76 if (!val.IsInt())
77 {
78 throw WRONG_TYPE{"integer"};
79 }
80 convert_numeric(val.GetInt(), i);
81 }
82 template<typename Type>
83 void to_int64(const rapidjson::Value& val, Type& i)
84 {
85 if (!val.IsInt64())
86 {
87 throw WRONG_TYPE{"integer"};
88 }
89 convert_numeric(val.GetInt64(), i);
90 }
91
92 template<typename Type>
93 void to_uint(const rapidjson::Value& val, Type& i)
94 {
95 if (!val.IsUint())
96 {
97 throw WRONG_TYPE{"unsigned integer"};
98 }
99 convert_numeric(val.GetUint(), i);
100 }
101 template<typename Type>
102 void to_uint64(const rapidjson::Value& val, Type& i)
103 {
104 if (!val.IsUint64())
105 {
106 throw WRONG_TYPE{"unsigned integer"};
107 }
108 convert_numeric(val.GetUint64(), i);
109 }
110}
111
112void toJsonValue(rapidjson::Document& doc, const std::string& i, rapidjson::Value& val)
113{
114 val = rapidjson::Value(i.c_str(), doc.GetAllocator());
115}
116
117void fromJsonValue(const rapidjson::Value& val, std::string& str)
118{
119 if (!val.IsString())
120 {
121 throw WRONG_TYPE("string");
122 }
123
124 str = val.GetString();
125}
126
127void toJsonValue(rapidjson::Document& doc, bool i, rapidjson::Value& val)
128{
129 val.SetBool(i);
130}
131
132void fromJsonValue(const rapidjson::Value& val, bool& b)
133{
134 if (!val.IsBool())
135 {
136 throw WRONG_TYPE("boolean");
137 }
138 b = val.GetBool();
139}
140
141void fromJsonValue(const rapidjson::Value& val, unsigned char& i)
142{
143 to_uint(val, i);
144}
145
146void fromJsonValue(const rapidjson::Value& val, char& i)
147{
148 to_int(val, i);
149}
150
151void fromJsonValue(const rapidjson::Value& val, signed char& i)
152{
153 to_int(val, i);
154}
155
156void fromJsonValue(const rapidjson::Value& val, unsigned short& i)
157{
158 to_uint(val, i);
159}
160
161void fromJsonValue(const rapidjson::Value& val, short& i)
162{
163 to_int(val, i);
164}
165
166void toJsonValue(rapidjson::Document& doc, const unsigned int i, rapidjson::Value& val)
167{
168 val = rapidjson::Value(i);
169}
170
171void fromJsonValue(const rapidjson::Value& val, unsigned int& i)
172{
173 to_uint(val, i);
174}
175
176void toJsonValue(rapidjson::Document& doc, const int i, rapidjson::Value& val)
177{
178 val = rapidjson::Value(i);
179}
180
181void fromJsonValue(const rapidjson::Value& val, int& i)
182{
183 to_int(val, i);
184}
185
186void toJsonValue(rapidjson::Document& doc, const unsigned long long i, rapidjson::Value& val)
187{
188 static_assert(!precision_loss<unsigned long long, std::uint64_t>(), "precision loss");
189 val = rapidjson::Value(std::uint64_t(i));
190}
191
192void fromJsonValue(const rapidjson::Value& val, unsigned long long& i)
193{
194 to_uint64(val, i);
195}
196
197void toJsonValue(rapidjson::Document& doc, const long long i, rapidjson::Value& val)
198{
199 static_assert(!precision_loss<long long, std::int64_t>(), "precision loss");
200 val = rapidjson::Value(std::int64_t(i));
201}
202
203void fromJsonValue(const rapidjson::Value& val, long long& i)
204{
205 to_int64(val, i);
206}
207
208void fromJsonValue(const rapidjson::Value& val, unsigned long& i)
209{
210 to_uint64(val, i);
211}
212
213void fromJsonValue(const rapidjson::Value& val, long& i)
214{
215 to_int64(val, i);
216}
217
218void toJsonValue(rapidjson::Document& doc, const cryptonote::transaction& tx, rapidjson::Value& val)
219{
220 val.SetObject();
221
223 INSERT_INTO_JSON_OBJECT(val, doc, unlock_time, tx.unlock_time);
224 INSERT_INTO_JSON_OBJECT(val, doc, inputs, tx.vin);
225 INSERT_INTO_JSON_OBJECT(val, doc, outputs, tx.vout);
226 INSERT_INTO_JSON_OBJECT(val, doc, extra, tx.extra);
227 INSERT_INTO_JSON_OBJECT(val, doc, signatures, tx.signatures);
228 INSERT_INTO_JSON_OBJECT(val, doc, ringct, tx.rct_signatures);
229}
230
231
232void fromJsonValue(const rapidjson::Value& val, cryptonote::transaction& tx)
233{
234 if (!val.IsObject())
235 {
236 throw WRONG_TYPE("json object");
237 }
238
240 GET_FROM_JSON_OBJECT(val, tx.unlock_time, unlock_time);
241 GET_FROM_JSON_OBJECT(val, tx.vin, inputs);
242 GET_FROM_JSON_OBJECT(val, tx.vout, outputs);
243 GET_FROM_JSON_OBJECT(val, tx.extra, extra);
244 GET_FROM_JSON_OBJECT(val, tx.signatures, signatures);
245 GET_FROM_JSON_OBJECT(val, tx.rct_signatures, ringct);
246}
247
248void toJsonValue(rapidjson::Document& doc, const cryptonote::block& b, rapidjson::Value& val)
249{
250 val.SetObject();
251
252 INSERT_INTO_JSON_OBJECT(val, doc, major_version, b.major_version);
253 INSERT_INTO_JSON_OBJECT(val, doc, minor_version, b.minor_version);
254 INSERT_INTO_JSON_OBJECT(val, doc, timestamp, b.timestamp);
255 INSERT_INTO_JSON_OBJECT(val, doc, prev_id, b.prev_id);
256 INSERT_INTO_JSON_OBJECT(val, doc, nonce, b.nonce);
257 INSERT_INTO_JSON_OBJECT(val, doc, miner_tx, b.miner_tx);
258 INSERT_INTO_JSON_OBJECT(val, doc, tx_hashes, b.tx_hashes);
259}
260
261
262void fromJsonValue(const rapidjson::Value& val, cryptonote::block& b)
263{
264 if (!val.IsObject())
265 {
266 throw WRONG_TYPE("json object");
267 }
268
269 GET_FROM_JSON_OBJECT(val, b.major_version, major_version);
270 GET_FROM_JSON_OBJECT(val, b.minor_version, minor_version);
271 GET_FROM_JSON_OBJECT(val, b.timestamp, timestamp);
272 GET_FROM_JSON_OBJECT(val, b.prev_id, prev_id);
273 GET_FROM_JSON_OBJECT(val, b.nonce, nonce);
274 GET_FROM_JSON_OBJECT(val, b.miner_tx, miner_tx);
275 GET_FROM_JSON_OBJECT(val, b.tx_hashes, tx_hashes);
276}
277
278void toJsonValue(rapidjson::Document& doc, const cryptonote::txin_v& txin, rapidjson::Value& val)
279{
280 val.SetObject();
281
282 struct add_input
283 {
284 using result_type = void;
285
286 rapidjson::Document& doc;
287 rapidjson::Value& val;
288
289 void operator()(cryptonote::txin_to_key const& input) const
290 {
291 INSERT_INTO_JSON_OBJECT(val, doc, to_key, input);
292 }
293 void operator()(cryptonote::txin_to_key_public const& input) const
294 {
295 INSERT_INTO_JSON_OBJECT(val, doc, to_key, input);
296 }
297 void operator()(cryptonote::txin_gen const& input) const
298 {
299 INSERT_INTO_JSON_OBJECT(val, doc, gen, input);
300 }
301 void operator()(cryptonote::txin_to_script const& input) const
302 {
303 INSERT_INTO_JSON_OBJECT(val, doc, to_script, input);
304 }
305 void operator()(cryptonote::txin_to_scripthash const& input) const
306 {
307 INSERT_INTO_JSON_OBJECT(val, doc, to_scripthash, input);
308 }
309 };
310 boost::apply_visitor(add_input{doc, val}, txin);
311}
312
313
314void fromJsonValue(const rapidjson::Value& val, cryptonote::txin_v& txin)
315{
316 if (!val.IsObject())
317 {
318 throw WRONG_TYPE("json object");
319 }
320
321 if (val.MemberCount() != 1)
322 {
323 throw MISSING_KEY("Invalid input object");
324 }
325
326 for (auto const& elem : val.GetObject())
327 {
328 if (elem.name == "to_key")
329 {
331 fromJsonValue(elem.value, tmpVal);
332 txin = std::move(tmpVal);
333 }
334 else if (elem.name == "gen")
335 {
337 fromJsonValue(elem.value, tmpVal);
338 txin = std::move(tmpVal);
339 }
340 else if (elem.name == "to_script")
341 {
343 fromJsonValue(elem.value, tmpVal);
344 txin = std::move(tmpVal);
345 }
346 else if (elem.name == "to_scripthash")
347 {
349 fromJsonValue(elem.value, tmpVal);
350 txin = std::move(tmpVal);
351 }
352 }
353}
354
355void toJsonValue(rapidjson::Document& doc, const cryptonote::txin_gen& txin, rapidjson::Value& val)
356{
357 val.SetObject();
358
359 INSERT_INTO_JSON_OBJECT(val, doc, height, txin.height);
360}
361
362
363void fromJsonValue(const rapidjson::Value& val, cryptonote::txin_gen& txin)
364{
365 if (!val.IsObject())
366 {
367 throw WRONG_TYPE("json object");
368 }
369
371}
372
373void toJsonValue(rapidjson::Document& doc, const cryptonote::txin_to_script& txin, rapidjson::Value& val)
374{
375 val.SetObject();
376
377 INSERT_INTO_JSON_OBJECT(val, doc, prev, txin.prev);
378 INSERT_INTO_JSON_OBJECT(val, doc, prevout, txin.prevout);
379 INSERT_INTO_JSON_OBJECT(val, doc, sigset, txin.sigset);
380}
381
382
383void fromJsonValue(const rapidjson::Value& val, cryptonote::txin_to_script& txin)
384{
385 if (!val.IsObject())
386 {
387 throw WRONG_TYPE("json object");
388 }
389
390 GET_FROM_JSON_OBJECT(val, txin.prev, prev);
391 GET_FROM_JSON_OBJECT(val, txin.prevout, prevout);
392 GET_FROM_JSON_OBJECT(val, txin.sigset, sigset);
393}
394
395void toJsonValue(rapidjson::Document& doc, const cryptonote::txin_to_scripthash& txin, rapidjson::Value& val)
396{
397 val.SetObject();
398
399 INSERT_INTO_JSON_OBJECT(val, doc, prev, txin.prev);
400 INSERT_INTO_JSON_OBJECT(val, doc, prevout, txin.prevout);
401 INSERT_INTO_JSON_OBJECT(val, doc, script, txin.script);
402 INSERT_INTO_JSON_OBJECT(val, doc, sigset, txin.sigset);
403}
404
405
406void fromJsonValue(const rapidjson::Value& val, cryptonote::txin_to_scripthash& txin)
407{
408 if (!val.IsObject())
409 {
410 throw WRONG_TYPE("json object");
411 }
412
413 GET_FROM_JSON_OBJECT(val, txin.prev, prev);
414 GET_FROM_JSON_OBJECT(val, txin.prevout, prevout);
415 GET_FROM_JSON_OBJECT(val, txin.script, script);
416 GET_FROM_JSON_OBJECT(val, txin.sigset, sigset);
417}
418
419void toJsonValue(rapidjson::Document& doc, const cryptonote::txin_to_key& txin, rapidjson::Value& val)
420{
421 val.SetObject();
422
423 INSERT_INTO_JSON_OBJECT(val, doc, amount, txin.amount);
424 INSERT_INTO_JSON_OBJECT(val, doc, key_offsets, txin.key_offsets);
425 INSERT_INTO_JSON_OBJECT(val, doc, key_image, txin.k_image);
426}
427
428void toJsonValue(rapidjson::Document& doc, const cryptonote::txin_to_key_public& txin, rapidjson::Value& val)
429{
430 val.SetObject();
431
432 INSERT_INTO_JSON_OBJECT(val, doc, amount, txin.amount);
433 INSERT_INTO_JSON_OBJECT(val, doc, tx_hash, txin.tx_hash);
434 INSERT_INTO_JSON_OBJECT(val, doc, relative_offset, txin.relative_offset);
435}
436
437void fromJsonValue(const rapidjson::Value& val, cryptonote::txin_to_key& txin)
438{
439 if (!val.IsObject())
440 {
441 throw WRONG_TYPE("json object");
442 }
443
444 GET_FROM_JSON_OBJECT(val, txin.amount, amount);
445 GET_FROM_JSON_OBJECT(val, txin.key_offsets, key_offsets);
446 GET_FROM_JSON_OBJECT(val, txin.k_image, key_image);
447}
448
449void fromJsonValue(const rapidjson::Value& val, cryptonote::txin_to_key_public& txin)
450{
451 if (!val.IsObject())
452 {
453 throw WRONG_TYPE("json object");
454 }
455
456 GET_FROM_JSON_OBJECT(val, txin.amount, amount);
457 GET_FROM_JSON_OBJECT(val, txin.tx_hash, tx_hash);
458 GET_FROM_JSON_OBJECT(val, txin.relative_offset, relative_offset);
459}
460
461void toJsonValue(rapidjson::Document& doc, const cryptonote::txout_to_script& txout, rapidjson::Value& val)
462{
463 val.SetObject();
464
465 INSERT_INTO_JSON_OBJECT(val, doc, keys, txout.keys);
466 INSERT_INTO_JSON_OBJECT(val, doc, script, txout.script);
467}
468
469
470void fromJsonValue(const rapidjson::Value& val, cryptonote::txout_to_script& txout)
471{
472 if (!val.IsObject())
473 {
474 throw WRONG_TYPE("json object");
475 }
476
477 GET_FROM_JSON_OBJECT(val, txout.keys, keys);
478 GET_FROM_JSON_OBJECT(val, txout.script, script);
479}
480
481void toJsonValue(rapidjson::Document& doc, const cryptonote::txout_to_scripthash& txout, rapidjson::Value& val)
482{
483 val.SetObject();
484
485 INSERT_INTO_JSON_OBJECT(val, doc, hash, txout.hash);
486}
487
488
489void fromJsonValue(const rapidjson::Value& val, cryptonote::txout_to_scripthash& txout)
490{
491 if (!val.IsObject())
492 {
493 throw WRONG_TYPE("json object");
494 }
495
496 GET_FROM_JSON_OBJECT(val, txout.hash, hash);
497}
498
499void toJsonValue(rapidjson::Document& doc, const cryptonote::txout_to_key& txout, rapidjson::Value& val)
500{
501 val.SetObject();
502
503 INSERT_INTO_JSON_OBJECT(val, doc, key, txout.key);
504}
505
506void fromJsonValue(const rapidjson::Value& val, cryptonote::txout_to_key_public& txout)
507{
508 if (!val.IsObject())
509 {
510 throw WRONG_TYPE("json object");
511 }
512
513 GET_FROM_JSON_OBJECT(val, txout.m_address_prefix, prefix);
515}
516
517void toJsonValue(rapidjson::Document& doc, const cryptonote::txout_to_key_public& txout, rapidjson::Value& val)
518{
519 val.SetObject();
520
521 INSERT_INTO_JSON_OBJECT(val, doc, prefix, txout.m_address_prefix);
522 INSERT_INTO_JSON_OBJECT(val, doc, address, txout.address);
523}
524
525void fromJsonValue(const rapidjson::Value& val, cryptonote::txout_to_key& txout)
526{
527 if (!val.IsObject())
528 {
529 throw WRONG_TYPE("json object");
530 }
531
532 GET_FROM_JSON_OBJECT(val, txout.key, key);
533}
534
535void toJsonValue(rapidjson::Document& doc, const cryptonote::tx_out& txout, rapidjson::Value& val)
536{
537 val.SetObject();
538
539 INSERT_INTO_JSON_OBJECT(val, doc, amount, txout.amount);
540
541 struct add_output
542 {
543 using result_type = void;
544
545 rapidjson::Document& doc;
546 rapidjson::Value& val;
547
548 void operator()(cryptonote::txout_to_key const& output) const
549 {
550 INSERT_INTO_JSON_OBJECT(val, doc, to_key, output);
551 }
552 void operator()(cryptonote::txout_to_key_public const& output) const
553 {
554 INSERT_INTO_JSON_OBJECT(val, doc, to_key_public, output);
555 }
556 void operator()(cryptonote::txout_to_script const& output) const
557 {
558 INSERT_INTO_JSON_OBJECT(val, doc, to_script, output);
559 }
560 void operator()(cryptonote::txout_to_scripthash const& output) const
561 {
562 INSERT_INTO_JSON_OBJECT(val, doc, to_scripthash, output);
563 }
564 };
565 boost::apply_visitor(add_output{doc, val}, txout.target);
566}
567
568void fromJsonValue(const rapidjson::Value& val, cryptonote::tx_out& txout)
569{
570 if (!val.IsObject())
571 {
572 throw WRONG_TYPE("json object");
573 }
574
575 if (val.MemberCount() != 2)
576 {
577 throw MISSING_KEY("Invalid input object");
578 }
579
580 for (auto const& elem : val.GetObject())
581 {
582 if (elem.name == "amount")
583 {
584 fromJsonValue(elem.value, txout.amount);
585 }
586
587 if (elem.name == "to_key")
588 {
590 fromJsonValue(elem.value, tmpVal);
591 txout.target = std::move(tmpVal);
592 }
593 else if (elem.name == "to_key_public")
594 {
596 fromJsonValue(elem.value, tmpVal);
597 txout.target = std::move(tmpVal);
598 }
599 else if (elem.name == "to_script")
600 {
602 fromJsonValue(elem.value, tmpVal);
603 txout.target = std::move(tmpVal);
604 }
605 else if (elem.name == "to_scripthash")
606 {
608 fromJsonValue(elem.value, tmpVal);
609 txout.target = std::move(tmpVal);
610 }
611 }
612}
613
614void toJsonValue(rapidjson::Document& doc, const cryptonote::connection_info& info, rapidjson::Value& val)
615{
616 val.SetObject();
617
618 INSERT_INTO_JSON_OBJECT(val, doc, incoming, info.incoming);
619 INSERT_INTO_JSON_OBJECT(val, doc, localhost, info.localhost);
620 INSERT_INTO_JSON_OBJECT(val, doc, local_ip, info.local_ip);
621
622 INSERT_INTO_JSON_OBJECT(val, doc, ip, info.ip);
623 INSERT_INTO_JSON_OBJECT(val, doc, port, info.port);
624 INSERT_INTO_JSON_OBJECT(val, doc, rpc_port, info.rpc_port);
625
626 INSERT_INTO_JSON_OBJECT(val, doc, peer_id, info.peer_id);
627
628 INSERT_INTO_JSON_OBJECT(val, doc, recv_count, info.recv_count);
629 INSERT_INTO_JSON_OBJECT(val, doc, recv_idle_time, info.recv_idle_time);
630
631 INSERT_INTO_JSON_OBJECT(val, doc, send_count, info.send_count);
632 INSERT_INTO_JSON_OBJECT(val, doc, send_idle_time, info.send_idle_time);
633
634 INSERT_INTO_JSON_OBJECT(val, doc, state, info.state);
635
636 INSERT_INTO_JSON_OBJECT(val, doc, live_time, info.live_time);
637
638 INSERT_INTO_JSON_OBJECT(val, doc, avg_download, info.avg_download);
639 INSERT_INTO_JSON_OBJECT(val, doc, current_download, info.current_download);
640
641 INSERT_INTO_JSON_OBJECT(val, doc, avg_upload, info.avg_upload);
642 INSERT_INTO_JSON_OBJECT(val, doc, current_upload, info.current_upload);
643}
644
645
646void fromJsonValue(const rapidjson::Value& val, cryptonote::connection_info& info)
647{
648 if (!val.IsObject())
649 {
650 throw WRONG_TYPE("json object");
651 }
652
653 GET_FROM_JSON_OBJECT(val, info.incoming, incoming);
654 GET_FROM_JSON_OBJECT(val, info.localhost, localhost);
655 GET_FROM_JSON_OBJECT(val, info.local_ip, local_ip);
656
657 GET_FROM_JSON_OBJECT(val, info.ip, ip);
658 GET_FROM_JSON_OBJECT(val, info.port, port);
659 GET_FROM_JSON_OBJECT(val, info.rpc_port, rpc_port);
660
661 GET_FROM_JSON_OBJECT(val, info.peer_id, peer_id);
662
663 GET_FROM_JSON_OBJECT(val, info.recv_count, recv_count);
664 GET_FROM_JSON_OBJECT(val, info.recv_idle_time, recv_idle_time);
665
666 GET_FROM_JSON_OBJECT(val, info.send_count, send_count);
667 GET_FROM_JSON_OBJECT(val, info.send_idle_time, send_idle_time);
668
669 GET_FROM_JSON_OBJECT(val, info.state, state);
670
671 GET_FROM_JSON_OBJECT(val, info.live_time, live_time);
672
673 GET_FROM_JSON_OBJECT(val, info.avg_download, avg_download);
674 GET_FROM_JSON_OBJECT(val, info.current_download, current_download);
675
676 GET_FROM_JSON_OBJECT(val, info.avg_upload, avg_upload);
677 GET_FROM_JSON_OBJECT(val, info.current_upload, current_upload);
678}
679
680void toJsonValue(rapidjson::Document& doc, const cryptonote::block_complete_entry& blk, rapidjson::Value& val)
681{
682 val.SetObject();
683
684 INSERT_INTO_JSON_OBJECT(val, doc, block, blk.block);
685 INSERT_INTO_JSON_OBJECT(val, doc, transactions, blk.txs);
686}
687
688
689void fromJsonValue(const rapidjson::Value& val, cryptonote::block_complete_entry& blk)
690{
691 if (!val.IsObject())
692 {
693 throw WRONG_TYPE("json object");
694 }
695
697 GET_FROM_JSON_OBJECT(val, blk.txs, transactions);
698}
699
700void toJsonValue(rapidjson::Document& doc, const cryptonote::rpc::block_with_transactions& blk, rapidjson::Value& val)
701{
702 val.SetObject();
703
704 INSERT_INTO_JSON_OBJECT(val, doc, block, blk.block);
705 INSERT_INTO_JSON_OBJECT(val, doc, transactions, blk.transactions);
706}
707
708
709void fromJsonValue(const rapidjson::Value& val, cryptonote::rpc::block_with_transactions& blk)
710{
711 if (!val.IsObject())
712 {
713 throw WRONG_TYPE("json object");
714 }
715
717 GET_FROM_JSON_OBJECT(val, blk.transactions, transactions);
718}
719
720void toJsonValue(rapidjson::Document& doc, const cryptonote::rpc::transaction_info& tx_info, rapidjson::Value& val)
721{
722 val.SetObject();
723
724 INSERT_INTO_JSON_OBJECT(val, doc, height, tx_info.height);
725 INSERT_INTO_JSON_OBJECT(val, doc, in_pool, tx_info.in_pool);
726 INSERT_INTO_JSON_OBJECT(val, doc, transaction, tx_info.transaction);
727}
728
729
730void fromJsonValue(const rapidjson::Value& val, cryptonote::rpc::transaction_info& tx_info)
731{
732 if (!val.IsObject())
733 {
734 throw WRONG_TYPE("json object");
735 }
736
737 GET_FROM_JSON_OBJECT(val, tx_info.height, height);
738 GET_FROM_JSON_OBJECT(val, tx_info.in_pool, in_pool);
739 GET_FROM_JSON_OBJECT(val, tx_info.transaction, transaction);
740}
741
742void toJsonValue(rapidjson::Document& doc, const cryptonote::rpc::output_key_and_amount_index& out, rapidjson::Value& val)
743{
744 val.SetObject();
745
746 INSERT_INTO_JSON_OBJECT(val, doc, amount_index, out.amount_index);
747 INSERT_INTO_JSON_OBJECT(val, doc, key, out.key);
748}
749
750
751void fromJsonValue(const rapidjson::Value& val, cryptonote::rpc::output_key_and_amount_index& out)
752{
753 if (!val.IsObject())
754 {
755 throw WRONG_TYPE("json object");
756 }
757
758 GET_FROM_JSON_OBJECT(val, out.amount_index, amount_index);
759 GET_FROM_JSON_OBJECT(val, out.key, key);
760}
761
762void toJsonValue(rapidjson::Document& doc, const cryptonote::rpc::amount_with_random_outputs& out, rapidjson::Value& val)
763{
764 val.SetObject();
765
766 INSERT_INTO_JSON_OBJECT(val, doc, amount, out.amount);
767 INSERT_INTO_JSON_OBJECT(val, doc, outputs, out.outputs);
768}
769
770
771void fromJsonValue(const rapidjson::Value& val, cryptonote::rpc::amount_with_random_outputs& out)
772{
773 if (!val.IsObject())
774 {
775 throw WRONG_TYPE("json object");
776 }
777
778 GET_FROM_JSON_OBJECT(val, out.amount, amount);
779 GET_FROM_JSON_OBJECT(val, out.outputs, outputs);
780}
781
782void toJsonValue(rapidjson::Document& doc, const cryptonote::rpc::peer& peer, rapidjson::Value& val)
783{
784 val.SetObject();
785
786 INSERT_INTO_JSON_OBJECT(val, doc, id, peer.id);
787 INSERT_INTO_JSON_OBJECT(val, doc, ip, peer.ip);
788 INSERT_INTO_JSON_OBJECT(val, doc, port, peer.port);
789 INSERT_INTO_JSON_OBJECT(val, doc, rpc_port, peer.rpc_port);
790 INSERT_INTO_JSON_OBJECT(val, doc, last_seen, peer.last_seen);
791 INSERT_INTO_JSON_OBJECT(val, doc, pruning_seed, peer.pruning_seed);
792}
793
794
795void fromJsonValue(const rapidjson::Value& val, cryptonote::rpc::peer& peer)
796{
797 if (!val.IsObject())
798 {
799 throw WRONG_TYPE("json object");
800 }
801
802 GET_FROM_JSON_OBJECT(val, peer.id, id);
803 GET_FROM_JSON_OBJECT(val, peer.ip, ip);
804 GET_FROM_JSON_OBJECT(val, peer.port, port);
805 GET_FROM_JSON_OBJECT(val, peer.rpc_port, rpc_port);
806 GET_FROM_JSON_OBJECT(val, peer.last_seen, last_seen);
807 GET_FROM_JSON_OBJECT(val, peer.pruning_seed, pruning_seed);
808}
809
810void toJsonValue(rapidjson::Document& doc, const cryptonote::rpc::tx_in_pool& tx, rapidjson::Value& val)
811{
812 val.SetObject();
813
814 INSERT_INTO_JSON_OBJECT(val, doc, tx, tx.tx);
815 INSERT_INTO_JSON_OBJECT(val, doc, tx_hash, tx.tx_hash);
816 INSERT_INTO_JSON_OBJECT(val, doc, blob_size, tx.blob_size);
817 INSERT_INTO_JSON_OBJECT(val, doc, weight, tx.weight);
818 INSERT_INTO_JSON_OBJECT(val, doc, fee, tx.fee);
819 INSERT_INTO_JSON_OBJECT(val, doc, max_used_block_hash, tx.max_used_block_hash);
820 INSERT_INTO_JSON_OBJECT(val, doc, max_used_block_height, tx.max_used_block_height);
821 INSERT_INTO_JSON_OBJECT(val, doc, kept_by_block, tx.kept_by_block);
822 INSERT_INTO_JSON_OBJECT(val, doc, last_failed_block_hash, tx.last_failed_block_hash);
823 INSERT_INTO_JSON_OBJECT(val, doc, last_failed_block_height, tx.last_failed_block_height);
824 INSERT_INTO_JSON_OBJECT(val, doc, receive_time, tx.receive_time);
825 INSERT_INTO_JSON_OBJECT(val, doc, last_relayed_time, tx.last_relayed_time);
826 INSERT_INTO_JSON_OBJECT(val, doc, relayed, tx.relayed);
827 INSERT_INTO_JSON_OBJECT(val, doc, do_not_relay, tx.do_not_relay);
828 INSERT_INTO_JSON_OBJECT(val, doc, double_spend_seen, tx.double_spend_seen);
829 INSERT_INTO_JSON_OBJECT(val, doc, nonexistent_utxo_seen, tx.nonexistent_utxo_seen);
830}
831
832
833void fromJsonValue(const rapidjson::Value& val, cryptonote::rpc::tx_in_pool& tx)
834{
835 if (!val.IsObject())
836 {
837 throw WRONG_TYPE("json object");
838 }
839
840 GET_FROM_JSON_OBJECT(val, tx.tx, tx);
841 GET_FROM_JSON_OBJECT(val, tx.blob_size, blob_size);
842 GET_FROM_JSON_OBJECT(val, tx.weight, weight);
843 GET_FROM_JSON_OBJECT(val, tx.fee, fee);
844 GET_FROM_JSON_OBJECT(val, tx.max_used_block_hash, max_used_block_hash);
845 GET_FROM_JSON_OBJECT(val, tx.max_used_block_height, max_used_block_height);
846 GET_FROM_JSON_OBJECT(val, tx.kept_by_block, kept_by_block);
847 GET_FROM_JSON_OBJECT(val, tx.last_failed_block_hash, last_failed_block_hash);
848 GET_FROM_JSON_OBJECT(val, tx.last_failed_block_height, last_failed_block_height);
849 GET_FROM_JSON_OBJECT(val, tx.receive_time, receive_time);
850 GET_FROM_JSON_OBJECT(val, tx.last_relayed_time, last_relayed_time);
851 GET_FROM_JSON_OBJECT(val, tx.relayed, relayed);
852 GET_FROM_JSON_OBJECT(val, tx.do_not_relay, do_not_relay);
853 GET_FROM_JSON_OBJECT(val, tx.double_spend_seen, double_spend_seen);
854 GET_FROM_JSON_OBJECT(val, tx.nonexistent_utxo_seen, nonexistent_utxo_seen);
855}
856
857void toJsonValue(rapidjson::Document& doc, const cryptonote::rpc::hard_fork_info& info, rapidjson::Value& val)
858{
859 val.SetObject();
860
861 INSERT_INTO_JSON_OBJECT(val, doc, version, info.version);
862 INSERT_INTO_JSON_OBJECT(val, doc, enabled, info.enabled);
863 INSERT_INTO_JSON_OBJECT(val, doc, window, info.window);
864 INSERT_INTO_JSON_OBJECT(val, doc, votes, info.votes);
865 INSERT_INTO_JSON_OBJECT(val, doc, threshold, info.threshold);
866 INSERT_INTO_JSON_OBJECT(val, doc, voting, info.voting);
867 INSERT_INTO_JSON_OBJECT(val, doc, state, info.state);
868 INSERT_INTO_JSON_OBJECT(val, doc, earliest_height, info.earliest_height);
869}
870
871
872void fromJsonValue(const rapidjson::Value& val, cryptonote::rpc::hard_fork_info& info)
873{
874 if (!val.IsObject())
875 {
876 throw WRONG_TYPE("json object");
877 }
878
879 GET_FROM_JSON_OBJECT(val, info.version, version);
880 GET_FROM_JSON_OBJECT(val, info.enabled, enabled);
881 GET_FROM_JSON_OBJECT(val, info.window, window);
882 GET_FROM_JSON_OBJECT(val, info.votes, votes);
883 GET_FROM_JSON_OBJECT(val, info.threshold, threshold);
884 GET_FROM_JSON_OBJECT(val, info.voting, voting);
885 GET_FROM_JSON_OBJECT(val, info.state, state);
886 GET_FROM_JSON_OBJECT(val, info.earliest_height, earliest_height);
887}
888
889void toJsonValue(rapidjson::Document& doc, const cryptonote::rpc::output_amount_count& out, rapidjson::Value& val)
890{
891 val.SetObject();
892
893 INSERT_INTO_JSON_OBJECT(val, doc, amount, out.amount);
894 INSERT_INTO_JSON_OBJECT(val, doc, total_count, out.total_count);
895 INSERT_INTO_JSON_OBJECT(val, doc, unlocked_count, out.unlocked_count);
896 INSERT_INTO_JSON_OBJECT(val, doc, recent_count, out.recent_count);
897}
898
899
900void fromJsonValue(const rapidjson::Value& val, cryptonote::rpc::output_amount_count& out)
901{
902 if (!val.IsObject())
903 {
904 throw WRONG_TYPE("json object");
905 }
906
907 GET_FROM_JSON_OBJECT(val, out.amount, amount);
908 GET_FROM_JSON_OBJECT(val, out.total_count, total_count);
909 GET_FROM_JSON_OBJECT(val, out.unlocked_count, unlocked_count);
910 GET_FROM_JSON_OBJECT(val, out.recent_count, recent_count);
911}
912
913void toJsonValue(rapidjson::Document& doc, const cryptonote::rpc::output_amount_and_index& out, rapidjson::Value& val)
914{
915 val.SetObject();
916
917 INSERT_INTO_JSON_OBJECT(val, doc, amount, out.amount);
918 INSERT_INTO_JSON_OBJECT(val, doc, index, out.index);
919}
920
921
922void fromJsonValue(const rapidjson::Value& val, cryptonote::rpc::output_amount_and_index& out)
923{
924 if (!val.IsObject())
925 {
926 throw WRONG_TYPE("json object");
927 }
928
929 GET_FROM_JSON_OBJECT(val, out.amount, amount);
930 GET_FROM_JSON_OBJECT(val, out.index, index);
931}
932
933void toJsonValue(rapidjson::Document& doc, const cryptonote::rpc::output_key_mask_unlocked& out, rapidjson::Value& val)
934{
935 val.SetObject();
936
937 INSERT_INTO_JSON_OBJECT(val, doc, key, out.key);
938 INSERT_INTO_JSON_OBJECT(val, doc, mask, out.mask);
939 INSERT_INTO_JSON_OBJECT(val, doc, unlocked, out.unlocked);
940}
941
942void fromJsonValue(const rapidjson::Value& val, cryptonote::rpc::output_key_mask_unlocked& out)
943{
944 if (!val.IsObject())
945 {
946 throw WRONG_TYPE("json object");
947 }
948
949 GET_FROM_JSON_OBJECT(val, out.key, key);
950 GET_FROM_JSON_OBJECT(val, out.mask, mask);
951 GET_FROM_JSON_OBJECT(val, out.unlocked, unlocked);
952}
953
954void toJsonValue(rapidjson::Document& doc, const cryptonote::rpc::error& err, rapidjson::Value& val)
955{
956 val.SetObject();
957
958 INSERT_INTO_JSON_OBJECT(val, doc, code, err.code);
959 INSERT_INTO_JSON_OBJECT(val, doc, error_str, err.error_str);
961}
962
963void fromJsonValue(const rapidjson::Value& val, cryptonote::rpc::error& error)
964{
965 if (!val.IsObject())
966 {
967 throw WRONG_TYPE("json object");
968 }
969
970 GET_FROM_JSON_OBJECT(val, error.code, code);
971 GET_FROM_JSON_OBJECT(val, error.error_str, error_str);
972 GET_FROM_JSON_OBJECT(val, error.message, message);
973}
974
975void toJsonValue(rapidjson::Document& doc, const cryptonote::rpc::BlockHeaderResponse& response, rapidjson::Value& val)
976{
977 val.SetObject();
978
979 INSERT_INTO_JSON_OBJECT(val, doc, major_version, response.major_version);
980 INSERT_INTO_JSON_OBJECT(val, doc, minor_version, response.minor_version);
981 INSERT_INTO_JSON_OBJECT(val, doc, timestamp, response.timestamp);
982 INSERT_INTO_JSON_OBJECT(val, doc, prev_id, response.prev_id);
983 INSERT_INTO_JSON_OBJECT(val, doc, nonce, response.nonce);
984 INSERT_INTO_JSON_OBJECT(val, doc, height, response.height);
985 INSERT_INTO_JSON_OBJECT(val, doc, depth, response.depth);
986 INSERT_INTO_JSON_OBJECT(val, doc, hash, response.hash);
987 INSERT_INTO_JSON_OBJECT(val, doc, difficulty, response.difficulty);
988 INSERT_INTO_JSON_OBJECT(val, doc, reward, response.reward);
989}
990
991void fromJsonValue(const rapidjson::Value& val, cryptonote::rpc::BlockHeaderResponse& response)
992{
993 if (!val.IsObject())
994 {
995 throw WRONG_TYPE("json object");
996 }
997
998 GET_FROM_JSON_OBJECT(val, response.major_version, major_version);
999 GET_FROM_JSON_OBJECT(val, response.minor_version, minor_version);
1000 GET_FROM_JSON_OBJECT(val, response.timestamp, timestamp);
1001 GET_FROM_JSON_OBJECT(val, response.prev_id, prev_id);
1002 GET_FROM_JSON_OBJECT(val, response.nonce, nonce);
1003 GET_FROM_JSON_OBJECT(val, response.height, height);
1004 GET_FROM_JSON_OBJECT(val, response.depth, depth);
1005 GET_FROM_JSON_OBJECT(val, response.hash, hash);
1006 GET_FROM_JSON_OBJECT(val, response.difficulty, difficulty);
1007 GET_FROM_JSON_OBJECT(val, response.reward, reward);
1008}
1009
1010void toJsonValue(rapidjson::Document& doc, const rct::rctSig& sig, rapidjson::Value& val)
1011{
1012 using boost::adaptors::transform;
1013
1014 val.SetObject();
1015
1016 const auto just_mask = [] (rct::ctkey const& key) -> rct::key const&
1017 {
1018 return key.mask;
1019 };
1020
1021 INSERT_INTO_JSON_OBJECT(val, doc, type, sig.type);
1022 INSERT_INTO_JSON_OBJECT(val, doc, encrypted, sig.ecdhInfo);
1023 INSERT_INTO_JSON_OBJECT(val, doc, commitments, transform(sig.outPk, just_mask));
1024 INSERT_INTO_JSON_OBJECT(val, doc, fee, sig.txnFee);
1025
1026 // prunable
1027 {
1028 rapidjson::Value prunable;
1029 prunable.SetObject();
1030
1031 INSERT_INTO_JSON_OBJECT(prunable, doc, range_proofs, sig.p.rangeSigs);
1032 INSERT_INTO_JSON_OBJECT(prunable, doc, bulletproofs, sig.p.bulletproofs);
1033 INSERT_INTO_JSON_OBJECT(prunable, doc, mlsags, sig.p.MGs);
1034 INSERT_INTO_JSON_OBJECT(prunable, doc, pseudo_outs, sig.get_pseudo_outs());
1035
1036 val.AddMember("prunable", prunable, doc.GetAllocator());
1037 }
1038}
1039
1040void fromJsonValue(const rapidjson::Value& val, rct::rctSig& sig)
1041{
1042 using boost::adaptors::transform;
1043
1044 if (!val.IsObject())
1045 {
1046 throw WRONG_TYPE("json object");
1047 }
1048
1049 std::vector<rct::key> commitments;
1050
1051 GET_FROM_JSON_OBJECT(val, sig.type, type);
1052 GET_FROM_JSON_OBJECT(val, sig.ecdhInfo, encrypted);
1053 GET_FROM_JSON_OBJECT(val, commitments, commitments);
1054 GET_FROM_JSON_OBJECT(val, sig.txnFee, fee);
1055
1056 // prunable
1057 {
1058 OBJECT_HAS_MEMBER_OR_THROW(val, "prunable");
1059 const auto& prunable = val["prunable"];
1060
1061 rct::keyV pseudo_outs;
1062
1063 GET_FROM_JSON_OBJECT(prunable, sig.p.rangeSigs, range_proofs);
1064 GET_FROM_JSON_OBJECT(prunable, sig.p.bulletproofs, bulletproofs);
1065 GET_FROM_JSON_OBJECT(prunable, sig.p.MGs, mlsags);
1066 GET_FROM_JSON_OBJECT(prunable, pseudo_outs, pseudo_outs);
1067
1068 sig.get_pseudo_outs() = std::move(pseudo_outs);
1069 }
1070
1071 sig.outPk.reserve(commitments.size());
1072 for (rct::key const& commitment : commitments)
1073 {
1074 sig.outPk.push_back({{}, commitment});
1075 }
1076}
1077
1078void toJsonValue(rapidjson::Document& doc, const rct::ecdhTuple& tuple, rapidjson::Value& val)
1079{
1080 val.SetObject();
1081
1082 INSERT_INTO_JSON_OBJECT(val, doc, mask, tuple.mask);
1083 INSERT_INTO_JSON_OBJECT(val, doc, amount, tuple.amount);
1084}
1085
1086void fromJsonValue(const rapidjson::Value& val, rct::ecdhTuple& tuple)
1087{
1088 if (!val.IsObject())
1089 {
1090 throw WRONG_TYPE("json object");
1091 }
1092
1093 GET_FROM_JSON_OBJECT(val, tuple.mask, mask);
1094 GET_FROM_JSON_OBJECT(val, tuple.amount, amount);
1095}
1096
1097void toJsonValue(rapidjson::Document& doc, const rct::rangeSig& sig, rapidjson::Value& val)
1098{
1099 val.SetObject();
1100
1101 INSERT_INTO_JSON_OBJECT(val, doc, asig, sig.asig);
1102
1103 std::vector<rct::key> keyVector(sig.Ci, std::end(sig.Ci));
1104 INSERT_INTO_JSON_OBJECT(val, doc, Ci, keyVector);
1105}
1106
1107void fromJsonValue(const rapidjson::Value& val, rct::rangeSig& sig)
1108{
1109 if (!val.IsObject())
1110 {
1111 throw WRONG_TYPE("json object");
1112 }
1113
1114 const auto ci = val.FindMember("Ci");
1115 if (ci == val.MemberEnd())
1116 {
1117 throw MISSING_KEY("Ci");
1118 }
1119
1120 GET_FROM_JSON_OBJECT(val, sig.asig, asig);
1121
1122 std::vector<rct::key> keyVector;
1123 cryptonote::json::fromJsonValue(ci->value, keyVector);
1124 if (!(keyVector.size() == 64))
1125 {
1126 throw WRONG_TYPE("key64 (rct::key[64])");
1127 }
1128 for (size_t i=0; i < 64; i++)
1129 {
1130 sig.Ci[i] = keyVector[i];
1131 }
1132}
1133
1134void toJsonValue(rapidjson::Document& doc, const rct::Bulletproof& p, rapidjson::Value& val)
1135{
1136 val.SetObject();
1137
1138 INSERT_INTO_JSON_OBJECT(val, doc, V, p.V);
1139 INSERT_INTO_JSON_OBJECT(val, doc, A, p.A);
1140 INSERT_INTO_JSON_OBJECT(val, doc, S, p.S);
1141 INSERT_INTO_JSON_OBJECT(val, doc, T1, p.T1);
1142 INSERT_INTO_JSON_OBJECT(val, doc, T2, p.T2);
1143 INSERT_INTO_JSON_OBJECT(val, doc, taux, p.taux);
1144 INSERT_INTO_JSON_OBJECT(val, doc, mu, p.mu);
1145 INSERT_INTO_JSON_OBJECT(val, doc, L, p.L);
1146 INSERT_INTO_JSON_OBJECT(val, doc, R, p.R);
1147 INSERT_INTO_JSON_OBJECT(val, doc, a, p.a);
1148 INSERT_INTO_JSON_OBJECT(val, doc, b, p.b);
1149 INSERT_INTO_JSON_OBJECT(val, doc, t, p.t);
1150}
1151
1152void fromJsonValue(const rapidjson::Value& val, rct::Bulletproof& p)
1153{
1154 if (!val.IsObject())
1155 {
1156 throw WRONG_TYPE("json object");
1157 }
1158
1159 GET_FROM_JSON_OBJECT(val, p.V, V);
1160 GET_FROM_JSON_OBJECT(val, p.A, A);
1161 GET_FROM_JSON_OBJECT(val, p.S, S);
1162 GET_FROM_JSON_OBJECT(val, p.T1, T1);
1163 GET_FROM_JSON_OBJECT(val, p.T2, T2);
1164 GET_FROM_JSON_OBJECT(val, p.taux, taux);
1165 GET_FROM_JSON_OBJECT(val, p.mu, mu);
1166 GET_FROM_JSON_OBJECT(val, p.L, L);
1167 GET_FROM_JSON_OBJECT(val, p.R, R);
1168 GET_FROM_JSON_OBJECT(val, p.a, a);
1169 GET_FROM_JSON_OBJECT(val, p.b, b);
1170 GET_FROM_JSON_OBJECT(val, p.t, t);
1171}
1172
1173void toJsonValue(rapidjson::Document& doc, const rct::boroSig& sig, rapidjson::Value& val)
1174{
1175 val.SetObject();
1176
1177 std::vector<rct::key> keyVector(sig.s0, std::end(sig.s0));
1178 INSERT_INTO_JSON_OBJECT(val, doc, s0, keyVector);
1179
1180 keyVector.assign(sig.s1, std::end(sig.s1));
1181 INSERT_INTO_JSON_OBJECT(val, doc, s1, keyVector);
1182
1183 INSERT_INTO_JSON_OBJECT(val, doc, ee, sig.ee);
1184}
1185
1186void fromJsonValue(const rapidjson::Value& val, rct::boroSig& sig)
1187{
1188 if (!val.IsObject())
1189 {
1190 throw WRONG_TYPE("json object");
1191 }
1192
1194 std::vector<rct::key> keyVector;
1195 cryptonote::json::fromJsonValue(val["s0"], keyVector);
1196 if (!(keyVector.size() == 64))
1197 {
1198 throw WRONG_TYPE("key64 (rct::key[64])");
1199 }
1200 for (size_t i=0; i < 64; i++)
1201 {
1202 sig.s0[i] = keyVector[i];
1203 }
1204
1206 keyVector.clear();
1207 cryptonote::json::fromJsonValue(val["s1"], keyVector);
1208 if (!(keyVector.size() == 64))
1209 {
1210 throw WRONG_TYPE("key64 (rct::key[64])");
1211 }
1212 for (size_t i=0; i < 64; i++)
1213 {
1214 sig.s1[i] = keyVector[i];
1215 }
1216
1217 GET_FROM_JSON_OBJECT(val, sig.ee, ee);
1218}
1219
1220void toJsonValue(rapidjson::Document& doc, const rct::mgSig& sig, rapidjson::Value& val)
1221{
1222 val.SetObject();
1223
1224 INSERT_INTO_JSON_OBJECT(val, doc, ss, sig.ss);
1225 INSERT_INTO_JSON_OBJECT(val, doc, cc, sig.cc);
1226}
1227
1228void fromJsonValue(const rapidjson::Value& val, rct::mgSig& sig)
1229{
1230 if (!val.IsObject())
1231 {
1232 throw WRONG_TYPE("key64 (rct::key[64])");
1233 }
1234
1235 GET_FROM_JSON_OBJECT(val, sig.ss, ss);
1236 GET_FROM_JSON_OBJECT(val, sig.cc, cc);
1237}
1238
1239void toJsonValue(rapidjson::Document& doc, const cryptonote::rpc::DaemonInfo& info, rapidjson::Value& val)
1240{
1241 val.SetObject();
1242
1243 INSERT_INTO_JSON_OBJECT(val, doc, height, info.height);
1244 INSERT_INTO_JSON_OBJECT(val, doc, target_height, info.target_height);
1245 INSERT_INTO_JSON_OBJECT(val, doc, difficulty, info.difficulty);
1246 INSERT_INTO_JSON_OBJECT(val, doc, target, info.target);
1247 INSERT_INTO_JSON_OBJECT(val, doc, tx_count, info.tx_count);
1248 INSERT_INTO_JSON_OBJECT(val, doc, tx_pool_size, info.tx_pool_size);
1249 INSERT_INTO_JSON_OBJECT(val, doc, alt_blocks_count, info.alt_blocks_count);
1250 INSERT_INTO_JSON_OBJECT(val, doc, outgoing_connections_count, info.outgoing_connections_count);
1251 INSERT_INTO_JSON_OBJECT(val, doc, incoming_connections_count, info.incoming_connections_count);
1252 INSERT_INTO_JSON_OBJECT(val, doc, white_peerlist_size, info.white_peerlist_size);
1253 INSERT_INTO_JSON_OBJECT(val, doc, grey_peerlist_size, info.grey_peerlist_size);
1254 INSERT_INTO_JSON_OBJECT(val, doc, mainnet, info.mainnet);
1255 INSERT_INTO_JSON_OBJECT(val, doc, testnet, info.testnet);
1256 INSERT_INTO_JSON_OBJECT(val, doc, stagenet, info.stagenet);
1257 INSERT_INTO_JSON_OBJECT(val, doc, nettype, info.nettype);
1258 INSERT_INTO_JSON_OBJECT(val, doc, top_block_hash, info.top_block_hash);
1259 INSERT_INTO_JSON_OBJECT(val, doc, cumulative_difficulty, info.cumulative_difficulty);
1260 INSERT_INTO_JSON_OBJECT(val, doc, block_size_limit, info.block_size_limit);
1261 INSERT_INTO_JSON_OBJECT(val, doc, block_weight_limit, info.block_weight_limit);
1262 INSERT_INTO_JSON_OBJECT(val, doc, block_size_median, info.block_size_median);
1263 INSERT_INTO_JSON_OBJECT(val, doc, block_weight_median, info.block_weight_median);
1264 INSERT_INTO_JSON_OBJECT(val, doc, start_time, info.start_time);
1265}
1266
1267void fromJsonValue(const rapidjson::Value& val, cryptonote::rpc::DaemonInfo& info)
1268{
1269 if (!val.IsObject())
1270 {
1271 throw WRONG_TYPE("json object");
1272 }
1273
1274 GET_FROM_JSON_OBJECT(val, info.height, height);
1275 GET_FROM_JSON_OBJECT(val, info.target_height, target_height);
1276 GET_FROM_JSON_OBJECT(val, info.difficulty, difficulty);
1277 GET_FROM_JSON_OBJECT(val, info.target, target);
1278 GET_FROM_JSON_OBJECT(val, info.tx_count, tx_count);
1279 GET_FROM_JSON_OBJECT(val, info.tx_pool_size, tx_pool_size);
1280 GET_FROM_JSON_OBJECT(val, info.alt_blocks_count, alt_blocks_count);
1281 GET_FROM_JSON_OBJECT(val, info.outgoing_connections_count, outgoing_connections_count);
1282 GET_FROM_JSON_OBJECT(val, info.incoming_connections_count, incoming_connections_count);
1283 GET_FROM_JSON_OBJECT(val, info.white_peerlist_size, white_peerlist_size);
1284 GET_FROM_JSON_OBJECT(val, info.grey_peerlist_size, grey_peerlist_size);
1285 GET_FROM_JSON_OBJECT(val, info.mainnet, mainnet);
1286 GET_FROM_JSON_OBJECT(val, info.testnet, testnet);
1287 GET_FROM_JSON_OBJECT(val, info.stagenet, stagenet);
1288 GET_FROM_JSON_OBJECT(val, info.nettype, nettype);
1289 GET_FROM_JSON_OBJECT(val, info.top_block_hash, top_block_hash);
1290 GET_FROM_JSON_OBJECT(val, info.cumulative_difficulty, cumulative_difficulty);
1291 GET_FROM_JSON_OBJECT(val, info.block_size_limit, block_size_limit);
1292 GET_FROM_JSON_OBJECT(val, info.block_weight_limit, block_weight_limit);
1293 GET_FROM_JSON_OBJECT(val, info.block_size_median, block_size_median);
1294 GET_FROM_JSON_OBJECT(val, info.block_weight_median, block_weight_median);
1295 GET_FROM_JSON_OBJECT(val, info.start_time, start_time);
1296}
1297
1298void toJsonValue(rapidjson::Document& doc, const cryptonote::rpc::output_distribution& dist, rapidjson::Value& val)
1299{
1300 val.SetObject();
1301
1302 INSERT_INTO_JSON_OBJECT(val, doc, distribution, dist.data.distribution);
1303 INSERT_INTO_JSON_OBJECT(val, doc, amount, dist.amount);
1304 INSERT_INTO_JSON_OBJECT(val, doc, start_height, dist.data.start_height);
1305 INSERT_INTO_JSON_OBJECT(val, doc, base, dist.data.base);
1306}
1307
1308void fromJsonValue(const rapidjson::Value& val, cryptonote::rpc::output_distribution& dist)
1309{
1310 if (!val.IsObject())
1311 {
1312 throw WRONG_TYPE("json object");
1313 }
1314
1315 GET_FROM_JSON_OBJECT(val, dist.data.distribution, distribution);
1316 GET_FROM_JSON_OBJECT(val, dist.amount, amount);
1317 GET_FROM_JSON_OBJECT(val, dist.data.start_height, start_height);
1318 GET_FROM_JSON_OBJECT(val, dist.data.base, base);
1319}
1320
1321} // namespace json
1322
1323} // namespace cryptonote
uint64_t height
uint8_t version
uint8_t threshold
std::vector< std::vector< crypto::signature > > signatures
std::string message("Message requiring signing")
const char * key
#define GET_FROM_JSON_OBJECT(source, dst, key)
Definition json_object.h:52
#define OBJECT_HAS_MEMBER_OR_THROW(val, key)
Definition json_object.h:38
#define INSERT_INTO_JSON_OBJECT(jsonVal, doc, key, source)
Definition json_object.h:47
void toJsonValue(rapidjson::Document &doc, const std::string &i, rapidjson::Value &val)
void fromJsonValue(const rapidjson::Value &val, std::string &str)
Holds cryptonote related classes and helpers.
Definition ban.cpp:40
boost::variant< txin_gen, txin_to_script, txin_to_scripthash, txin_to_key, txin_to_key_public > txin_v
std::vector< key > keyV
Definition rctTypes.h:88
const CharType(& source)[N]
Definition pointer.h:1147
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1124
Type
Type of JSON value.
Definition rapidjson.h:620
CXA_THROW_INFO_T * info
std::vector< blobdata > txs
blobdata block
std::vector< crypto::hash > tx_hashes
std::vector< cryptonote::transaction > transactions
std::vector< std::uint64_t > distribution
Definition rpc_handler.h:46
txout_target_v target
crypto::key_image k_image
std::vector< uint64_t > key_offsets
std::vector< uint8_t > sigset
std::vector< uint8_t > sigset
cryptonote::account_public_address address
std::vector< crypto::public_key > keys
std::vector< uint8_t > script
rct::keyV L
Definition rctTypes.h:184
rct::key taux
Definition rctTypes.h:183
rct::keyV V
Definition rctTypes.h:181
rct::keyV R
Definition rctTypes.h:184
boroSig asig
Definition rctTypes.h:170
etn_amount txnFee
Definition rctTypes.h:248
std::vector< ecdhTuple > ecdhInfo
Definition rctTypes.h:246
rctSigPrunable p
Definition rctTypes.h:437
keyV & get_pseudo_outs()
Definition rctTypes.h:439
std::vector< mgSig > MGs
Definition rctTypes.h:321
std::vector< rangeSig > rangeSigs
Definition rctTypes.h:319
std::vector< Bulletproof > bulletproofs
Definition rctTypes.h:320
const char * address
Definition multisig.cpp:37