P2Data constructor

P2Data(
  1. PaymentArg _a, [
  2. PaymentOpts? opts
])

Implementation

P2Data(this._a, [PaymentOpts? opts]) {
  if (_a.data == null && _a.output == null) {
    throw Exception('Not enough data');
  }

  opts = PaymentOpts(
      validate: opts?.validate ?? true,
      allowIncomplete: opts?.allowIncomplete);

  name = 'embed';

  if (opts.validate == true) {
    if (_a.output != null) {
      final chunks = bscript.script.decompile(_a.output);
      if (chunks![0] != OPS['OP_RETURN']!) {
        throw Exception('Output is invalid');
      }
      if (!chunks.sublist(1).every((element) => element is Uint8List)) {
        throw Exception('Output is invalid');
      }

      if (_a.data != null &&
          !isListEqual(_a.data!, data as List<Uint8List>)) {
        throw Exception('Data mismatch');
      }
    }
  }

  _assign(_a);
}