build static method

RawTransaction build({
  1. required int version,
  2. required List<Output> outputs,
  3. required Map<ElectrumOutput, Input> inputMap,
  4. int? lockTime,
  5. int? validFrom,
  6. int? validUntil,
})

Implementation

static RawTransaction build({
  required int version,
  required List<Output> outputs,
  required Map<ElectrumOutput, Input> inputMap,
  int? lockTime,
  int? validFrom,
  int? validUntil,
}) {
  final inputs = inputMap.values;
  final btcInputs = inputs.whereType<BTCInput>();
  final btcOutputs = outputs.whereType<BTCOutput>();

  if (btcInputs.isNotEmpty && btcOutputs.isNotEmpty && lockTime != null) {
    return BTCRawTransaction(
      version: version,
      inputs: btcInputs.toList(),
      outputs: btcOutputs.toList(),
      inputMap: inputMap,
      lockTime: lockTime,
    );
  }

  final ec8Inputs = inputs.whereType<EC8Input>();
  final ec8Outputs = outputs.whereType<EC8Output>();

  if (ec8Inputs.isNotEmpty &&
      ec8Outputs.isNotEmpty &&
      validFrom != null &&
      validUntil != null) {
    return EC8RawTransaction(
      version: version,
      inputs: ec8Inputs.toList(),
      outputs: ec8Outputs.toList(),
      inputMap: inputMap,
      validFrom: validFrom,
      validUntil: validUntil,
    );
  }

  throw UnimplementedError();
}