mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
Merge branch 'testnet' into block-generation
# Conflicts: # adnl/adnl-query.cpp # crypto/block/block.tlb # crypto/block/mc-config.h # lite-client/lite-client.cpp # overlay/overlay-manager.h # overlay/overlay-peers.cpp # overlay/overlay.cpp # overlay/overlay.h # overlay/overlay.hpp # overlay/overlays.h # rldp-http-proxy/DNSResolver.cpp # rldp-http-proxy/rldp-http-proxy.cpp # tl/generate/scheme/ton_api.tl # tl/generate/scheme/ton_api.tlo # tl/generate/scheme/tonlib_api.tlo # ton/ton-types.h # tonlib/tonlib/ExtClient.cpp # tonlib/tonlib/ExtClient.h # tonlib/tonlib/ExtClientLazy.cpp # tonlib/tonlib/ExtClientOutbound.h # tonlib/tonlib/ExtClientRaw.h # tonlib/tonlib/TonlibClient.cpp # tonlib/tonlib/TonlibClient.h # tonlib/tonlib/tonlib-cli.cpp # validator/impl/collator.cpp # validator/impl/validate-query.cpp # validator/impl/validate-query.hpp # validator/manager.cpp # validator/state-serializer.cpp # validator/state-serializer.hpp # validator/validator-group.cpp # validator/validator-group.hpp # validator/validator.h
This commit is contained in:
commit
d652f7d706
200 changed files with 13492 additions and 2997 deletions
|
|
@ -18,6 +18,7 @@ set(TONLIB_SOURCE
|
|||
tonlib/LastConfig.cpp
|
||||
tonlib/Logging.cpp
|
||||
tonlib/TonlibClient.cpp
|
||||
tonlib/TonlibClientWrapper.cpp
|
||||
tonlib/utils.cpp
|
||||
|
||||
tonlib/Client.h
|
||||
|
|
@ -34,6 +35,7 @@ set(TONLIB_SOURCE
|
|||
tonlib/Logging.h
|
||||
tonlib/TonlibCallback.h
|
||||
tonlib/TonlibClient.h
|
||||
tonlib/TonlibClientWrapper.h
|
||||
tonlib/utils.h
|
||||
|
||||
tonlib/keys/bip39.cpp
|
||||
|
|
@ -69,6 +71,7 @@ if (TONLIB_ENABLE_JNI AND NOT ANDROID) # jni is available by default on Android
|
|||
endif()
|
||||
message(STATUS "Found JNI: ${JNI_INCLUDE_DIRS} ${JNI_LIBRARIES}")
|
||||
target_include_directories(tonlib PUBLIC ${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH2})
|
||||
target_include_directories(tl_tonlib_api PUBLIC ${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH2})
|
||||
target_link_libraries(tonlib PUBLIC ${JAVA_JVM_LIBRARY})
|
||||
endif()
|
||||
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ void ExtClient::with_last_block(td::Promise<LastBlockState> promise) {
|
|||
td::actor::send_closure(client_.last_block_actor_, &LastBlock::get_last_block, std::move(P));
|
||||
}
|
||||
|
||||
void ExtClient::send_raw_query(td::BufferSlice query, ton::ShardIdFull shard, td::Promise<td::BufferSlice> promise) {
|
||||
void ExtClient::send_raw_query(td::BufferSlice query, td::Promise<td::BufferSlice> promise) {
|
||||
auto query_id = queries_.create(std::move(promise));
|
||||
td::Promise<td::BufferSlice> P = [query_id, self = this,
|
||||
actor_id = td::actor::actor_id()](td::Result<td::BufferSlice> result) {
|
||||
|
|
@ -62,10 +62,10 @@ void ExtClient::send_raw_query(td::BufferSlice query, ton::ShardIdFull shard, td
|
|||
self->queries_.extract(query_id).set_result(std::move(result));
|
||||
});
|
||||
};
|
||||
if (client_.raw_client_.empty()) {
|
||||
if (client_.adnl_ext_client_.empty()) {
|
||||
return P.set_error(TonlibError::NoLiteServers());
|
||||
}
|
||||
td::actor::send_closure(client_.raw_client_, &ExtClientRaw::send_query, "query", std::move(query), shard,
|
||||
td::actor::send_closure(client_.adnl_ext_client_, &ton::adnl::AdnlExtClient::send_query, "query", std::move(query),
|
||||
td::Timestamp::in(10.0), std::move(P));
|
||||
}
|
||||
} // namespace tonlib
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@
|
|||
#include "td/utils/Container.h"
|
||||
#include "td/utils/Random.h"
|
||||
|
||||
#include "ExtClientRaw.h"
|
||||
#include "ExtClientLazy.h"
|
||||
#include "TonlibError.h"
|
||||
#include "utils.h"
|
||||
#include "QueryTraits.h"
|
||||
|
|
@ -40,7 +40,7 @@ class LastConfig;
|
|||
struct LastBlockState;
|
||||
struct LastConfigState;
|
||||
struct ExtClientRef {
|
||||
td::actor::ActorId<ExtClientRaw> raw_client_;
|
||||
td::actor::ActorId<ExtClientLazy> adnl_ext_client_;
|
||||
td::actor::ActorId<LastBlock> last_block_actor_;
|
||||
td::actor::ActorId<LastConfig> last_config_actor_;
|
||||
};
|
||||
|
|
@ -99,8 +99,8 @@ class ExtClient {
|
|||
}
|
||||
|
||||
void force_change_liteserver() {
|
||||
if (!client_.raw_client_.empty()) {
|
||||
td::actor::send_closure(client_.raw_client_, &ExtClientRaw::force_change_liteserver);
|
||||
if (!client_.adnl_ext_client_.empty()) {
|
||||
td::actor::send_closure(client_.adnl_ext_client_, &ExtClientLazy::force_change_liteserver);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,15 +16,15 @@
|
|||
|
||||
Copyright 2017-2020 Telegram Systems LLP
|
||||
*/
|
||||
#include "ExtClientRaw.h"
|
||||
#include "ExtClientLazy.h"
|
||||
#include "TonlibError.h"
|
||||
#include "td/utils/Random.h"
|
||||
namespace tonlib {
|
||||
|
||||
class ExtClientLazyImp : public ExtClientRaw {
|
||||
class ExtClientLazyImp : public ExtClientLazy {
|
||||
public:
|
||||
ExtClientLazyImp(std::vector<std::pair<ton::adnl::AdnlNodeIdFull, td::IPAddress>> servers,
|
||||
td::unique_ptr<ExtClientRaw::Callback> callback)
|
||||
td::unique_ptr<ExtClientLazy::Callback> callback)
|
||||
: servers_(std::move(servers)), callback_(std::move(callback)) {
|
||||
CHECK(!servers_.empty());
|
||||
}
|
||||
|
|
@ -34,7 +34,15 @@ class ExtClientLazyImp : public ExtClientRaw {
|
|||
td::random_shuffle(td::as_mutable_span(servers_), rnd);
|
||||
}
|
||||
|
||||
void send_query(std::string name, td::BufferSlice data, ton::ShardIdFull shard, td::Timestamp timeout,
|
||||
void check_ready(td::Promise<td::Unit> promise) override {
|
||||
before_query();
|
||||
if (client_.empty()) {
|
||||
return promise.set_error(TonlibError::Cancelled());
|
||||
}
|
||||
send_closure(client_, &ton::adnl::AdnlExtClient::check_ready, std::move(promise));
|
||||
}
|
||||
|
||||
void send_query(std::string name, td::BufferSlice data, td::Timestamp timeout,
|
||||
td::Promise<td::BufferSlice> promise) override {
|
||||
before_query();
|
||||
if (client_.empty()) {
|
||||
|
|
@ -101,7 +109,7 @@ class ExtClientLazyImp : public ExtClientRaw {
|
|||
bool cur_server_bad_force_ = false;
|
||||
|
||||
td::actor::ActorOwn<ton::adnl::AdnlExtClient> client_;
|
||||
td::unique_ptr<ExtClientRaw::Callback> callback_;
|
||||
td::unique_ptr<ExtClientLazy::Callback> callback_;
|
||||
static constexpr double MAX_NO_QUERIES_TIMEOUT = 100;
|
||||
|
||||
bool is_closing_{false};
|
||||
|
|
@ -132,12 +140,12 @@ class ExtClientLazyImp : public ExtClientRaw {
|
|||
}
|
||||
};
|
||||
|
||||
td::actor::ActorOwn<ExtClientRaw> ExtClientRaw::create(ton::adnl::AdnlNodeIdFull dst, td::IPAddress dst_addr,
|
||||
td::unique_ptr<Callback> callback) {
|
||||
td::actor::ActorOwn<ExtClientLazy> ExtClientLazy::create(ton::adnl::AdnlNodeIdFull dst, td::IPAddress dst_addr,
|
||||
td::unique_ptr<Callback> callback) {
|
||||
return create({std::make_pair(dst, dst_addr)}, std::move(callback));
|
||||
}
|
||||
|
||||
td::actor::ActorOwn<ExtClientRaw> ExtClientRaw::create(
|
||||
td::actor::ActorOwn<ExtClientLazy> ExtClientLazy::create(
|
||||
std::vector<std::pair<ton::adnl::AdnlNodeIdFull, td::IPAddress>> servers, td::unique_ptr<Callback> callback) {
|
||||
return td::actor::create_actor<ExtClientLazyImp>("ExtClientLazy", std::move(servers), std::move(callback));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,9 @@ class ExtClientOutboundImp : public ExtClientOutbound {
|
|||
void force_change_liteserver() override {
|
||||
}
|
||||
|
||||
void force_change_liteserver() override {
|
||||
}
|
||||
|
||||
void on_query_result(td::int64 id, td::Result<td::BufferSlice> r_data, td::Promise<td::Unit> promise) override {
|
||||
auto it = queries_.find(id);
|
||||
if (it == queries_.end()) {
|
||||
|
|
|
|||
|
|
@ -19,10 +19,10 @@
|
|||
#pragma once
|
||||
#include "td/actor/actor.h"
|
||||
|
||||
#include "ExtClientRaw.h"
|
||||
#include "ExtClientLazy.h"
|
||||
|
||||
namespace tonlib {
|
||||
class ExtClientOutbound : public ExtClientRaw {
|
||||
class ExtClientOutbound : public ExtClientLazy {
|
||||
public:
|
||||
class Callback {
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -22,20 +22,18 @@
|
|||
#include "ton/ton-types.h"
|
||||
|
||||
namespace tonlib {
|
||||
class ExtClientRaw : public td::actor::Actor {
|
||||
class ExtClientLazy : public ton::adnl::AdnlExtClient {
|
||||
public:
|
||||
class Callback {
|
||||
public:
|
||||
virtual ~Callback() = default;
|
||||
};
|
||||
|
||||
virtual void send_query(std::string name, td::BufferSlice data, ton::ShardIdFull shard, td::Timestamp timeout,
|
||||
td::Promise<td::BufferSlice> promise) = 0;
|
||||
virtual void force_change_liteserver() = 0;
|
||||
|
||||
static td::actor::ActorOwn<ExtClientRaw> create(ton::adnl::AdnlNodeIdFull dst, td::IPAddress dst_addr,
|
||||
td::unique_ptr<Callback> callback);
|
||||
static td::actor::ActorOwn<ExtClientRaw> create(
|
||||
static td::actor::ActorOwn<ExtClientLazy> create(ton::adnl::AdnlNodeIdFull dst, td::IPAddress dst_addr,
|
||||
td::unique_ptr<Callback> callback);
|
||||
static td::actor::ActorOwn<ExtClientLazy> create(
|
||||
std::vector<std::pair<ton::adnl::AdnlNodeIdFull, td::IPAddress>> servers, td::unique_ptr<Callback> callback);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
#include "TonlibClient.h"
|
||||
|
||||
#include "tonlib/ExtClientRaw.h"
|
||||
#include "tonlib/ExtClientLazy.h"
|
||||
#include "tonlib/ExtClientOutbound.h"
|
||||
#include "tonlib/LastBlock.h"
|
||||
#include "tonlib/LastConfig.h"
|
||||
|
|
@ -1650,7 +1650,7 @@ void TonlibClient::hangup() {
|
|||
|
||||
ExtClientRef TonlibClient::get_client_ref() {
|
||||
ExtClientRef ref;
|
||||
ref.raw_client_ = raw_client_.get();
|
||||
ref.adnl_ext_client_ = raw_client_.get();
|
||||
ref.last_block_actor_ = raw_last_block_.get();
|
||||
ref.last_config_actor_ = raw_last_config_.get();
|
||||
|
||||
|
|
@ -1685,7 +1685,11 @@ void TonlibClient::init_ext_client() {
|
|||
ext_client_outbound_ = client.get();
|
||||
raw_client_ = std::move(client);
|
||||
} else {
|
||||
class Callback : public ExtClientRaw::Callback {
|
||||
std::vector<std::pair<ton::adnl::AdnlNodeIdFull, td::IPAddress>> servers;
|
||||
for (const auto& s : config_.lite_clients) {
|
||||
servers.emplace_back(s.adnl_id, s.address);
|
||||
}
|
||||
class Callback : public ExtClientLazy::Callback {
|
||||
public:
|
||||
explicit Callback(td::actor::ActorShared<> parent) : parent_(std::move(parent)) {
|
||||
}
|
||||
|
|
@ -1708,6 +1712,7 @@ void TonlibClient::init_ext_client() {
|
|||
}
|
||||
ext_client_outbound_ = {};
|
||||
ref_cnt_++;
|
||||
raw_client_ = ExtClientLazy::create(std::move(servers), td::make_unique<Callback>(td::actor::actor_shared()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2299,24 +2304,46 @@ const MasterConfig& get_default_master_config() {
|
|||
"liteservers": [
|
||||
],
|
||||
"validator": {
|
||||
"@type": "validator.config.global",
|
||||
"zero_state": {
|
||||
"workchain": -1,
|
||||
"shard": -9223372036854775808,
|
||||
"seqno": 0,
|
||||
"root_hash": "gj+B8wb/AmlPk1z1AhVI484rhrUpgSr2oSFIh56VoSg=",
|
||||
"file_hash": "Z+IKwYS54DmmJmesw/nAD5DzWadnOCMzee+kdgSYDOg="
|
||||
},
|
||||
"init_block" : {
|
||||
"root_hash": "gj+B8wb/AmlPk1z1AhVI484rhrUpgSr2oSFIh56VoSg=",
|
||||
"seqno": 0,
|
||||
"file_hash": "Z+IKwYS54DmmJmesw/nAD5DzWadnOCMzee+kdgSYDOg=",
|
||||
"workchain": -1,
|
||||
"shard": -9223372036854775808
|
||||
},
|
||||
"hardforks": [
|
||||
]
|
||||
}
|
||||
"zero_state": {
|
||||
"file_hash": "Z+IKwYS54DmmJmesw/nAD5DzWadnOCMzee+kdgSYDOg=",
|
||||
"seqno": 0,
|
||||
"root_hash": "gj+B8wb/AmlPk1z1AhVI484rhrUpgSr2oSFIh56VoSg=",
|
||||
"workchain": -1,
|
||||
"shard": -9223372036854775808
|
||||
},
|
||||
"@type": "validator.config.global",
|
||||
"init_block":
|
||||
{
|
||||
"file_hash": "xRaxgUwgTXYFb16YnR+Q+VVsczLl6jmYwvzhQ/ncrh4=",
|
||||
"seqno": 5176527,
|
||||
"root_hash": "SoPLqMe9Dz26YJPOGDOHApTSe5i0kXFtRmRh/zPMGuI=",
|
||||
"workchain": -1,
|
||||
"shard": -9223372036854775808
|
||||
},
|
||||
"hardforks": [
|
||||
{
|
||||
"file_hash": "jF3RTD+OyOoP+OI9oIjdV6M8EaOh9E+8+c3m5JkPYdg=",
|
||||
"seqno": 5141579,
|
||||
"root_hash": "6JSqIYIkW7y8IorxfbQBoXiuY3kXjcoYgQOxTJpjXXA=",
|
||||
"workchain": -1,
|
||||
"shard": -9223372036854775808
|
||||
},
|
||||
{
|
||||
"file_hash": "WrNoMrn5UIVPDV/ug/VPjYatvde8TPvz5v1VYHCLPh8=",
|
||||
"seqno": 5172980,
|
||||
"root_hash": "054VCNNtUEwYGoRe1zjH+9b1q21/MeM+3fOo76Vcjes=",
|
||||
"workchain": -1,
|
||||
"shard": -9223372036854775808
|
||||
},
|
||||
{
|
||||
"file_hash": "xRaxgUwgTXYFb16YnR+Q+VVsczLl6jmYwvzhQ/ncrh4=",
|
||||
"seqno": 5176527,
|
||||
"root_hash": "SoPLqMe9Dz26YJPOGDOHApTSe5i0kXFtRmRh/zPMGuI=",
|
||||
"workchain": -1,
|
||||
"shard": -9223372036854775808
|
||||
}
|
||||
]
|
||||
}
|
||||
})abc");
|
||||
return res;
|
||||
}();
|
||||
|
|
@ -2520,7 +2547,18 @@ struct ToRawTransactions {
|
|||
auto body_cell = vm::CellBuilder().append_cellslice(*body).finalize();
|
||||
auto body_hash = body_cell->get_hash().as_slice().str();
|
||||
|
||||
auto get_data = [body = std::move(body), body_cell, this](td::Slice salt) mutable {
|
||||
td::Ref<vm::Cell> init_state_cell;
|
||||
auto& init_state_cs = message.init.write();
|
||||
if (init_state_cs.fetch_ulong(1) == 1) {
|
||||
if (init_state_cs.fetch_long(1) == 0) {
|
||||
init_state_cell = vm::CellBuilder().append_cellslice(init_state_cs).finalize();
|
||||
} else {
|
||||
init_state_cell = init_state_cs.fetch_ref();
|
||||
}
|
||||
}
|
||||
|
||||
auto get_data = [body = std::move(body), body_cell = std::move(body_cell),
|
||||
init_state_cell = std::move(init_state_cell), this](td::Slice salt) mutable {
|
||||
tonlib_api::object_ptr<tonlib_api::msg_Data> data;
|
||||
if (try_decode_messages_ && body->size() >= 32 && static_cast<td::uint32>(body->prefetch_long(32)) <= 1) {
|
||||
auto type = body.write().fetch_long(32);
|
||||
|
|
@ -2550,7 +2588,7 @@ struct ToRawTransactions {
|
|||
}
|
||||
}
|
||||
if (!data) {
|
||||
data = tonlib_api::make_object<tonlib_api::msg_dataRaw>(to_bytes(std::move(body_cell)), "");
|
||||
data = tonlib_api::make_object<tonlib_api::msg_dataRaw>(to_bytes(std::move(body_cell)), to_bytes(std::move(init_state_cell)));
|
||||
}
|
||||
return data;
|
||||
};
|
||||
|
|
@ -2708,7 +2746,7 @@ td::Status TonlibClient::do_request(const tonlib_api::raw_sendMessageReturnHash&
|
|||
td::Promise<object_ptr<tonlib_api::raw_extMessageInfo>>&& promise) {
|
||||
TRY_RESULT_PREFIX(body, vm::std_boc_deserialize(request.body_), TonlibError::InvalidBagOfCells("body"));
|
||||
auto hash = body->get_hash().as_slice().str();
|
||||
make_request(int_api::SendMessage{std::move(body)},
|
||||
make_request(int_api::SendMessage{std::move(body)},
|
||||
promise.wrap([hash = std::move(hash)](auto res) {
|
||||
return tonlib_api::make_object<tonlib_api::raw_extMessageInfo>(std::move(hash));
|
||||
}));
|
||||
|
|
@ -3687,6 +3725,17 @@ td::Status TonlibClient::do_request(const tonlib_api::smc_load& request,
|
|||
return td::Status::OK();
|
||||
}
|
||||
|
||||
td::Status TonlibClient::do_request(const tonlib_api::smc_forget& request,
|
||||
td::Promise<object_ptr<tonlib_api::ok>>&& promise) {
|
||||
auto it = smcs_.find(request.id_);
|
||||
if (it == smcs_.end()) {
|
||||
return TonlibError::InvalidSmcId();
|
||||
}
|
||||
smcs_.erase(it);
|
||||
promise.set_value(tonlib_api::make_object<tonlib_api::ok>());
|
||||
return td::Status::OK();
|
||||
}
|
||||
|
||||
td::Status TonlibClient::do_request(const tonlib_api::smc_getCode& request,
|
||||
td::Promise<object_ptr<tonlib_api::tvm_cell>>&& promise) {
|
||||
auto it = smcs_.find(request.id_);
|
||||
|
|
@ -3867,7 +3916,7 @@ td::Status TonlibClient::do_request(const tonlib_api::smc_getLibraries& request,
|
|||
return td::Status::OK();
|
||||
}
|
||||
|
||||
client_.send_query(ton::lite_api::liteServer_getLibraries(std::move(not_cached_hashes)),
|
||||
client_.send_query(ton::lite_api::liteServer_getLibraries(std::move(not_cached_hashes)),
|
||||
promise.wrap([self=this, result_entries = std::move(result_entries)]
|
||||
(td::Result<ton::lite_api::object_ptr<ton::lite_api::liteServer_libraryResult>> r_libraries) mutable
|
||||
{
|
||||
|
|
@ -4609,7 +4658,7 @@ td::Status TonlibClient::do_request(const tonlib_api::getConfigParam& request,
|
|||
std::vector<int32_t> params = { param };
|
||||
|
||||
client_.send_query(ton::lite_api::liteServer_getConfigParams(0, std::move(lite_block), std::move(params)),
|
||||
promise.wrap([block, param](auto r_config) {
|
||||
promise.wrap([block, param](auto r_config) {
|
||||
auto state = block::check_extract_state_proof(block, r_config->state_proof_.as_slice(),
|
||||
r_config->config_proof_.as_slice());
|
||||
if (state.is_error()) {
|
||||
|
|
@ -4693,7 +4742,7 @@ td::Status TonlibClient::do_request(const tonlib_api::blocks_lookupBlock& reques
|
|||
|
||||
auto to_tonlib_api(const ton::lite_api::liteServer_transactionId& txid)
|
||||
-> tonlib_api_ptr<tonlib_api::blocks_shortTxId> {
|
||||
return tonlib_api::make_object<tonlib_api::blocks_shortTxId>(
|
||||
return tonlib_api::make_object<tonlib_api::blocks_shortTxId>(
|
||||
txid.mode_, txid.account_.as_slice().str(), txid.lt_, txid.hash_.as_slice().str());
|
||||
}
|
||||
|
||||
|
|
@ -4817,7 +4866,7 @@ td::Status TonlibClient::do_request(const tonlib_api::blocks_getShardBlockProof&
|
|||
TRY_RESULT(id, to_block_id(*request.id_));
|
||||
ton::BlockIdExt from;
|
||||
if (request.mode_ & 1) {
|
||||
TRY_RESULT_ASSIGN(from, to_block_id(*request.id_));
|
||||
TRY_RESULT_ASSIGN(from, to_block_id(*request.from_));
|
||||
}
|
||||
auto actor_id = actor_id_++;
|
||||
actors_[actor_id] = td::actor::create_actor<GetShardBlockProof>("GetShardBlockProof", client_.get_client(), id, from,
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ class TonlibClient : public td::actor::Actor {
|
|||
vm::Dictionary libraries{256};
|
||||
|
||||
// network
|
||||
td::actor::ActorOwn<ExtClientRaw> raw_client_;
|
||||
td::actor::ActorOwn<ExtClientLazy> raw_client_;
|
||||
td::actor::ActorId<ExtClientOutbound> ext_client_outbound_;
|
||||
td::actor::ActorOwn<LastBlock> raw_last_block_;
|
||||
td::actor::ActorOwn<LastConfig> raw_last_config_;
|
||||
|
|
@ -305,6 +305,7 @@ class TonlibClient : public td::actor::Actor {
|
|||
td::Result<tonlib_api::object_ptr<tonlib_api::smc_info>> get_smc_info(td::int64 id);
|
||||
void finish_load_smc(td::unique_ptr<AccountState> query, td::Promise<object_ptr<tonlib_api::smc_info>>&& promise);
|
||||
td::Status do_request(const tonlib_api::smc_load& request, td::Promise<object_ptr<tonlib_api::smc_info>>&& promise);
|
||||
td::Status do_request(const tonlib_api::smc_forget& request, td::Promise<object_ptr<tonlib_api::ok>>&& promise);
|
||||
td::Status do_request(const tonlib_api::smc_getCode& request,
|
||||
td::Promise<object_ptr<tonlib_api::tvm_cell>>&& promise);
|
||||
td::Status do_request(const tonlib_api::smc_getData& request,
|
||||
|
|
|
|||
70
tonlib/tonlib/TonlibClientWrapper.cpp
Normal file
70
tonlib/tonlib/TonlibClientWrapper.cpp
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
This file is part of TON Blockchain source code.
|
||||
|
||||
TON Blockchain 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 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
TON Blockchain 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 TON Blockchain. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, as a special exception, the copyright holders give permission
|
||||
to link the code of portions of this program with the OpenSSL library.
|
||||
You must obey the GNU General Public License in all respects for all
|
||||
of the code used other than OpenSSL. If you modify file(s) with this
|
||||
exception, you may extend this exception to your version of the file(s),
|
||||
but you are not obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. If you delete this exception statement
|
||||
from all source files in the program, then also delete it here.
|
||||
*/
|
||||
#include "TonlibClientWrapper.h"
|
||||
|
||||
namespace tonlib {
|
||||
|
||||
TonlibClientWrapper::TonlibClientWrapper(ton::tl_object_ptr<tonlib_api::options> options)
|
||||
: options_(std::move(options)) {
|
||||
}
|
||||
|
||||
void TonlibClientWrapper::start_up() {
|
||||
class Cb : public tonlib::TonlibCallback {
|
||||
public:
|
||||
explicit Cb(td::actor::ActorId<TonlibClientWrapper> self_id) : self_id_(self_id) {
|
||||
}
|
||||
void on_result(std::uint64_t id, tonlib_api::object_ptr<tonlib_api::Object> result) override {
|
||||
td::actor::send_closure(self_id_, &TonlibClientWrapper::receive_request_result, id, std::move(result));
|
||||
}
|
||||
void on_error(std::uint64_t id, tonlib_api::object_ptr<tonlib_api::error> error) override {
|
||||
td::actor::send_closure(self_id_, &TonlibClientWrapper::receive_request_result, id,
|
||||
td::Status::Error(error->code_, std::move(error->message_)));
|
||||
}
|
||||
|
||||
private:
|
||||
td::actor::ActorId<TonlibClientWrapper> self_id_;
|
||||
};
|
||||
|
||||
tonlib_client_ = td::actor::create_actor<tonlib::TonlibClient>("tonlibclient", td::make_unique<Cb>(actor_id(this)));
|
||||
auto init = tonlib_api::make_object<tonlib_api::init>(std::move(options_));
|
||||
auto P = td::PromiseCreator::lambda(
|
||||
[](td::Result<tonlib_api::object_ptr<tonlib_api::options_info>> R) mutable { R.ensure(); });
|
||||
send_request(std::move(init), std::move(P));
|
||||
}
|
||||
|
||||
void TonlibClientWrapper::receive_request_result(td::uint64 id,
|
||||
td::Result<tonlib_api::object_ptr<tonlib_api::Object>> R) {
|
||||
if (id == 0) {
|
||||
return;
|
||||
}
|
||||
auto it = requests_.find(id);
|
||||
CHECK(it != requests_.end());
|
||||
auto promise = std::move(it->second);
|
||||
requests_.erase(it);
|
||||
promise.set_result(std::move(R));
|
||||
}
|
||||
|
||||
} // namespace tonlib
|
||||
61
tonlib/tonlib/TonlibClientWrapper.h
Normal file
61
tonlib/tonlib/TonlibClientWrapper.h
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
This file is part of TON Blockchain source code.
|
||||
|
||||
TON Blockchain 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 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
TON Blockchain 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 TON Blockchain. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, as a special exception, the copyright holders give permission
|
||||
to link the code of portions of this program with the OpenSSL library.
|
||||
You must obey the GNU General Public License in all respects for all
|
||||
of the code used other than OpenSSL. If you modify file(s) with this
|
||||
exception, you may extend this exception to your version of the file(s),
|
||||
but you are not obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. If you delete this exception statement
|
||||
from all source files in the program, then also delete it here.
|
||||
*/
|
||||
#pragma once
|
||||
#include "td/actor/actor.h"
|
||||
#include "auto/tl/tonlib_api.hpp"
|
||||
#include "tonlib/tonlib/TonlibClient.h"
|
||||
|
||||
namespace tonlib {
|
||||
|
||||
class TonlibClientWrapper : public td::actor::Actor {
|
||||
public:
|
||||
explicit TonlibClientWrapper(ton::tl_object_ptr<tonlib_api::options> options);
|
||||
|
||||
void start_up() override;
|
||||
|
||||
template <typename F>
|
||||
void send_request(tonlib_api::object_ptr<F> obj, td::Promise<typename F::ReturnType> promise) {
|
||||
auto id = next_request_id_++;
|
||||
auto P = promise.wrap([](tonlib_api::object_ptr<tonlib_api::Object> x) -> td::Result<typename F::ReturnType> {
|
||||
if (x->get_id() != F::ReturnType::element_type::ID) {
|
||||
return td::Status::Error("Invalid response from tonlib");
|
||||
}
|
||||
return ton::move_tl_object_as<typename F::ReturnType::element_type>(std::move(x));
|
||||
});
|
||||
CHECK(requests_.emplace(id, std::move(P)).second);
|
||||
td::actor::send_closure(tonlib_client_, &tonlib::TonlibClient::request, id, std::move(obj));
|
||||
}
|
||||
|
||||
private:
|
||||
void receive_request_result(td::uint64 id, td::Result<tonlib_api::object_ptr<tonlib_api::Object>> R);
|
||||
|
||||
ton::tl_object_ptr<tonlib_api::options> options_;
|
||||
td::actor::ActorOwn<tonlib::TonlibClient> tonlib_client_;
|
||||
std::map<td::uint64, td::Promise<tonlib_api::object_ptr<tonlib_api::Object>>> requests_;
|
||||
td::uint64 next_request_id_{1};
|
||||
};
|
||||
|
||||
} // namespace tonlib
|
||||
|
|
@ -175,7 +175,7 @@ class TonlibCli : public td::actor::Actor {
|
|||
|
||||
std::map<std::uint64_t, td::Promise<tonlib_api::object_ptr<tonlib_api::Object>>> query_handlers_;
|
||||
|
||||
td::actor::ActorOwn<tonlib::ExtClientRaw> raw_client_;
|
||||
td::actor::ActorOwn<tonlib::ExtClientLazy> raw_client_;
|
||||
|
||||
bool is_closing_{false};
|
||||
td::uint32 ref_cnt_{1};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue