MultisigProgram.fromScript constructor
MultisigProgram.fromScript(
- Script script
Implementation
MultisigProgram.fromScript(this.script) {
// Must have threshold, 1-20 public keys, pubkey number and CHECKMULTISIG
if (script.length < 4 || script.length > maxPubkeys+3) {
throw NoProgramMatch();
}
if (!script.ops.last.match(checkmultisig)) throw NoProgramMatch();
final pknum = script[script.length-2].number;
if (
pknum == null || pknum < 1 || pknum > maxPubkeys
|| script.length != pknum+3
) throw NoProgramMatch();
final firstNum = script[0].number;
if (firstNum == null) throw NoProgramMatch();
threshold = firstNum;
// Threshold must be within 1-pknum
if (threshold < 1 || threshold > pknum) throw NoProgramMatch();
// Check all public keys are push data and extract data
final potentialPubkeys = script.ops.sublist(1, script.length-2);
if (
potentialPubkeys.any(
(op) => op is! ScriptPushData
|| (op.data.length != 33 && op.data.length != 65),
)
) throw NoProgramMatch();
try {
pubkeys = List.unmodifiable(
potentialPubkeys.map(
(op) => ECPublicKey((op as ScriptPushData).data),
),
);
} on InvalidPublicKey {
throw NoProgramMatch();
}
}