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

updated tonlib + fixes in vm

This commit is contained in:
ton 2020-02-20 19:56:18 +04:00
parent 28735ddc9e
commit efd47af432
42 changed files with 750 additions and 307 deletions

View file

@ -14,7 +14,7 @@
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
Copyright 2017-2020 Telegram Systems LLP
*/
#include <tl/tlblib.hpp>
@ -138,22 +138,23 @@ bool TLB::print_skip(PrettyPrinter& pp, vm::CellSlice& cs) const {
return pp.fail("invalid value");
}
pp.raw_nl();
cs_copy.print_rec(pp.os, pp.indent);
return pp.mkindent() && pp.close();
return cs_copy.print_rec(pp.os, &pp.limit, pp.indent) && pp.mkindent() && pp.close();
}
bool TLB::print_special(PrettyPrinter& pp, vm::CellSlice& cs) const {
pp.open("raw@");
pp << *this << ' ';
pp.raw_nl();
cs.print_rec(pp.os, pp.indent);
return pp.mkindent() && pp.close();
return cs.print_rec(pp.os, &pp.limit, pp.indent) && pp.mkindent() && pp.close();
}
bool TLB::print_ref(PrettyPrinter& pp, Ref<vm::Cell> cell_ref) const {
if (cell_ref.is_null()) {
return pp.fail("null cell reference");
}
if (!pp.register_recursive_call()) {
return pp.fail("too many recursive calls while printing a TL-B value");
}
bool is_special;
auto cs = load_cell_slice_special(std::move(cell_ref), is_special);
if (is_special) {
@ -163,18 +164,21 @@ bool TLB::print_ref(PrettyPrinter& pp, Ref<vm::Cell> cell_ref) const {
}
}
bool TLB::print_skip(std::ostream& os, vm::CellSlice& cs, int indent) const {
bool TLB::print_skip(std::ostream& os, vm::CellSlice& cs, int indent, int rec_limit) const {
PrettyPrinter pp{os, indent};
pp.set_limit(rec_limit);
return pp.fail_unless(print_skip(pp, cs));
}
bool TLB::print(std::ostream& os, const vm::CellSlice& cs, int indent) const {
bool TLB::print(std::ostream& os, const vm::CellSlice& cs, int indent, int rec_limit) const {
PrettyPrinter pp{os, indent};
pp.set_limit(rec_limit);
return pp.fail_unless(print(pp, cs));
}
bool TLB::print_ref(std::ostream& os, Ref<vm::Cell> cell_ref, int indent) const {
bool TLB::print_ref(std::ostream& os, Ref<vm::Cell> cell_ref, int indent, int rec_limit) const {
PrettyPrinter pp{os, indent};
pp.set_limit(rec_limit);
return pp.fail_unless(print_ref(pp, std::move(cell_ref)));
}

View file

@ -14,7 +14,7 @@
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
Copyright 2017-2020 Telegram Systems LLP
*/
#pragma once
#include <iostream>
@ -208,12 +208,12 @@ class TLB {
bool print(PrettyPrinter& pp, Ref<vm::CellSlice> cs_ref) const {
return print(pp, *cs_ref);
}
bool print_skip(std::ostream& os, vm::CellSlice& cs, int indent = 0) const;
bool print(std::ostream& os, const vm::CellSlice& cs, int indent = 0) const;
bool print(std::ostream& os, Ref<vm::CellSlice> cs_ref, int indent = 0) const {
return print(os, *cs_ref, indent);
bool print_skip(std::ostream& os, vm::CellSlice& cs, int indent = 0, int rec_limit = 0) const;
bool print(std::ostream& os, const vm::CellSlice& cs, int indent = 0, int rec_limit = 0) const;
bool print(std::ostream& os, Ref<vm::CellSlice> cs_ref, int indent = 0, int rec_limit = 0) const {
return print(os, *cs_ref, indent, rec_limit);
}
bool print_ref(std::ostream& os, Ref<vm::Cell> cell_ref, int indent = 0) const;
bool print_ref(std::ostream& os, Ref<vm::Cell> cell_ref, int indent = 0, int rec_limit = 0) const;
std::string as_string_skip(vm::CellSlice& cs, int indent = 0) const;
std::string as_string(const vm::CellSlice& cs, int indent = 0) const;
std::string as_string(Ref<vm::CellSlice> cs_ref, int indent = 0) const {
@ -456,15 +456,20 @@ bool store_from(vm::CellBuilder& cb, const T& tlb_type, Ref<vm::CellSlice> field
namespace tlb {
struct PrettyPrinter {
enum { default_print_limit = 4096 };
std::ostream& os;
int indent;
int level;
bool failed;
bool nl_used;
int mode;
int limit{default_print_limit};
PrettyPrinter(std::ostream& _os, int _indent = 0, int _mode = 1)
: os(_os), indent(_indent), level(0), failed(false), nl_used(false), mode(_mode) {
}
PrettyPrinter(int _limit, std::ostream& _os, int _indent = 0, int _mode = 1)
: os(_os), indent(_indent), level(0), failed(false), nl_used(false), mode(_mode), limit(_limit) {
}
~PrettyPrinter();
bool ok() const {
return !failed && !level;
@ -489,6 +494,14 @@ struct PrettyPrinter {
bool field_int(long long value, std::string name);
bool field_uint(unsigned long long value);
bool field_uint(unsigned long long value, std::string name);
bool register_recursive_call() {
return limit--;
}
void set_limit(int new_limit) {
if (new_limit > 0) {
limit = new_limit;
}
}
bool out(std::string str) {
os << str;
return true;