mergeMultisigTransactions static method
Merges the given (partially) signed multisig transactions. Transactions are the partially signed multisig transactions to merge. Underlying transactions may be mutated.
Returns the merged multisig transaction
Implementation
static Future<SignedTransaction> mergeMultisigTransactions(
List<SignedTransaction> transactions,
) async {
if (transactions.length < 2) {
throw AlgorandException(message: 'Cannot merge a single transaction');
}
final merged = transactions[0];
for (var i = 0; i < transactions.length; i++) {
final tx = transactions[i];
final mSig = tx.multiSignature;
if (mSig == null) {
throw AlgorandException(message: 'No valid multisignature');
}
if (mSig.version != merged.multiSignature?.version ||
mSig.threshold != merged.multiSignature?.threshold) {
throw AlgorandException(
message: 'transaction msig parameters do not match',
);
}
for (var j = 0; j < mSig.subsigs.length; j++) {
var myMsig = merged.multiSignature?.subsigs[j];
var theirMsig = mSig.subsigs[j];
if (myMsig == null) {
throw AlgorandException(message: 'No valid subsig');
}
if (theirMsig.key != myMsig.key) {
throw AlgorandException(
message: 'transaction msig public keys do not match',
);
}
if (myMsig.signature == null) {
myMsig = myMsig.copyWith(signature: theirMsig.signature);
} else if (myMsig.signature != theirMsig.signature &&
theirMsig.signature != null) {
throw AlgorandException(
message: 'transaction msig has mismatched signatures',
);
}
merged.multiSignature?.subsigs[j] = myMsig;
}
}
return merged;
}