mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
initial commit
This commit is contained in:
commit
c2da007f40
1610 changed files with 398047 additions and 0 deletions
21
common/CMakeLists.txt
Normal file
21
common/CMakeLists.txt
Normal file
|
@ -0,0 +1,21 @@
|
|||
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
|
||||
|
||||
set(COMMON_SOURCE
|
||||
checksum.h
|
||||
errorcode.h
|
||||
status.h
|
||||
io.hpp
|
||||
|
||||
errorlog.h
|
||||
errorlog.cpp
|
||||
)
|
||||
|
||||
|
||||
add_library(common STATIC ${COMMON_SOURCE})
|
||||
|
||||
target_include_directories(common PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>/..
|
||||
${OPENSSL_INCLUDE_DIR}
|
||||
)
|
||||
target_link_libraries(common PRIVATE tdutils ton_crypto )
|
33
common/checksum.h
Normal file
33
common/checksum.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
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/utils/int_types.h"
|
||||
#include "crypto/common/bitstring.h"
|
||||
#include "td/utils/crypto.h"
|
||||
|
||||
namespace td {
|
||||
|
||||
inline Bits256 sha256_bits256(Slice data) {
|
||||
Bits256 id;
|
||||
sha256(data, id.as_slice());
|
||||
return id;
|
||||
}
|
||||
|
||||
} // namespace td
|
52
common/delay.h
Normal file
52
common/delay.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
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"
|
||||
|
||||
namespace ton {
|
||||
|
||||
template <typename T>
|
||||
class DelayedAction : public td::actor::Actor {
|
||||
public:
|
||||
DelayedAction(T promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
void set_timer(td::Timestamp t) {
|
||||
alarm_timestamp() = t;
|
||||
}
|
||||
void alarm() override {
|
||||
promise_();
|
||||
stop();
|
||||
}
|
||||
|
||||
static void create(T promise, td::Timestamp t) {
|
||||
auto A = td::actor::create_actor<DelayedAction>("delayed", std::move(promise));
|
||||
td::actor::send_closure(A, &DelayedAction::set_timer, t);
|
||||
A.release();
|
||||
}
|
||||
|
||||
private:
|
||||
T promise_;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
void delay_action(T promise, td::Timestamp timeout) {
|
||||
DelayedAction<T>::create(std::move(promise), timeout);
|
||||
}
|
||||
} // namespace ton
|
25
common/errorcode.h
Normal file
25
common/errorcode.h
Normal file
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
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
|
||||
|
||||
namespace ton {
|
||||
|
||||
enum ErrorCode : int { failure = 601, error = 602, warning = 603, protoviolation = 621, notready = 651, timeout = 652 };
|
||||
|
||||
}
|
74
common/errorlog.cpp
Normal file
74
common/errorlog.cpp
Normal file
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
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 "errorlog.h"
|
||||
#include "checksum.h"
|
||||
|
||||
#include "td/utils/port/FileFd.h"
|
||||
#include "td/utils/filesystem.h"
|
||||
#include "td/utils/port/path.h"
|
||||
#include "td/utils/Time.h"
|
||||
|
||||
#include <mutex>
|
||||
|
||||
namespace ton {
|
||||
|
||||
namespace errorlog {
|
||||
|
||||
td::FileFd fd;
|
||||
std::mutex init_mutex_;
|
||||
std::string files_path_;
|
||||
|
||||
void ErrorLog::create(std::string db_root) {
|
||||
init_mutex_.lock();
|
||||
if (!fd.empty()) {
|
||||
init_mutex_.unlock();
|
||||
return;
|
||||
}
|
||||
auto path = db_root + "/error";
|
||||
td::mkdir(path).ensure();
|
||||
files_path_ = path + "/files";
|
||||
td::mkdir(files_path_).ensure();
|
||||
auto R = td::FileFd::open(path + "/log.txt",
|
||||
td::FileFd::Flags::Write | td::FileFd::Flags::Append | td::FileFd::Flags::Create);
|
||||
R.ensure();
|
||||
fd = R.move_as_ok();
|
||||
init_mutex_.unlock();
|
||||
}
|
||||
|
||||
void ErrorLog::log(std::string error) {
|
||||
error = PSTRING() << "[" << td::Clocks::system() << "] " << error << "\n";
|
||||
CHECK(!fd.empty());
|
||||
auto s = td::Slice{error};
|
||||
while (s.size() > 0) {
|
||||
auto R = fd.write(s);
|
||||
R.ensure();
|
||||
s.remove_prefix(R.move_as_ok());
|
||||
}
|
||||
}
|
||||
|
||||
void ErrorLog::log_file(td::BufferSlice data) {
|
||||
auto filename = sha256_bits256(data.as_slice());
|
||||
auto path = files_path_ + "/" + filename.to_hex();
|
||||
|
||||
td::write_file(path, data.as_slice()).ensure();
|
||||
}
|
||||
|
||||
} // namespace errorlog
|
||||
|
||||
} // namespace ton
|
37
common/errorlog.h
Normal file
37
common/errorlog.h
Normal 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 <string>
|
||||
#include "td/utils/buffer.h"
|
||||
|
||||
namespace ton {
|
||||
|
||||
namespace errorlog {
|
||||
|
||||
class ErrorLog {
|
||||
public:
|
||||
static void create(std::string db_root);
|
||||
static void log(std::string error);
|
||||
static void log_file(td::BufferSlice data);
|
||||
};
|
||||
|
||||
} // namespace errorlog
|
||||
|
||||
} // namespace ton
|
45
common/io.hpp
Normal file
45
common/io.hpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
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/utils/buffer.h"
|
||||
#include "td/utils/misc.h"
|
||||
#include "td/utils/crypto.h"
|
||||
#include "td/utils/format.h"
|
||||
#include "td/utils/base64.h"
|
||||
#include "tl-utils/tl-utils.hpp"
|
||||
|
||||
#include "common/errorcode.h"
|
||||
#include "common/status.h"
|
||||
#include "keys/keys.hpp"
|
||||
|
||||
#include "crypto/common/bitstring.h"
|
||||
|
||||
namespace td {
|
||||
|
||||
template <unsigned size>
|
||||
StringBuilder &operator<<(StringBuilder &stream, const td::BitArray<size> &x) {
|
||||
return stream << td::base64_encode(as_slice(x));
|
||||
}
|
||||
|
||||
inline StringBuilder &operator<<(StringBuilder &stream, const ton::PublicKeyHash &value) {
|
||||
return stream << value.bits256_value();
|
||||
}
|
||||
|
||||
} // namespace td
|
33
common/status.h
Normal file
33
common/status.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
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/utils/Status.h"
|
||||
|
||||
namespace td {
|
||||
|
||||
inline td::Status status_prefix(td::Status &&status, std::string prefix) {
|
||||
if (status.is_ok()) {
|
||||
return std::move(status);
|
||||
} else {
|
||||
return td::Status::Error(status.code(), prefix + status.message().str());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace td
|
Loading…
Add table
Add a link
Reference in a new issue