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

101 lines
3.7 KiB
Plaintext
Raw Permalink Normal View History

2019-09-29 15:51:54 +02:00
"TonUtil.fif" include
2019-10-10 17:37:47 +02:00
"lib.fif" include
2019-10-05 19:27:18 +02:00
2019-10-11 16:54:08 +02:00
{ ."usage: " @' $0 type ." <workchain-id> <wallet-name> <n> <k> <privkey1> [<pubkey2> ...]" cr cr
2019-10-06 20:34:05 +02:00
."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
2019-10-05 19:27:18 +02:00
."Min <k> (1-10) signatures required to send an order; load <n> pre-existing public keys from files <key1...n>." cr
1 halt
2019-09-29 15:51:54 +02:00
} : usage
2019-10-05 19:27:18 +02:00
$# 5 < ' usage if
2019-09-29 15:51:54 +02:00
$1 parse-workchain-id =: wc // set workchain id from command line argument
2019-10-05 19:27:18 +02:00
$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
2019-09-29 15:51:54 +02:00
2019-10-05 19:27:18 +02:00
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!"
2019-10-06 20:41:54 +02:00
$5 +".pk" load-generate-keypair const privkey 256 B>u@
2019-10-06 20:34:05 +02:00
6 { dup $() +".pubkey" load-pubkey swap 1+ } n 1- times drop
2019-10-06 18:16:41 +02:00
n tuple constant keys
2019-10-05 19:27:18 +02:00
2019-10-06 18:16:41 +02:00
cr
2019-10-11 20:27:37 +02:00
."Creating new multisignature wallet in workchain " wc .
2019-10-05 19:27:18 +02:00
."with n=" n .
2019-10-11 16:54:08 +02:00
."k=" k . ."..." cr cr
2019-10-05 19:27:18 +02:00
2019-10-06 18:16:41 +02:00
// 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
2019-10-11 13:31:10 +02:00
// Extract keys
keys explode
2019-10-11 19:23:59 +02:00
dup 1- // Create counter
dictnew swap // ...and dict (swap the two)
2019-10-11 13:31:10 +02:00
rot // Put length on top for times
2019-10-14 20:47:20 +02:00
{ dup 1- swap // Decrement counter (val dict ncount curcount)
3 roll // Get n-th value v (dict ncount curcount val)
2019-10-11 13:31:10 +02:00
<b swap 256 u, // Create builder bval
2019-10-14 20:47:20 +02:00
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')
2019-10-10 17:37:47 +02:00
not abort"Failure storing dictionary value!"
2019-10-06 18:16:41 +02:00
2019-10-14 20:47:20 +02:00
swap // Swap dict (dict' ncount)
2019-10-11 13:31:10 +02:00
} swap times drop const keys-dict
2019-10-12 21:14:02 +02:00
.s
2019-09-29 15:51:54 +02:00
// code
2019-10-05 19:27:18 +02:00
"wallet-code.fif" include
// data
2019-10-11 13:31:10 +02:00
// storage$_ seqno:uint32 minSigs:(## 4) keys:(HashmapE 4 PubKey) messages:(HashmapE 256 (MultiSigWrapperStorage X))
2019-10-06 19:16:06 +02:00
// { minSigs > 0 } { n >= minSigs } { n <= 10 } { minSigs <= 10 } = Storage X;
2019-09-29 15:51:54 +02:00
<b 0 32 u,
2019-10-06 19:16:06 +02:00
k 4 u,
2019-10-10 17:37:47 +02:00
keys-dict dict,
2019-10-11 16:54:08 +02:00
dictnew dict,
2019-10-05 19:27:18 +02:00
b>
2019-10-06 19:16:06 +02:00
// create StateInit
2019-10-06 20:34:05 +02:00
// _ split_depth:(Maybe (## 5)) special:(Maybe TickTock)
// code:(Maybe ^Cell) data:(Maybe ^Cell)
// library:(HashmapE 256 SimpleLib) = StateInit;
2019-10-14 20:47:20 +02:00
// split_depth 0 special 0 code 1 data 1 library hme_empty 0
2019-10-06 20:34:05 +02:00
//
2019-10-14 20:47:20 +02:00
<b b{00110} s, rot ref, swap ref, b>
2019-10-06 20:34:05 +02:00
2019-09-29 15:51:54 +02:00
dup ."StateInit: " <s csr. cr
2019-10-10 17:37:47 +02:00
dup hash wc swap 2dup 2constant wallet-addr
2019-09-29 15:51:54 +02:00
."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
2019-10-08 22:13:46 +02:00
2019-10-13 21:01:16 +02:00
// multiSigInit$10 = MultiSigWrapper X;
<b 2 2 u, b>
// dup ."signing message: " <s csr. cr
// dup hash privkey ed25519_sign_uint
2019-10-09 17:18:04 +02:00
2019-10-11 13:31:10 +02:00
// Put StateInit on top
2019-10-13 21:01:16 +02:00
swap
2019-10-09 17:18:04 +02:00
// message$_ {X:Type} info:CommonMsgInfo
2019-10-11 13:31:10 +02:00
// init:(Maybe (Either StateInit ^StateInit))
// body:(Either X ^X) = Message X;
2019-10-09 17:18:04 +02:00
2019-10-14 20:47:20 +02:00
<b b{1000100} s, wallet-addr addr, 0 Gram, 1 1 u, swap maybe-ref, b{0} s, swap <s s, b>
2019-09-29 15:51:54 +02:00
dup ."External message for initialization is " <s csr. cr
2 boc+>B dup Bx. cr
2019-10-07 21:18:31 +02:00
file-base +"-create.boc" tuck B>file
2019-09-29 15:51:54 +02:00
."(Saved wallet creating query to file " type .")" cr