#!/usr/bin/fift -s "TonUtil.fif" include "GetOpt.fif" include { show-options-help 1 halt } : usage 86400 30 * =: expire-in false =: critical -1 =: old-hash begin-options " [-x ] [-c] [-H ] []" +cr +tab +"Creates a new configuration proposal for setting configuration parameter to (`null` means no new value), " +"and saves it as an internal message body into .boc ('config-msg-body.boc' by default)" disable-digit-options generic-help-setopt "c" "--critical" { true =: critical } short-long-option "Creates a critical parameter change proposal" option-help "x" "--expires-in" { parse-int =: expire-in } short-long-option-arg "Sets proposal expiration time in seconds (default " expire-in (.) $+ +")" option-help "H" "--old-hash" { (hex-number) 1 = not .s abort"256-bit hex number expected as hash" =: old-hash } short-long-option-arg "Sets the required cell hash of existing parameter value (0 means no value)" option-help "h" "--help" { usage } short-long-option "Shows a help message" option-help parse-options $# dup 2 < swap 3 > or ' usage if 3 :$1..n $1 parse-int dup =: param-idx 32 fits not abort"parameter index out of range" $2 =: boc-filename $3 "config-msg-body.boc" replace-if-null =: savefile expire-in now + =: expire-at boc-filename dup "null" $= { ."New value of configuration parameter" param-idx . ."is null" cr drop null } { ."Loading new value of configuration parameter " param-idx . ."from file " dup type cr boc-filename file>B B>boc dup = tuck 1 i, -rot { 256 u, } { drop } cond b> ref, critical 1 i, b> dup ."resulting internal message body: " B dup Bx. cr param-value dup null? { drop } { totalcsize swap ."(a total of " . ."data bits, " . ."cell references -> " drop dup Blen . ."BoC data bytes)" cr } cond savefile tuck B>file ."(Saved to file " type .")" cr