1
0
mirror of https://github.com/danog/toncontest.git synced 2024-11-26 12:04:50 +01:00
toncontest/wallet/wallet-create.fif
2019-10-14 20:47:20 +02:00

101 lines
3.7 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"TonUtil.fif" include
"lib.fif" include
{ ."usage: " @' $0 type ." <workchain-id> <wallet-name> <n> <k> <privkey1> [<pubkey2> ...]" cr cr
."Creates a new multisignature wallet in specified workchain composed of <n> (1-10) keys." cr
."The first of the keys must be a private key (pre-existing or not), used to generate the wallet; the rest MUST be public keys." cr
."Create or generate public key files from private keys using gen-pub.fif privkey" cr cr
."Min <k> (1-10) signatures required to send an order; load <n> pre-existing public keys from files <key1...n>." cr
1 halt
} : usage
$# 5 < ' usage if
$1 parse-workchain-id =: wc // set workchain id from command line argument
$2 constant file-base
$3 (number) 1 <> abort"<n> must be a number!" constant n
$4 (number) 1 <> abort"<k> must be a number!" constant k
n 1 < n 10 > or abort"<n> must be between 1 and 10"
k 1 < k 10 > or abort"<k> must be between 1 and 10"
k n <= not abort"<k> must smaller than or equal to <n>"
$# 4 n + < abort"Not enough keys were provided in args!"
$5 +".pk" load-generate-keypair const privkey 256 B>u@
6 { dup $() +".pubkey" load-pubkey swap 1+ } n 1- times drop
n tuple constant keys
cr
."Creating new multisignature wallet in workchain " wc .
."with n=" n .
."k=" k . ."..." cr cr
// idict! (v x s n s0 1 or s 0), adds a new value v (represented
// by a Slice) with key given by signed big-endian n-bit integer x into
// dictionary s with n-bit keys, and returns the new dictionary s0 and 1
// on success. Otherwise the unchanged dictionary s and 0 are returned.
// Create dictionaries with keys and messages
// Extract keys
keys explode
dup 1- // Create counter
dictnew swap // ...and dict (swap the two)
rot // Put length on top for times
{ dup 1- swap // Decrement counter (val dict ncount curcount)
3 roll // Get n-th value v (dict ncount curcount val)
<b swap 256 u, // Create builder bval
swap // Get x (dict ncount bval curcount)
3 roll // Get dictionary s (ncount bval curcount dict)
4 // Get n (ncount bval curcount dict 4)
b>udict! // Store (ncount dict')
not abort"Failure storing dictionary value!"
swap // Swap dict (dict' ncount)
} swap times drop const keys-dict
.s
// code
"wallet-code.fif" include
// data
// storage$_ seqno:uint32 minSigs:(## 4) keys:(HashmapE 4 PubKey) messages:(HashmapE 256 (MultiSigWrapperStorage X))
// { minSigs > 0 } { n >= minSigs } { n <= 10 } { minSigs <= 10 } = Storage X;
<b 0 32 u,
k 4 u,
keys-dict dict,
dictnew dict,
b>
// create StateInit
// _ split_depth:(Maybe (## 5)) special:(Maybe TickTock)
// code:(Maybe ^Cell) data:(Maybe ^Cell)
// library:(HashmapE 256 SimpleLib) = StateInit;
// split_depth 0 special 0 code 1 data 1 library hme_empty 0
//
<b b{00110} s, rot ref, swap ref, b>
dup ."StateInit: " <s csr. cr
dup hash wc swap 2dup 2constant wallet-addr
."new wallet address = " 2dup .addr cr
2dup file-base +".addr" save-address-verbose
."Non-bounceable address (for init): " 2dup 7 .Addr cr
."Bounceable address (for later access): " 6 .Addr cr
// multiSigInit$10 = MultiSigWrapper X;
<b 2 2 u, b>
// dup ."signing message: " <s csr. cr
// dup hash privkey ed25519_sign_uint
// Put StateInit on top
swap
// message$_ {X:Type} info:CommonMsgInfo
// init:(Maybe (Either StateInit ^StateInit))
// body:(Either X ^X) = Message X;
<b b{1000100} s, wallet-addr addr, 0 Gram, 1 1 u, swap maybe-ref, b{0} s, swap <s s, b>
dup ."External message for initialization is " <s csr. cr
2 boc+>B dup Bx. cr
file-base +"-create.boc" tuck B>file
."(Saved wallet creating query to file " type .")" cr