mirror of
https://github.com/danog/toncontest.git
synced 2024-12-11 17:09:44 +01:00
54 lines
1.9 KiB
Plaintext
54 lines
1.9 KiB
Plaintext
|
#!/usr/bin/env -S fift -s
|
||
|
"TonUtil.fif" include
|
||
|
"lib.fif" include
|
||
|
|
||
|
{
|
||
|
."usage: " @' $0 type ." <input1> <input2> [<input3> ...] <output>" cr
|
||
|
."Merges multisig <inputx>.boc files and writes result to <output>.boc" cr 1 halt
|
||
|
} : usage
|
||
|
$# 3 < ' usage if
|
||
|
|
||
|
$# 1 - const input-len
|
||
|
1 { dup $() +".boc" swap 1+ } input-len times drop
|
||
|
input-len tuple const input-files
|
||
|
|
||
|
$# $() +".boc" const output-file
|
||
|
|
||
|
."Inspecting and merging " input-len . ."files..." cr
|
||
|
input-files explode 1- swap
|
||
|
load-boc inspect cr
|
||
|
message-hash const previous-hash
|
||
|
wallet-addr 2const previous-address
|
||
|
|
||
|
// multiSigWrapper$0 signatures:(HashmapE 4 Signature) message:(WrappedMessage X) = MultiSigWrapper X;
|
||
|
message-contents
|
||
|
1 u@+ nip // $0 was already verified
|
||
|
dict@+ // Read signatures
|
||
|
s>c const wrapped-message // Store rest of message in const
|
||
|
swap // put length on top, signatures right underneath
|
||
|
|
||
|
{ swap // Get filename, signatures right underneath
|
||
|
load-boc inspect cr
|
||
|
message-hash previous-hash <> abort"Hash mismatch!"
|
||
|
// I suppose it's ok if there are multiple wallet instances with the same messages on different workchains/at different addresses, we're all agreeing to sign the same message anyway
|
||
|
// wallet-address previous-address rot <> abort"Wallet address mismatch!" <> abort"Wallet address mismatch (different workchain)!"
|
||
|
message-contents
|
||
|
1 u@+ nip // $0 was already verified
|
||
|
dict@ // Read signatures
|
||
|
4 { drop s, -1 } dictmerge
|
||
|
} swap times
|
||
|
|
||
|
// Signatures are the only element on the stack
|
||
|
."Final message signed by the following keys: "
|
||
|
dup 4 { drop . ."- " -1 } dictforeach cr drop
|
||
|
|
||
|
// multiSigWrapper$0 signatures:(HashmapE 4 Signature) message:(WrappedMessage X) = MultiSigWrapper X;
|
||
|
<b 0 1 u, swap dict, wrapped-message <s s, b>
|
||
|
|
||
|
// Renerate external message
|
||
|
<b 68 7 u, wallet-addr addr, 0 Gram, 0 1 u, swap maybe-ref, b>
|
||
|
|
||
|
2 boc+>B dup Bx. cr
|
||
|
output-file tuck B>file
|
||
|
."Saved new multisigned message to file " type cr
|