create method Null safety

Future<OwnershipModel> create(
  1. {required String source,
  2. required TikiSdkDataTypeEnum type,
  3. String? origin,
  4. String? about,
  5. List<String> contains = const []}
)

Creates a ownership register in the blockchain.

This method creates a new transcation that will be commited in the next block in the chain. If no origin is provided the default origin will be used

Implementation

Future<OwnershipModel> create(
    {required String source,
    required TikiSdkDataTypeEnum type,
    String? origin,
    String? about,
    List<String> contains = const []}) async {
  OwnershipModel? ownershipModel = getBySource(source, origin: origin);
  if (ownershipModel != null) {
    throw 'Ownership already granted for $source and $origin. ${ownershipModel.toString()}';
  }
  ownershipModel = OwnershipModel(
      source: source,
      type: type,
      origin: origin ?? _defaultOrigin,
      about: about,
      contains: contains);
  Uint8List contents = (BytesBuilder()
        ..addByte(1)
        ..addByte(1)
        ..add(ownershipModel.serialize()))
      .toBytes();
  TransactionModel transaction = await nodeService.write(contents);
  ownershipModel.transactionId = transaction.id;
  _repository.save(ownershipModel);
  return ownershipModel;
}