2019-10-08 19:45:25 +02:00
#!/usr/bin/env -S fift -s
"TonUtil.fif" include
2019-10-10 17:37:47 +02:00
"lib.fif" include
2019-10-08 19:45:25 +02:00
{
."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
2019-10-11 13:31:10 +02:00
load-boc inspect cr
2019-10-08 19:45:25 +02:00
message-hash const previous-hash
2019-10-11 19:23:59 +02:00
wallet-addr 2const previous-address
2019-10-08 19:45:25 +02:00
2019-10-10 17:37:47 +02:00
// 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
2019-10-08 19:45:25 +02:00
{ swap // Get filename, signatures right underneath
2019-10-11 13:31:10 +02:00
load-boc inspect cr
message-hash previous-hash <> abort"Hash mismatch!"
2019-10-10 17:37:47 +02:00
// 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
2019-10-08 19:45:25 +02:00
4 { drop s, -1 } dictmerge
} swap times
// Signatures are the only element on the stack
2019-10-11 13:31:10 +02:00
."Final message signed by the following keys: "
2019-10-08 19:45:25 +02:00
dup 4 { drop . ."- " -1 } dictforeach cr drop
2019-10-10 17:37:47 +02:00
// 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
2019-10-11 13:31:10 +02:00
<b 68 7 u, wallet-addr addr, 0 Gram, 0 1 u, swap maybe-ref, b>
2019-10-08 19:45:25 +02:00
2 boc+>B dup Bx. cr
output-file tuck B>file
."Saved new multisigned message to file " type cr