1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-03-09 15:40:10 +00:00

pow-testgiver support

This commit is contained in:
ton 2020-07-06 17:07:20 +03:00
parent dbde9c1c40
commit f064b1047a
257 changed files with 6665 additions and 2608 deletions

View file

@ -39,11 +39,11 @@ char *str_dup(Slice str) {
string implode(const vector<string> &v, char delimiter) {
string result;
for (auto &str : v) {
if (!result.empty()) {
for (size_t i = 0; i < v.size(); i++) {
if (i != 0) {
result += delimiter;
}
result += str;
result += v[i];
}
return result;
}
@ -110,21 +110,32 @@ Result<string> hex_decode(Slice hex) {
return std::move(result);
}
string hex_encode(Slice data) {
const char *hex = "0123456789abcdef";
string res;
res.reserve(2 * data.size());
for (unsigned char c : data) {
res.push_back(hex[c >> 4]);
res.push_back(hex[c & 15]);
}
return res;
}
static bool is_url_char(char c) {
return is_alnum(c) || c == '-' || c == '.' || c == '_' || c == '~';
}
string url_encode(Slice str) {
size_t length = 3 * str.size();
for (auto c : str) {
string url_encode(Slice data) {
size_t length = 3 * data.size();
for (auto c : data) {
length -= 2 * is_url_char(c);
}
if (length == str.size()) {
return str.str();
if (length == data.size()) {
return data.str();
}
string result;
result.reserve(length);
for (auto c : str) {
for (auto c : data) {
if (is_url_char(c)) {
result += c;
} else {
@ -138,6 +149,17 @@ string url_encode(Slice str) {
return result;
}
string buffer_to_hex(Slice buffer) {
const char *hex = "0123456789ABCDEF";
string res(2 * buffer.size(), '\0');
for (std::size_t i = 0; i < buffer.size(); i++) {
auto c = buffer.ubegin()[i];
res[2 * i] = hex[c & 15];
res[2 * i + 1] = hex[c >> 4];
}
return res;
}
namespace {
template <class F>
@ -181,17 +203,6 @@ bool is_zero_or_one(unsigned char c) {
} // namespace
string buffer_to_hex(Slice buffer) {
const char *hex = "0123456789ABCDEF";
string res(2 * buffer.size(), '\0');
for (std::size_t i = 0; i < buffer.size(); i++) {
auto c = buffer.ubegin()[i];
res[2 * i] = hex[c & 15];
res[2 * i + 1] = hex[c >> 4];
}
return res;
}
std::string zero_encode(Slice data) {
return x_encode(data, is_zero);
}