Input.expandInput constructor

Input.expandInput(
  1. Uint8List? scriptSig,
  2. List<Uint8List?> witness, [
  3. String? type,
  4. Uint8List? scriptPubKey,
])

Implementation

factory Input.expandInput(Uint8List? scriptSig, List<Uint8List?> witness,
    [String? type, Uint8List? scriptPubKey]) {
  if (type == null || type == '') {
    var ssType = classifyInput(scriptSig);
    var wsType = classifyWitness(witness);
    if (ssType == SCRIPT_TYPES['NONSTANDARD']) ssType = null;
    if (wsType == SCRIPT_TYPES['NONSTANDARD']) wsType = null;
    type = ssType ?? wsType;
  }
  if (type == SCRIPT_TYPES['P2WPKH']) {
    P2WPKH p2wpkh = new P2WPKH(data: new PaymentData(witness: witness));
    return new Input(
        prevOutScript: p2wpkh.data.output,
        prevOutType: SCRIPT_TYPES['P2WPKH'],
        pubkeys: [p2wpkh.data.pubkey],
        signatures: [p2wpkh.data.signature]);
  } else if (type == SCRIPT_TYPES['P2PKH']) {
    P2PKH p2pkh = new P2PKH(data: new PaymentData(input: scriptSig));
    return new Input(
        prevOutScript: p2pkh.data.output,
        prevOutType: SCRIPT_TYPES['P2PKH'],
        pubkeys: [p2pkh.data.pubkey],
        signatures: [p2pkh.data.signature]);
  } else if (type == SCRIPT_TYPES['P2PK']) {
    P2PK p2pk = new P2PK(data: new PaymentData(input: scriptSig));
    return new Input(
        prevOutType: SCRIPT_TYPES['P2PK'],
        pubkeys: [],
        signatures: [p2pk.data.signature]);
  } else {
    throw ArgumentError('Unknown script type: ${type}');
  }
}