Output.expandOutput constructor
Implementation
factory Output.expandOutput(Uint8List? script, [Uint8List? ourPubKey]) {
if (ourPubKey == null) return new Output();
var type = classifyOutput(script!);
if (type == SCRIPT_TYPES['P2WPKH']) {
Uint8List? wpkh1 =
new P2WPKH(data: new PaymentData(output: script)).data.hash;
Uint8List wpkh2 = bcrypto.hash160(ourPubKey);
if (wpkh1 != wpkh2) throw ArgumentError('Hash mismatch!');
return new Output(pubkeys: [ourPubKey], signatures: [null]);
} else if (type == SCRIPT_TYPES['P2PKH']) {
Uint8List? pkh1 =
new P2PKH(data: new PaymentData(output: script)).data.hash;
Uint8List pkh2 = bcrypto.hash160(ourPubKey);
if (pkh1 != pkh2) throw ArgumentError('Hash mismatch!');
return new Output(pubkeys: [ourPubKey], signatures: [null]);
} else {
throw ArgumentError('Unknown script type: ${type}');
}
}