#!/usr/bin/fift -s "TonUtil.fif" include { ."usage: " @' $0 type ." []" cr ."Creates a request to participate in validator elections starting at on behalf of smart-contract with address (prefix with '@' to load address from file) and hexadecimal adnl address (empty string or '0' for none)." cr ."The result is saved into and output in hexadecimal form, to be signed later by the validator public key" cr 1 halt } : usage $# dup 3 < swap 5 > or ' usage if $1 true parse-load-address drop swap 1+ abort"only masterchain smartcontracts may participate in validator elections" constant src_addr $2 (number) 1 <> { 0 } if dup 0<= abort" must be a positive integer" constant elect_time $3 (number) dup 0= abort" must be a real number 1..100" 1 = { 16 << } { 16 < or abort" must be a real number 1..100" constant max_factor def? $4 { @' $4 dup $len 1 > { parse-adnl-address } { drop 0 } cond } ' 0 cond constant adnl_addr def? $5 { @' $5 } { "validator-to-sign.bin" } cond constant output_fname ."Creating a request to participate in validator elections at time " elect_time . ."from smart contract " -1 src_addr 2dup 1 .Addr ." = " .addr ." with maximal stake factor with respect to the minimal stake " max_factor ._ ."/65536 and validator ADNL address " adnl_addr 64x. cr B{654c5074} elect_time 32 u>B B+ max_factor 32 u>B B+ src_addr 256 u>B B+ adnl_addr 256 u>B B+ dup Bx. cr dup B>base64url type cr output_fname tuck B>file ."Saved to file " type cr