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

updated fift + bugfixes

This commit is contained in:
ton 2019-12-05 16:51:51 +04:00
parent 090e0c16eb
commit ceaed40ac4
28 changed files with 530 additions and 108 deletions

View file

@ -137,16 +137,21 @@ _ perform_action(cfg_dict, public_key, action, cs) {
}
}
slice get_validator_descr(int idx) inline_ref {
(slice, int) get_validator_descr(int idx) inline_ref {
var vset = config_param(34);
if (vset.null?()) {
return null();
return (null(), 0);
}
var cs = begin_parse(vset);
cs~skip_bits(8 + 32 + 32 + 16 + 16);
;; validators_ext#12 utime_since:uint32 utime_until:uint32
;; total:(## 16) main:(## 16) { main <= total } { main >= 1 }
;; total_weight:uint64
throw_unless(40, cs~load_uint(8) == 0x12);
cs~skip_bits(32 + 32 + 16 + 16);
int total_weight = cs~load_uint(64);
var dict = begin_cell().store_slice(cs).end_cell();
var (value, _) = dict.udict_get?(16, idx);
return value;
return (value, total_weight);
}
(int, int) unpack_validator_descr(slice cs) inline {
@ -158,33 +163,51 @@ slice get_validator_descr(int idx) inline_ref {
return (cs~load_uint(256), cs~load_uint(64));
}
slice create_new_entry(cs) inline {
return begin_cell().store_int(false, 1).store_uint(0, 64).store_uint(0, 256).store_slice(cs).end_cell().begin_parse();
(cell, int, int, slice) new_proposal(cs) inline {
return (null(), 0, 0, cs);
}
(cell, int, int, slice) unpack_suggestion(slice cs) inline {
(cell, int, int, slice) unpack_proposal(slice cs) inline {
return (cs~load_dict(), cs~load_uint(64), cs~load_uint(256), cs);
}
builder pack_suggestion(cell voters, int sum_weight, int vset_id, slice body) inline {
builder pack_proposal(cell voters, int sum_weight, int vset_id, slice body) inline {
return begin_cell().store_dict(voters).store_uint(sum_weight, 64).store_uint(vset_id, 256).store_slice(body);
}
cell register_vote(vote_dict, action, cs, idx, weight) {
(cell, slice) register_vote(vote_dict, action, cs, idx, weight, total_weight, cur_vset_id) {
int hash = 0;
int found? = 0;
var entry = null();
if (action & 1) {
hash = slice_hash(cs);
(entry, var found?) = vote_dict.udict_get?(256, hash);
ifnot (found?) {
entry = create_new_entry(cs);
}
(entry, found?) = vote_dict.udict_get?(256, hash);
} else {
hash = cs.preload_uint(256);
(entry, var found?) = vote_dict.udict_get?(256, hash);
(entry, found?) = vote_dict.udict_get?(256, hash);
throw_unless(42, found?);
}
return vote_dict;
var (voters, sum_weight, vset_id, body) = found? ? unpack_proposal(entry) : (null(), 0, cur_vset_id, cs);
if (vset_id != cur_vset_id) {
voters = null();
sum_weight = 0;
vset_id = cur_vset_id;
}
var (_, found?) = voters.udict_get?(16, idx);
ifnot (found?) {
voters~udict_set_builder(16, idx, begin_cell().store_uint(32, now()));
sum_weight += weight;
if (sum_weight * 3 > total_weight * 2) {
;; proposal accepted
vote_dict~udict_delete?(256, hash);
return (vote_dict, body);
} else {
vote_dict~udict_set_builder(256, hash, pack_proposal(voters, sum_weight, cur_vset_id, body));
return (vote_dict, null());
}
} else {
return (vote_dict, null());
}
}
() recv_external(slice in_msg) impure {
@ -198,15 +221,19 @@ cell register_vote(vote_dict, action, cs, idx, weight) {
throw_unless(33, msg_seqno == stored_seqno);
ifnot ((action - 0x566f7465) & -2) {
var idx = cs~load_uint(16);
var vdescr = get_validator_descr(idx);
var (vdescr, total_weight) = get_validator_descr(idx);
var (val_pubkey, weight) = unpack_validator_descr(vdescr);
throw_unless(34, check_signature(slice_hash(in_msg), signature, val_pubkey));
accept_message();
stored_seqno += 1;
store_data(cfg_dict, stored_seqno, public_key, vote_dict);
commit();
vote_dict = register_vote(vote_dict, action, cs, idx, weight);
(vote_dict, var accepted) = register_vote(vote_dict, action, cs, idx, weight, total_weight, config_param(34).cell_hash());
store_data(cfg_dict, stored_seqno, public_key, vote_dict);
ifnot (accepted.null?()) {
(cfg_dict, public_key) = perform_action(cfg_dict, public_key, accepted~load_uint(32), accepted);
store_data(cfg_dict, stored_seqno, public_key, vote_dict);
}
return ();
}
throw_unless(34, check_signature(slice_hash(in_msg), signature, public_key));

View file

@ -1,20 +1,41 @@
#!/usr/bin/fift -s
"TonUtil.fif" include
"GetOpt.fif" include
{ show-options-help 1 halt } : usage
true =: allow-bounce
false =: force-bounce
3 =: send-mode // mode for SENDRAWMSG: +1 - sender pays fees, +2 - ignore errors
60 =: timeout // external message expires in 60 seconds
begin-options
" <filename-base> <subwallet-id> <order-file> [-n|-b] [-t<timeout>] [<savefile>]" +cr +tab
+"Creates a request with up to 254 orders loaded from <order-file> to high-load (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>`"
generic-help
"n" "--no-bounce" { false =: allow-bounce } short-long-option
"Clears bounce flag" option-help
"b" "--force-bounce" { true =: force-bounce } short-long-option
"Forces bounce flag" option-help
"t" "--timeout" { parse-int =: timeout } short-long-option-arg
"Sets expiration timeout in seconds (" timeout (.) $+ +" by default)" option-help
"m" "--mode" { parse-int =: send-mode } short-long-option-arg
"Sets transfer mode (0..255) for SENDRAWMSG (" send-mode (.) $+ +" by default)"
option-help
"h" "--help" { usage } short-long-option
"Shows a help message" option-help
parse-options
{ ."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
4 :$1..n
$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
$4 "wallet-query" replace-if-null =: savefile
file-base +subwallet +".addr" load-address
2dup 2constant wallet_addr
@ -41,7 +62,7 @@ variable order# order# 0!
-rot 2dup 4 pick 7 + .Addr ." = " .addr ." bounce=" . cr
} : .transfer
// addr$ ng -- c
{ swap parse-smc-addr // ng wc addr bnc
{ swap parse-smc-addr force-bounce or allow-bounce and // ng wc addr bnc
2over 2over .transfer
<b 0 32 u, b> create-int-msg
} : create-simple-transfer

View file

@ -1,21 +1,42 @@
#!/usr/bin/fift -s
"TonUtil.fif" include
"GetOpt.fif" include
{ show-options-help 1 halt } : usage
true =: allow-bounce
false =: force-bounce
3 =: send-mode // mode for SENDRAWMSG: +1 - sender pays fees, +2 - ignore errors
60 =: timeout // external message expires in 60 seconds
begin-options
" <filename-base> <subwallet-id> <seqno> <order-file> [-n|-b] [-t<timeout>] [<savefile>]" +cr +tab
+"Creates a request with up to 254 orders loaded from <order-file> to high-load (sub)wallet created by new-highload-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>`"
generic-help
"n" "--no-bounce" { false =: allow-bounce } short-long-option
"Clears bounce flag" option-help
"b" "--force-bounce" { true =: force-bounce } short-long-option
"Forces bounce flag" option-help
"t" "--timeout" { parse-int =: timeout } short-long-option-arg
"Sets expiration timeout in seconds (" timeout (.) $+ +" by default)" option-help
"m" "--mode" { parse-int =: send-mode } short-long-option-arg
"Sets transfer mode (0..255) for SENDRAWMSG (" send-mode (.) $+ +" by default)"
option-help
"h" "--help" { usage } short-long-option
"Shows a help message" option-help
parse-options
{ ."usage: " @' $0 type ." <filename-base> <subwallet-id> <seqno> <order-file> [<savefile>]" cr
."Creates a request with up to 254 orders loaded from <order-file> to high-load (sub)wallet created by new-highload-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 4 < swap 5 > or ' usage if
5 :$1..n
$1 =: file-base
$2 parse-int dup 32 fits ' usage ifnot =: subwallet-id // parse subwallet-id
{ subwallet-id (.) $+ } : +subwallet
$3 parse-int =: seqno
$4 =: order-file
def? $5 { @' $5 } { "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
$5 "wallet-query" replace-if-null =: savefile
file-base +subwallet +".addr" load-address
2dup 2constant wallet_addr
@ -42,7 +63,7 @@ variable order# order# 0!
-rot 2dup 4 pick 7 + .Addr ." = " .addr ." bounce=" . cr
} : .transfer
// addr$ ng -- c
{ swap parse-smc-addr // ng wc addr bnc
{ swap parse-smc-addr force-bounce or allow-bounce and // ng wc addr bnc
2over 2over .transfer
<b 0 32 u, b> create-int-msg
} : create-simple-transfer

View file

@ -2,15 +2,16 @@
"TonUtil.fif" include
"Asm.fif" include
{ ."usage: " @' $0 type ." <workchain-id> <wallet-id> [<filename-base>]" cr
{ ."usage: " $0 type ." <workchain-id> <wallet-id> [<filename-base>]" cr
."Creates a new advanced wallet with unique 32-bit identifier <wallet-id> in specified workchain, with private key saved to or loaded from <filename-base>.pk" cr
."('new-wallet.pk' by default)" cr 1 halt
} : usage
$# 2- -2 and ' usage if
3 :$1..n
$1 parse-workchain-id =: wc // set workchain id from command line argument
$2 parse-int =: subwallet-id
def? $3 { @' $3 } { "new-wallet" } cond constant file-base
$3 "new-wallet" replace-if-null =: file-base
."Creating new advanced v3 wallet in workchain " wc . cr
."with unique wallet id " subwallet-id . cr

View file

@ -7,7 +7,7 @@
} : usage
$# 1 > ' usage if
1 :$1..n
$1 dup null? { drop "new-wallet" } if =: file-base
$1 "new-wallet" replace-if-null =: file-base
file-base +".addr" dup ."Loading wallet address from " type cr file>B 32 B|
dup Blen { 32 B>i@ } { drop Basechain } cond constant wallet_wc

View file

@ -1,7 +1,7 @@
#!/usr/bin/fift -s
"TonUtil.fif" include
{ ."usage: " @' $0 type ." <filename-base> <seqno> [<savefile>]" cr
{ ."usage: " $0 type ." <filename-base> <seqno> [<savefile>]" cr
."Creates a request to simple configuration smart contract requesting to change configuration smart contract code to the one currently stored in auto/config-code.fif, "
."with private key loaded from file <filename-base>.pk, "
."and saves it into <savefile>.boc ('config-query.boc' by default)" cr 1 halt
@ -15,9 +15,10 @@ true constant bounce
"auto/config-code.fif" constant config-source
100 constant interval // valid for 100 seconds
3 :$1..n
$1 =: file-base
$2 parse-int =: qseqno
def? $3 { @' $3 } { "config-query" } cond constant savefile
$3 "config-query" replace-if-null constant savefile
file-base +".addr" load-address
2dup 2constant config_addr

View file

@ -1,30 +1,52 @@
#!/usr/bin/fift -s
"TonUtil.fif" include
"GetOpt.fif" include
{ show-options-help 1 halt } : usage
"" =: comment // comment for simple transfers
true =: allow-bounce
false =: force-bounce
3 =: send-mode // mode for SENDRAWMSG: +1 - sender pays fees, +2 - ignore errors
60 =: timeout // external message expires in 60 seconds
begin-options
" <filename-base> <dest-addr> <seqno> <amount> [-n|-b] [-t<timeout>] [-B <body-boc>] [-C <comment>] [<savefile>]" +cr +tab
+"Creates a request to advanced wallet created by new-wallet-v2.fif, with private key loaded from file <filename-base>.pk "
+"and address from <filename-base>.addr, and saves it into <savefile>.boc ('wallet-query.boc' by default)"
generic-help
"n" "--no-bounce" { false =: allow-bounce } short-long-option
"Clears bounce flag" option-help
"b" "--force-bounce" { true =: force-bounce } short-long-option
"Forces bounce flag" option-help
"t" "--timeout" { parse-int =: timeout } short-long-option-arg
"Sets expiration timeout in seconds (" timeout (.) $+ +" by default)" option-help
"B" "--body" { =: body-boc-file } short-long-option-arg
"Sets the payload of the transfer message" option-help
"C" "--comment" { =: comment } short-long-option-arg
"Sets the comment to be sent in the transfer message" option-help
"m" "--mode" { parse-int =: send-mode } short-long-option-arg
"Sets transfer mode (0..255) for SENDRAWMSG (" send-mode (.) $+ +" by default)"
option-help
"h" "--help" { usage } short-long-option
"Shows a help message" option-help
parse-options
{ ."usage: " @' $0 type ." <filename-base> <dest-addr> <seqno> <amount> [-B <body-boc>] [<savefile>]" cr
."Creates a request to advanced wallet created by new-wallet-v2.fif, with private key loaded from file <filename-base>.pk "
."and address from <filename-base>.addr, and saves it into <savefile>.boc ('wallet-query.boc' by default)" cr 1 halt
} : usage
def? $6 { @' $5 "-B" $= { @' $6 =: body-boc-file [forget] $6 def? $7 { @' $7 =: $5 [forget] $7 } { [forget] $5 } cond
@' $# 2- =: $# } if } if
$# dup 4 < swap 5 > or ' usage if
5 :$1..n
true constant bounce
$1 =: file-base
$2 bounce parse-load-address =: bounce 2=: dest_addr
$2 bounce parse-load-address force-bounce or allow-bounce and =: bounce 2=: dest_addr
$3 parse-int =: seqno
$4 $>GR =: amount
def? $5 { @' $5 } { "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
$5 "wallet-query" replace-if-null =: savefile
file-base +".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
def? body-boc-file { @' body-boc-file file>B B>boc } { <b 0 32 u, "TESTv2" $, b> } cond
def? body-boc-file { @' body-boc-file file>B B>boc } { comment simple-transfer-body } cond
constant body-cell
."Transferring " amount .GR ."to account "

View file

@ -1,31 +1,54 @@
#!/usr/bin/fift -s
"TonUtil.fif" include
"GetOpt.fif" include
{ show-options-help 1 halt } : usage
"" =: comment // comment for simple transfers
true =: allow-bounce
false =: force-bounce
3 =: send-mode // mode for SENDRAWMSG: +1 - sender pays fees, +2 - ignore errors
60 =: timeout // external message expires in 60 seconds
begin-options
" <filename-base> <dest-addr> <subwallet-id> <seqno> <amount> [-n|-b] [-t<timeout>] [-B <body-boc>] [-C <comment>] [<savefile>]" +cr +tab
+"Creates a request to advanced wallet created by new-wallet-v3.fif, with private key loaded from file <filename-base>.pk "
+"and address from <filename-base>.addr, and saves it into <savefile>.boc ('wallet-query.boc' by default)"
generic-help
"n" "--no-bounce" { false =: allow-bounce } short-long-option
"Clears bounce flag" option-help
"b" "--force-bounce" { true =: force-bounce } short-long-option
"Forces bounce flag" option-help
"t" "--timeout" { parse-int =: timeout } short-long-option-arg
"Sets expiration timeout in seconds (" timeout (.) $+ +" by default)" option-help
"B" "--body" { =: body-boc-file } short-long-option-arg
"Sets the payload of the transfer message" option-help
"C" "--comment" { =: comment } short-long-option-arg
"Sets the comment to be sent in the transfer message" option-help
"m" "--mode" { parse-int =: send-mode } short-long-option-arg
"Sets transfer mode (0..255) for SENDRAWMSG (" send-mode (.) $+ +" by default)"
option-help
"h" "--help" { usage } short-long-option
"Shows a help message" option-help
parse-options
{ ."usage: " @' $0 type ." <filename-base> <dest-addr> <subwallet_id> <seqno> <amount> [-B <body-boc>] [<savefile>]" cr
."Creates a request to advanced wallet created by new-wallet-v3.fif, with private key loaded from file <filename-base>.pk "
."and address from <filename-base>.addr, and saves it into <savefile>.boc ('wallet-query.boc' by default)" cr 1 halt
} : usage
def? $7 { @' $6 "-B" $= { @' $7 =: body-boc-file [forget] $7 def? $8 { @' $8 =: $6 [forget] $8 } { [forget] $6 } cond
@' $# 2- =: $# } if } if
$# dup 5 < swap 6 > or ' usage if
6 :$1..n
true constant bounce
$1 =: file-base
$2 bounce parse-load-address =: bounce 2=: dest_addr
$2 bounce parse-load-address force-bounce or allow-bounce and =: bounce 2=: dest_addr
$3 parse-int =: subwallet_id
$4 parse-int =: seqno
$5 $>GR =: amount
def? $6 { @' $6 } { "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
$6 "wallet-query" replace-if-null =: savefile
file-base +".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
def? body-boc-file { @' body-boc-file file>B B>boc } { <b 0 32 u, "TESTv3" $, b> } cond
def? body-boc-file { @' body-boc-file file>B B>boc } { comment simple-transfer-body } cond
constant body-cell
."Transferring " amount .GR ."to account "

View file

@ -2,31 +2,42 @@
"TonUtil.fif" include
"GetOpt.fif" include
{ ."usage: " @' $0 type ." <filename-base> <dest-addr> <seqno> <amount> [-n] [-B <body-boc>] [-C <transfer-comment>] [<savefile>]" cr
."Creates a request to simple wallet created by new-wallet.fif, with private key loaded from file <filename-base>.pk "
."and address from <filename-base>.addr, and saves it into <savefile>.boc ('wallet-query.boc' by default)" cr 1 halt
} : usage
{ show-options-help 1 halt } : usage
"" =: comment // comment for simple transfers
true =: allow-bounce
false =: force-bounce
3 =: send-mode // mode for SENDRAWMSG: +1 - sender pays fees, +2 - ignore errors
begin-options
" <filename-base> <dest-addr> <seqno> <amount> [-n|-b] [-B <body-boc>] [-C <comment>] [<savefile>]" +cr +tab
+"Creates a request to simple wallet created by new-wallet.fif, with private key loaded from file <filename-base>.pk "
+"and address from <filename-base>.addr, and saves it into <savefile>.boc ('wallet-query.boc' by default)"
generic-help
"n" "--no-bounce" { false =: allow-bounce } short-long-option
"Clears bounce flag" option-help
"b" "--force-bounce" { true =: force-bounce } short-long-option
"Forces bounce flag" option-help
"B" "--body" { =: body-boc-file } short-long-option-arg
"Sets the payload of the transfer message" option-help
"C" "--comment" { =: comment } short-long-option-arg
"Sets the comment to be sent in the transfer message" option-help
"m" "--mode" { parse-int =: send-mode } short-long-option-arg
"Sets transfer mode (0..255) for SENDRAWMSG (" send-mode (.) $+ +" by default)"
option-help
"h" "--help" { usage } short-long-option
"Shows a help message" option-help
parse-options
$# dup 4 < swap 5 > or ' usage if
5 :$1..n
true =: bounce
$1 =: file-base
$2 bounce parse-load-address allow-bounce and =: bounce 2=: dest_addr
$2 bounce parse-load-address allow-bounce and force-bounce or =: bounce 2=: dest_addr
$3 parse-int =: seqno
$4 $>GR =: amount
$5 dup null? { drop "wallet-query" } if =: savefile
$5 "wallet-query" replace-if-null =: savefile
allow-bounce not force-bounce and abort"cannot have bounce flag both set and cleared"
// "" 1 { 69091 * 1+ 65535 and tuck 2521 / 65 + hold swap } 1000 times drop =: comment
file-base +".addr" load-address