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

updated lite-client

This commit is contained in:
ton 2020-03-31 17:11:56 +04:00
parent 4dd5eea11f
commit 4b5dd4525e
27 changed files with 204 additions and 29 deletions

View file

@ -599,6 +599,18 @@ void interpret_set_config_param(vm::Stack& stack) {
}
}
void interpret_check_config_param(vm::Stack& stack) {
int x = stack.pop_smallint_range(0x7fffffff, 0x80000000);
Ref<vm::Cell> value = stack.pop_cell();
if (verbosity > 2 && x >= 0) {
std::cerr << "checking validity as configuration parameter #" << x << " of ";
// vm::load_cell_slice(value).print_rec(std::cerr);
block::gen::ConfigParam{x}.print_ref(std::cerr, value);
std::cerr << std::endl;
}
stack.push_bool(x < 0 || block::gen::ConfigParam{x}.validate_ref(value));
}
void interpret_is_shard_state(vm::Stack& stack) {
Ref<vm::Cell> cell = stack.pop_cell();
if (verbosity > 4) {
@ -668,6 +680,7 @@ void init_words_custom(fift::Dictionary& d) {
d.def_stack_word("globalid! ", interpret_set_global_id);
d.def_stack_word("config@ ", interpret_get_config_param);
d.def_stack_word("config! ", interpret_set_config_param);
d.def_stack_word("config-valid? ", interpret_check_config_param);
d.def_stack_word("(configdict) ", interpret_get_config_dict);
d.def_stack_word("register_smc ", interpret_register_smartcontract);
d.def_stack_word("set_config_smc ", interpret_set_config_smartcontract);

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 "common/refcnt.hpp"
@ -284,7 +284,7 @@ class BitSliceGen {
ensure_throw(set_size_bool(bits));
return *this;
}
BitSliceGen subslice(unsigned from, unsigned bits) const& {
BitSliceGen subslice(unsigned from, unsigned bits) const & {
return BitSliceGen(*this, from, bits);
}
BitSliceGen subslice(unsigned from, unsigned bits) && {
@ -575,6 +575,14 @@ class BitArray {
std::string to_binary() const {
return bitstring::bits_to_binary(cbits(), size());
}
long from_hex(td::Slice hex_str, bool allow_partial = false) {
auto res = bitstring::parse_bitstring_hex_literal(data(), m, hex_str.begin(), hex_str.end());
return allow_partial ? std::min<long>(res, n) : (res == n ? res : -1);
}
long from_binary(td::Slice bin_str, bool allow_partial = false) {
auto res = bitstring::parse_bitstring_binary_literal(bits(), n, bin_str.begin(), bin_str.end());
return allow_partial ? std::min<long>(res, n) : (res == n ? res : -1);
}
int compare(const BitArray& other) const {
return (n % 8 == 0) ? std::memcmp(data(), other.data(), n / 8) : bitstring::bits_memcmp(bits(), other.bits(), n);
}

View file

@ -247,3 +247,16 @@ recursive append-long-bytes {
// ( x a b -- a<=x<=b )
{ 2 pick >= -rot >= and } : in-range?
// ( c i -- ? ) Checks whether c is a valid value for config param #i
def? config-valid? {
{ nip 0>= { ."warning: cannot check validity of configuration parameter value, use create-state instead of fift to check validity" cr } if
true } : config-valid?
} ifnot
{ dup -1000 = { drop <s ref@ <s 12 u@ 0xFF0 = } {
dup -1001 = { drop <s ref@ <s 12 u@ 0xFF0 = } {
over null? { 2drop true } {
config-valid?
} cond } cond } cond
} : is-valid-config?

View file

@ -41,13 +41,7 @@ boc-filename dup "null" $= {
} cond
=: param-value
{ dup -1000 = { drop <s ref@ <s 12 u@ 0xFF0 = } {
dup -1001 = { drop <s ref@ <s 12 u@ 0xFF0 = } {
2drop true
} cond } cond
} : is-valid-config?
dup param-idx is-valid-config? not abort"not a valid value for chosen configuration parameter"
param-value param-idx is-valid-config? not abort"not a valid value for chosen configuration parameter"
critical { ."Critical" } { ."Non-critical" } cond
." configuration proposal will expire at " expire-at . ."(in " expire-in . ."seconds)" cr

View file

@ -30,8 +30,6 @@ file-base +".pk" load-keypair nip constant config_pk
boc-filename file>B B>boc
dup <s csr. cr
{ 2drop true } : is-valid-config?
dup idx is-valid-config? not abort"not a valid value for chosen configuration parameter"
// create a message

View file

@ -375,4 +375,10 @@ const TLB* TypenameLookup::lookup(std::string str) const {
return it != types.end() ? it->second : nullptr;
}
const TLB* TypenameLookup::lookup(td::Slice str) const {
auto it = std::lower_bound(types.begin(), types.end(), str,
[](const auto& x, const auto& y) { return td::Slice(x.first) < y; });
return it != types.end() && td::Slice(it->first) == str ? it->second : nullptr;
}
} // namespace tlb

View file

@ -594,6 +594,7 @@ class TypenameLookup {
bool register_type(const char* name, const TLB* tp);
bool register_types(register_func_t func);
const TLB* lookup(std::string str) const;
const TLB* lookup(td::Slice str) const;
};
} // namespace tlb

View file

@ -289,6 +289,31 @@ Ref<Atom> StackEntry::as_atom() && {
return move_as<Atom, t_atom>();
}
bool StackEntry::for_each_scalar(const std::function<bool(const StackEntry&)>& func) const {
auto t = as<Tuple, t_tuple>();
if (t.not_null()) {
for (const auto& entry : *t) {
if (!entry.for_each_scalar(func)) {
return false;
}
}
return true;
} else {
return func(*this);
}
}
void StackEntry::for_each_scalar(const std::function<void(const StackEntry&)>& func) const {
auto t = as<Tuple, t_tuple>();
if (t.not_null()) {
for (const auto& entry : *t) {
entry.for_each_scalar(func);
}
} else {
func(*this);
}
}
const StackEntry& tuple_index(const Tuple& tup, unsigned idx) {
if (idx >= tup->size()) {
throw VmError{Excno::range_chk, "tuple index out of range"};
@ -672,6 +697,21 @@ void Stack::push_maybe_cellslice(Ref<CellSlice> cs) {
push_maybe(std::move(cs));
}
bool Stack::for_each_scalar(const std::function<bool(const StackEntry&)>& func) const {
for (const auto& v : stack) {
if (!v.for_each_scalar(func)) {
return false;
}
}
return true;
}
void Stack::for_each_scalar(const std::function<void(const StackEntry&)>& func) const {
for (const auto& v : stack) {
v.for_each_scalar(func);
}
}
/*
*
* SERIALIZE/DESERIALIZE STACK VALUES

View file

@ -285,6 +285,8 @@ class StackEntry {
Ref<T> as_object() && {
return dynamic_move_as<T, t_object>();
}
bool for_each_scalar(const std::function<bool(const StackEntry&)>& func) const;
void for_each_scalar(const std::function<void(const StackEntry&)>& func) const;
void dump(std::ostream& os) const;
void print_list(std::ostream& os) const;
std::string to_string() const;
@ -549,6 +551,8 @@ class Stack : public td::CntObject {
push(std::move(val));
}
}
bool for_each_scalar(const std::function<bool(const StackEntry&)>& func) const;
void for_each_scalar(const std::function<void(const StackEntry&)>& func) const;
// mode: +1 = add eoln, +2 = Lisp-style lists
void dump(std::ostream& os, int mode = 1) const;
bool serialize(vm::CellBuilder& cb, int mode = 0) const;