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

updated fift

updated fift
updated some smartcontracts
added partial support for hardforks
This commit is contained in:
ton 2019-10-01 14:07:35 +04:00
parent 2845f9a2cc
commit 841d5ebac2
16 changed files with 202 additions and 39 deletions

View file

@ -79,7 +79,7 @@ class SourceLookup {
if (os_time_) {
return os_time_->now();
}
return static_cast<td::uint32>(td::Time::now());
return static_cast<td::uint32>(td::Clocks::system());
}
protected:

View file

@ -942,7 +942,9 @@ void interpret_fetch(vm::Stack& stack, int mode) {
auto n = stack.pop_smallint_range(256 + (mode & 1));
auto cs = stack.pop_cellslice();
if (!cs->have(n)) {
stack.push(std::move(cs));
if (mode & 2) {
stack.push(std::move(cs));
}
stack.push_bool(false);
if (!(mode & 4)) {
throw IntError{"end of data while reading integer from cell"};

View file

@ -628,7 +628,7 @@ bool Op::generate_code_step(Stack& stack) {
stack.opt_show();
StackLayout layout1 = stack.vars();
bool next_empty = next->is_empty();
stack.o << (next_empty ? "WHILEEND:<{" : "WHILE:<{");
stack.o << "WHILE:<{";
stack.o.indent();
stack.forget_const();
block0->generate_code_all(stack);
@ -638,7 +638,7 @@ bool Op::generate_code_step(Stack& stack) {
stack.modified();
stack.o.undent();
Stack stack_copy{stack};
stack.o << (next_empty ? "}>" : "}>DO<{");
stack.o << (next_empty ? "}>DO:" : "}>DO<{");
if (!next_empty) {
stack.o.indent();
}

View file

@ -0,0 +1,69 @@
#!/usr/bin/env fift -s
"TonUtil.fif" include
{ ."usage: " @' $0 type ." <filename-base> <subwallet-id> <order-file> [<savefile>]" cr
."Creates a request with up to 254 orders loaded from <order-file> to high-load v2 (sub)wallet created by new-highload-v2-wallet.fif, with private key loaded from file <filename-base>.pk "
."and address from <filename-base><subwallet-id>.addr, and saves it into <savefile>.boc ('wallet-query.boc' by default)" cr
."<order-file> is a text file with lines `SEND <dest-addr> <amount>`" cr 1 halt
} : usage
$# dup 3 < swap 4 > or ' usage if
$1 =: file-base
$2 parse-int dup 32 fits ' usage ifnot =: subwallet-id // parse subwallet-id
{ subwallet-id (.) $+ } : +subwallet
$3 =: order-file
def? $4 { @' $4 } { "wallet-query" } cond constant savefile
3 constant send-mode // mode for SENDRAWMSG: +1 - sender pays fees, +2 - ignore errors
60 constant timeout // external message expires in 60 seconds
file-base +subwallet +".addr" load-address
2dup 2constant wallet_addr
."Source wallet address = " 2dup .addr cr 6 .Addr cr
file-base +".pk" load-keypair nip constant wallet_pk
variable orders dictnew orders !
variable order# order# 0!
// c --
{ <s order# @ dup 254 >= abort"more than 254 orders"
orders @ 16 udict!+ not abort"cannot add order to dictionary"
orders ! order# 1+!
} : add-order
// b body -- b'
{ tuck <s 2dup s-fits? not rot over 1 i, -rot
{ drop swap ref, } { s, nip } cond
} : append-msg-body
// ng wc addr bounce body -- c
{ <b b{01} s, rot 1 i, b{000100} s, 2swap addr, rot Gram,
0 9 64 32 + + 1+ u, swap append-msg-body b>
} : create-int-msg
// ng wc addr bnc --
{ ."Transferring " 3 roll .GR ."to account "
-rot 2dup 4 pick 7 + .Addr ." = " .addr ." bounce=" . cr
} : .transfer
// addr$ ng -- c
{ swap parse-smc-addr // ng wc addr bnc
2over 2over .transfer
<b 0 32 u, b> create-int-msg
} : create-simple-transfer
// c m -- c'
{ <b swap 8 u, swap ref, b> } : create-order
// addr$ ng --
{ create-simple-transfer send-mode create-order add-order } : send
{ bl word bl word $>GR send } : SEND
// parse order file
order-file include
// create external message
now timeout + 32 << <b orders @ dict, b> hashu 32 1<<1- and + =: query_id
<b subwallet-id 32 i, query_id 64 u, orders @ dict, b>
dup ."signing message: " <s csr. cr
dup hashu wallet_pk ed25519_sign_uint
<b b{1000100} s, wallet_addr addr, 0 Gram, b{00} s,
swap B, swap <s s, b>
dup ."resulting external message: " <s csr. cr
2 boc+>B dup Bx. cr
."Query_id is " query_id dup . ."= 0x" X. cr
savefile +".boc" tuck B>file
."(Saved to file " type .")" cr

View file

@ -0,0 +1,47 @@
#!/usr/bin/env fift -s
"TonUtil.fif" include
"Asm.fif" include
{ ."usage: " @' $0 type ." <workchain-id> <subwallet-id> [<filename-base>]" cr
."Creates a new v2 high-load wallet in the specified workchain, with the controlling private key saved to or loaded from <filename-base>.pk "
."('new-wallet.pk' by default)" cr
."<subwallet-id> is the 32-bit identifier of this subwallet among all controlled by the same private key" cr 1 halt
} : usage
$# 2- -2 and ' usage if
$1 parse-workchain-id =: wc // set workchain id from command line argument
$2 parse-int dup =: subwallet-id // parse subwallet-id
32 fits ' usage ifnot
{ subwallet-id (.) $+ } : +subwallet
def? $3 { @' $3 } { "new-wallet" } cond constant file-base
65536 constant timeout // init query times out in 65536 seconds
."Creating new v2 high-load wallet in workchain " wc .
."with subwallet id " subwallet-id . cr
// Create new high-load wallet; source code included from `highload-wallet-v2-code.fif`
"highload-wallet-v2-code.fif" include
// code
<b subwallet-id 32 i, 0 64 u,
file-base +".pk" load-generate-keypair
constant wallet_pk
B, false 1 i,
b> // data
null // no libraries
<b b{0011} s, 3 roll ref, rot ref, swap dict, b> // create StateInit
dup ."StateInit: " <s csr. cr
dup hashu wc swap 2dup 2constant wallet_addr
."new wallet address = " 2dup .addr cr
2dup file-base +subwallet +".addr" save-address-verbose
."Non-bounceable address (for init): " 2dup 7 .Addr cr
."Bounceable address (for later access): " 6 .Addr cr
now timeout + 32 << 1- dup =: query_id
."Init query_id is " dup . ."(0x" X._ .")" cr
<b subwallet-id 32 i, query_id 64 u, false 1 i, b>
dup ."signing message: " <s csr. cr
dup hashu wallet_pk ed25519_sign_uint rot
<b b{1000100} s, wallet_addr addr, b{000010} s, swap <s s, b{0} s, swap B, swap <s s, b>
dup ."External message for initialization is " <s csr. cr
2 boc+>B dup Bx. cr
file-base +subwallet +"-query.boc" tuck B>file
."(Saved wallet creating query to file " type .")" cr