Ton

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

5
{ show-options-help 1 halt } : usage
6
86400 30 * =: expire-in
7
false =: critical
8
-1 =: old-hash
9

10
begin-options
11
     " <index> <new-value-boc> [-x <expire-in>] [-c] [-H <old-hash>] [<savefile>]" +cr +tab
12
    +"Creates a new configuration proposal for setting configuration parameter <index> to <new-value-boc> (`null` means no new value), "
13
    +"and saves it as an internal message body into <savefile>.boc ('config-msg-body.boc' by default)"
14
     disable-digit-options generic-help-setopt
15
  "c" "--critical" { true =: critical } short-long-option
16
    "Creates a critical parameter change proposal" option-help
17
  "x" "--expires-in" { parse-int =: expire-in } short-long-option-arg
18
    "Sets proposal expiration time in seconds (default " expire-in (.) $+ +")" option-help
19
  "H" "--old-hash" { (hex-number) 1 = not .s abort"256-bit hex number expected as hash" =: old-hash }
20
     short-long-option-arg
21
     "Sets the required cell hash of existing parameter value (0 means no value)" option-help 
22
  "h" "--help" { usage } short-long-option
23
    "Shows a help message" option-help
24
parse-options
25

26
$# dup 2 < swap 3 > or ' usage if
27
3 :$1..n
28

29
$1 parse-int dup =: param-idx
30
  32 fits not abort"parameter index out of range"
31
$2 =: boc-filename
32
$3 "config-msg-body.boc" replace-if-null =: savefile
33
expire-in now + =: expire-at
34

35
boc-filename dup "null" $= {
36
  ."New value of configuration parameter" param-idx . ."is null" cr drop null
37
} {
38
  ."Loading new value of configuration parameter " param-idx . ."from file " dup type cr
39
  boc-filename file>B B>boc
40
  dup <s csr. cr
41
} cond
42
=: param-value
43

44
param-value param-idx is-valid-config? not abort"not a valid value for chosen configuration parameter"
45

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

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

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

58
dup ."resulting internal message body: " <s csr. cr
59
2 boc+>B dup Bx. cr
60

61
param-value dup null? { drop } {
62
  totalcsize swap ."(a total of " . ."data bits, " . ."cell references -> " 
63
  drop dup Blen . ."BoC data bytes)" cr
64
} cond
65

66
savefile tuck B>file
67
."(Saved to file " type .")" cr
68

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

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

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

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