1
0
mirror of https://github.com/danog/ton.git synced 2024-11-30 04:29:19 +01:00

tonlib: added missing files

This commit is contained in:
ton 2019-09-23 11:25:34 +04:00
parent 28df74178c
commit 87ccb27b70
2 changed files with 103 additions and 0 deletions

View File

@ -0,0 +1,66 @@
/*
This file is part of TON Blockchain Library.
TON Blockchain Library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser 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 Library 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with TON Blockchain Library. If not, see <http://www.gnu.org/licenses/>.
Copyright 2017-2019 Telegram Systems LLP
*/
#include "ExtClientOutbound.h"
#include <map>
namespace tonlib {
class ExtClientOutboundImp : public ExtClientOutbound {
public:
ExtClientOutboundImp(td::unique_ptr<ExtClientOutbound::Callback> callback) : callback_(std::move(callback)) {
}
void check_ready(td::Promise<td::Unit> promise) override {
promise.set_error(td::Status::Error("Not supported"));
}
void send_query(std::string name, td::BufferSlice data, td::Timestamp timeout,
td::Promise<td::BufferSlice> promise) override {
auto query_id = next_query_id_++;
queries_[query_id] = std::move(promise);
callback_->request(query_id, data.as_slice().str());
}
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()) {
promise.set_error(td::Status::Error(400, "Unknown query id"));
}
it->second.set_result(std::move(r_data));
queries_.erase(it);
promise.set_value(td::Unit());
}
private:
td::unique_ptr<ExtClientOutbound::Callback> callback_;
td::int64 next_query_id_{1};
std::map<td::int64, td::Promise<td::BufferSlice>> queries_;
void tear_down() override {
for (auto &it : queries_) {
it.second.set_error(td::Status::Error(400, "Query cancelled"));
}
queries_.clear();
}
};
td::actor::ActorOwn<ExtClientOutbound> ExtClientOutbound::create(td::unique_ptr<Callback> callback) {
return td::actor::create_actor<ExtClientOutboundImp>("ExtClientOutbound", std::move(callback));
}
} // namespace tonlib

View File

@ -0,0 +1,37 @@
/*
This file is part of TON Blockchain Library.
TON Blockchain Library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser 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 Library 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with TON Blockchain Library. If not, see <http://www.gnu.org/licenses/>.
Copyright 2017-2019 Telegram Systems LLP
*/
#pragma once
#include "td/actor/actor.h"
#include "adnl/adnl-ext-client.h"
namespace tonlib {
class ExtClientOutbound : public ton::adnl::AdnlExtClient {
public:
class Callback {
public:
virtual ~Callback() {
}
virtual void request(td::int64 id, std::string data) = 0;
};
virtual void on_query_result(td::int64 id, td::Result<td::BufferSlice> r_data, td::Promise<td::Unit> promise) = 0;
static td::actor::ActorOwn<ExtClientOutbound> create(td::unique_ptr<Callback> callback);
};
} // namespace tonlib