1
0
mirror of https://github.com/danog/toncontest.git synced 2024-11-26 20:15:01 +01:00
toncontest/wallet/wallet-create.fif
2019-10-13 21:01:16 +02:00

103 lines
3.6 KiB
Plaintext
Raw 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
3 roll // Get n-th value v (val dict ncount curcount)
<b swap 256 u, // Create builder bval
swap // Get x (dict ncount curcount bval)
3 roll // Get dictionary s (dict ncount bval curcount)
4 // Get n (ncount bval curcount dict) 4
b>udict!
not abort"Failure storing dictionary value!"
swap
} 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>
// no libraries
null
// 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
//
<b b{0011} s, 3 roll ref, rot ref, swap dict, 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, b{00001} s, 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