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

updated smartcontract code

- updated smartcontract code
- fixed bug in liteserver listening socket
- updated documentation
This commit is contained in:
ton 2019-10-14 11:13:23 +04:00
parent 38c3e39066
commit b978e27b2f
63 changed files with 3185 additions and 81 deletions

View file

@ -975,6 +975,8 @@ x{F82} @Defop(4u) GETPARAM
x{F823} @Defop NOW
x{F824} @Defop BLOCKLT
x{F825} @Defop LTIME
x{F826} @Defop BALANCE
x{F827} @Defop RANDSEED
x{F828} @Defop MYADDR
x{F829} @Defop CONFIGROOT
x{F830} @Defop CONFIGDICT

View file

@ -136,3 +136,15 @@ recursive append-long-bytes {
// S -- c
{ <b over $len { 0 32 u, swap 36 append-long-string } { nip } cond b>
} : simple-transfer-body
// ( S -- x ) parse public key
{ dup $len 48 <> abort"public key must be 48 characters long"
base64>B dup Blen 36 <> abort"public key must be 48 characters long"
34 B| 16 B>u@ over crc16 <> abort"crc16 mismatch in public key"
16 B>u@+ 0x3ee6 <> abort"invalid tag in public key"
256 B>u@
} : parse-pubkey
{ bl word parse-pubkey 1 'nop } ::_ PK'
// ( x -- S ) serialize public key
{ 256 u>B B{3ee6} swap B+ dup crc16 16 u>B B+ B>base64 } : pubkey>$
{ pubkey>$ type } : .pubkey

View file

@ -614,6 +614,43 @@ void interpret_str_reverse(vm::Stack& stack) {
stack.push_string(std::move(s));
}
void interpret_utf8_str_len(vm::Stack& stack) {
std::string s = stack.pop_string();
long long cnt = 0;
for (char c : s) {
if ((c & 0xc0) != 0x80) {
cnt++;
}
}
stack.push_smallint(cnt);
}
void interpret_utf8_str_split(vm::Stack& stack) {
stack.check_underflow(2);
unsigned c = stack.pop_smallint_range(0xffff);
std::string s = stack.pop_string();
if (c > s.size()) {
throw IntError{"not enough utf8 characters for cutting"};
}
auto it = s.begin();
for (; it < s.end(); ++it) {
if ((*it & 0xc0) != 0x80) {
if (!c) {
stack.push_string(std::string{s.begin(), it});
stack.push_string(std::string{it, s.end()});
return;
}
--c;
}
}
if (!c) {
stack.push_string(std::move(s));
stack.push_string(std::string{});
} else {
throw IntError{"not enough utf8 characters for cutting"};
}
}
void interpret_str_remove_trailing_int(vm::Stack& stack, int arg) {
char x = (char)(arg ? arg : stack.pop_long_range(127));
std::string s = stack.pop_string();
@ -1797,6 +1834,16 @@ void interpret_char(IntCtx& ctx) {
push_argcount(ctx, 1);
}
void interpret_char_internal(vm::Stack& stack) {
auto s = stack.pop_string();
int len = (s.size() < 10 ? (int)s.size() : 10);
int code = str_utf8_code(s.c_str(), len);
if (code < 0 || s.size() != (unsigned)len) {
throw IntError{"exactly one character expected"};
}
stack.push_smallint(code);
}
int parse_number(std::string s, td::RefInt256& num, td::RefInt256& denom, bool allow_frac = true,
bool throw_error = false) {
if (allow_frac) {
@ -2496,6 +2543,7 @@ void init_words_common(Dictionary& d) {
// char/string manipulation
d.def_active_word("\"", interpret_quote_str);
d.def_active_word("char ", interpret_char);
d.def_stack_word("(char) ", interpret_char_internal);
d.def_ctx_word("emit ", interpret_emit);
d.def_ctx_word("space ", std::bind(interpret_emit_const, _1, ' '));
d.def_ctx_word("cr ", std::bind(interpret_emit_const, _1, '\n'));
@ -2515,6 +2563,8 @@ void init_words_common(Dictionary& d) {
d.def_stack_word("-trailing0 ", std::bind(interpret_str_remove_trailing_int, _1, '0'));
d.def_stack_word("$len ", interpret_str_len);
d.def_stack_word("Blen ", interpret_bytes_len);
d.def_stack_word("$Len ", interpret_utf8_str_len);
d.def_stack_word("$Split ", interpret_utf8_str_split);
d.def_ctx_word("Bx. ", std::bind(interpret_bytes_hex_print_raw, _1, true));
d.def_stack_word("B>X ", std::bind(interpret_bytes_to_hex, _1, true));
d.def_stack_word("B>x ", std::bind(interpret_bytes_to_hex, _1, false));