2
This file is part of TON Blockchain source code.
4
TON Blockchain is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License
6
as published by the Free Software Foundation; either version 2
7
of the License, or (at your option) any later version.
9
TON Blockchain 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.
14
You should have received a copy of the GNU General Public License
16
In addition, as a special exception, the copyright holders give permission
17
to link the code of portions of this program with the OpenSSL library.
18
You must obey the GNU General Public License in all respects for all
19
of the code used other than OpenSSL. If you modify file(s) with this
20
exception, you may extend this exception to your version of the file(s),
21
but you are not obligated to do so. If you do not wish to do so, delete this
22
exception statement from your version. If you delete this exception statement
23
from all source files in the program, then also delete it here.
24
along with TON Blockchain. If not, see <http://www.gnu.org/licenses/>.
26
Copyright 2017-2020 Telegram Systems LLP
30
#include "auto/tl/ton_api.h"
31
#include "auto/tl/ton_api_json.h"
33
#include "tl/tl_json.h"
34
#include "td/utils/Random.h"
37
std::string config = R"json(
39
"@type" : "config.local",
42
"@type" : "dht.config.local",
44
"@type" : "adnl.id.pk.ed25519",
45
"key" : "VdeZz3BEIE8+tuPSBUNKN0jQXL/0T/SoK4ZpJ9vTCNQ="
48
"@type" : "adnl.addressList",
52
"@type" : "adnl.address.udp",
62
std::string config2 = R"json(
64
"@type" : "config.local",
67
"@type" : "dht.config.local",
69
"@type" : "adnl.id.pk.ed25519",
70
"key" : "VdeZz3BEIE8+tuPSBUNKN0jQXL/0T/SoK4ZpJ9vTCNQ="
73
"@type" : "adnl.addressList",
77
"@type" : "adnl.address.udp",
86
"@type" : "adnl.config.local"
93
std::cout << "hello world!\n";
95
auto decode_encode = [](auto obj_json) {
96
auto as_json_value = td::json_decode(obj_json).move_as_ok();
97
ton::ton_api::object_ptr<ton::ton_api::Object> obj2;
98
from_json(obj2, std::move(as_json_value)).ensure();
99
CHECK(obj2 != nullptr);
100
return td::json_encode<std::string>(td::ToJson(obj2));
103
auto test_tl_json = [&decode_encode](auto obj) {
104
auto obj_json = td::json_encode<std::string>(td::ToJson(obj));
105
std::cout << obj_json << "\n";
107
auto obj2_json = decode_encode(obj_json);
108
CHECK(obj_json == obj2_json);
113
test_tl_json(ton::ton_api::make_object<ton::ton_api::adnl_id_short>(uint256));
115
test_tl_json(ton::ton_api::make_object<ton::ton_api::testObject>(
116
1, ton::ton_api::make_object<ton::ton_api::adnl_id_short>(uint256),
117
ton::ton_api::make_object<ton::ton_api::getTestObject>()));
119
std::cout << decode_encode(config) << std::endl;
120
std::cout << decode_encode(config2) << std::endl;
122
auto decode_encode_local = [](auto obj_json) {
123
auto as_json_value = td::json_decode(obj_json).move_as_ok();
124
ton::ton_api::config_local config_local;
125
from_json(config_local, as_json_value.get_object()).ensure();
126
return td::json_encode<std::string>(td::ToJson(config_local));
128
std::cout << decode_encode_local(config) << std::endl;
129
std::cout << decode_encode_local(config2) << std::endl;
131
auto create_vector_bytes = [] {
132
std::vector<td::BufferSlice> res;
133
res.emplace_back("fdjskld");
134
res.emplace_back("fdj\0kld");
135
res.emplace_back("fdj\0\x01\xff\x7fkld");
138
test_tl_json(ton::ton_api::make_object<ton::ton_api::testVectorBytes>(create_vector_bytes()));
141
td::Random::secure_bytes(x.as_slice());
145
auto v = td::hex_decode(s).move_as_ok();
147
auto w = td::buffer_to_hex(x.as_slice());
150
y.as_slice().copy_from(v);
154
auto w2 = td::hex_decode(w).move_as_ok();
156
z.as_slice().copy_from(w2);
158
LOG_CHECK(x == z) << s << " " << w;