#!/usr/bin/fift -s "TonUtil.fif" include "GetOpt.fif" include "vote-query.boc" =: savefile { ."usage: " @' $0 type ." []" cr ."Creates an external message addressed to the configuration smart contract containing a signed request expiring at unixtime to vote for configuration proposal (decimal; prefix with '0x' if needed) on behalf of validator with zero-based index and (Base64) public key in current validator set (as stored in configuration parameter 34)" cr ." must be the base64 representation of Ed25519 signature of the previously generated unsigned request by means of " cr ."The result is saved into (" savefile type ." by default), to be sent later by the lite-client" cr 1 halt } : usage $# dup 6 < swap 7 > or ' usage if 7 :$1..n $1 true parse-load-address drop over 1+ abort"configuration smart contract must be in masterchain" 2=: config-addr $2 parse-int dup 30 1<< < { now + 1000 + 2000 /c 2000 * } if dup =: expire-at dup now <= abort"expiration time must be in the future" 32 ufits not abort"invalid expiration time" $3 parse-int dup =: val-idx 16 ufits not abort"validator index out of range" $4 parse-int dup =: prop-hash 256 ufits not abort"invalid proposal hash" $5 base64>B dup Blen 36 <> abort"validator Ed25519 public key must be exactly 36 bytes long" 32 B>u@+ 0xC6B41348 <> abort"invalid Ed25519 public key: unknown magic number" =: pubkey $6 base64>B dup Blen 64 <> abort"validator Ed25519 signature must be exactly 64 bytes long" =: signature $7 savefile replace-if-null =: savefile 0 =: seqno ."Creating an external message to configuration smart contract " config-addr 2dup 6 .Addr ." = " .addr cr ."containing a signed request expiring at " expire-at . ."to vote for configuration proposal 0x" prop-hash 64x. ."on behalf of validator with index " val-idx . "and public key" pubkey 64x. cr B{566f7465} seqno 32 u>B B+ expire-at 32 u>B B+ val-idx 16 u>B B+ prop-hash 256 u>B B+ dup =: to_sign ."String to sign is " Bx. cr to_sign signature pubkey ed25519_chksign not abort"Ed25519 signature is invalid" ."Provided a valid Ed25519 signature " signature Bx. ." with validator public key " pubkey Bx. cr cr ."External message is " dup B savefile tuck B>file ."Saved to file " type cr