Ton

Форк
0
/
create-elector-upgrade-proposal.fif 
65 строк · 2.4 Кб
1
#!/usr/bin/fift -s
2
"Asm.fif" include
3
"TonUtil.fif" include
4
"GetOpt.fif" include
5

6
// only the next three lines differ in elector/configuration smart contract upgrades
7
"elector" =: name
8
"auto/elector-code.fif" =: src-file
9
-1001 =: param-idx
10

11
86400 30 * =: expire-in
12
true =: critical
13
-1 =: old-hash
14

15
{ show-options-help 1 halt } : usage
16
{ name $+ } : +name
17

18
begin-options
19
     " [-s <fift-asm-code>] [-x <expire-in>] [-H <old-hash>] [<savefile>]" +cr +tab
20
    +"Creates a new configuration proposal for upgrading the " +name +" smart contract code to <fift-asm-code> ('" src-file $+ +"' by default), "
21
    +"and saves it as an internal message body into <savefile>.boc ('config-msg-body.boc' by default)"
22
     disable-digit-options generic-help-setopt
23
  "x" "--expires-in" { parse-int =: expire-in } short-long-option-arg
24
    "Sets proposal expiration time in seconds (default " expire-in (.) $+ +")" option-help
25
  "s" "--source" { =: src-file } short-long-option-arg
26
    "Fift assembler source file for the new " +name +" smart contract code ('"
27
    src-file $+ +"' by default)" option-help
28
  "H" "--old-hash" { (hex-number) not abort"256-bit hex number expected as hash" =: old-hash }
29
     short-long-option-arg
30
     "Sets the required cell hash of existing parameter value (0 means no value)" option-help 
31
  "h" "--help" { usage } short-long-option
32
    "Shows a help message" option-help
33
parse-options
34

35
$# 1 > ' usage if
36
1 :$1..n
37

38
$1 "config-msg-body.boc" replace-if-null =: savefile
39
expire-in now + =: expire-at
40

41
."Assembling new " name type ." smart contract code from " src-file type cr
42
src-file include
43
dup <s 12 u@ 0xFF0 <> abort"not valid smart contract code"
44
<b swap ref, b> =: param-value
45

46
critical { ."Critical" } { ."Non-critical" } cond
47
." configuration proposal for configuration parameter " param-idx .
48
."will expire at " expire-at . ."(in " expire-in . ."seconds)" cr
49

50
now 32 << param-idx + =: query-id
51
."Query id is " query-id . cr
52

53
// create message body
54
<b x{6e565052} s, query-id 64 u, expire-at 32 u, 
55
  <b x{f3} s, param-idx 32 i, param-value dict, 
56
     old-hash tuck 0>= tuck 1 i, -rot { 256 u, } { drop } cond b> ref, 
57
  critical 1 i, b>
58

59
dup ."resulting internal message body: " <s csr. cr
60
2 boc+>B dup Bx. cr
61
param-value totalcsize swap ."(a total of " . ."data bits, " . ."cell references -> "
62
drop dup Blen . ."BoC data bytes)" cr
63

64
savefile tuck B>file
65
."(Saved to file " type .")" cr
66

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.