OutputBase.expandOutput constructor

OutputBase.expandOutput(
  1. Uint8List? script, [
  2. Uint8List? ourPubKey
])

Implementation

factory OutputBase.expandOutput(Uint8List? script, [Uint8List? ourPubKey]) {
  if (ourPubKey == null) return OutputBase();
  var type = classifyOutput(script!);
  if (type == SCRIPT_TYPES['P2WPKH']) {
    var wpkh1 = P2WPKH(data: PaymentData(output: script)).data.hash;
    var wpkh2 = bcrypto.hash160(ourPubKey);
    if (wpkh1.toString() != wpkh2.toString()) {
      throw ArgumentError('Hash mismatch!');
    }
    return OutputBase(type: type, pubkeys: [ourPubKey], signatures: [null]);
  }

  if (type == SCRIPT_TYPES['P2PKH']) {
    var pkh1 = P2PKH(data: PaymentData(output: script)).data.hash;
    var pkh2 = bcrypto.hash160(ourPubKey);
    if (pkh1.toString() != pkh2.toString()) {
      throw ArgumentError('Hash mismatch!');
    }
    return OutputBase(type: type, pubkeys: [ourPubKey], signatures: [null]);
  }

  return OutputBase();
}