createOpReturnGenesis function

List<int> createOpReturnGenesis(
  1. int versionType,
  2. String ticker,
  3. String name,
  4. String documentUrl,
  5. List<int> documentHash,
  6. int decimals,
  7. BigInt quantity, [
  8. int? mintBatonVout,
])

Creates a GENESIS OP_RETURN buffer.

Implementation

List<int> createOpReturnGenesis(
  int versionType,
  String ticker,
  String name,
  String documentUrl,
  List<int> documentHash,
  int decimals,
  BigInt quantity,
  [ int? mintBatonVout ]
  ) {

  if (! [0x01, 0x41, 0x81].contains(versionType)) {
    throw('unknown versionType');
  }

  if (! documentHash.isEmpty && documentHash.length != 32) {
    throw('documentHash must be either 0 or 32 hex bytes');
  }

  if (decimals < 0 || decimals > 9) {
    throw('decimals out of range');
  }

  if (mintBatonVout != null && (mintBatonVout < 2 || mintBatonVout > 0xFF)) {
    throw('mintBatonVout out of range (0x02 < > 0xFF)');
  }

  if (versionType == 0x41) {
    if (quantity != BigInt.from(1)) {
      throw('quantity must be 1 for NFT1 child genesis');
    }

    if (decimals != 0) {
      throw('decimals must be 0 for NFT1 child genesis');
    }

    if (mintBatonVout != null) {
      throw('mintBatonVout must be null for NFT1 child genesis');
    }
  }

  var buf =
    [ 0x6A, // OP_RETURN
    ...pushdata(hex.decode("534c5000")), // lokad for "SLP")),
    ...pushdata([versionType]), // versionType
    ...pushdata(utf8.encode("GENESIS")),
    ...pushdata(utf8.encode(ticker)),
    ...pushdata(utf8.encode(name)),
    ...pushdata(utf8.encode(documentUrl)),
    ...pushdata(documentHash),
    ...pushdata([decimals]),
    ...pushdata(mintBatonVout == null ? [] : [mintBatonVout]),
    ...pushdata(BNToInt64BE(quantity))
  ];

  return buf;
}