scriptDatahash static method

ScriptDataHash scriptDatahash({
  1. required List<Redeemer> redeemers,
  2. required Costmdls costmdls,
  3. PlutusList? datums,
})

Implementation

static ScriptDataHash scriptDatahash(
    {required List<Redeemer> redeemers,
    required Costmdls costmdls,
    PlutusList? datums}) {
  if (redeemers.isEmpty && datums != null) {
    return ScriptDataHash(
        QuickCrypto.blake2b256Hash([0x80, ...datums.serialize(), 0xA0]));
  }
  final List<int> redeemersBytes =
      CborListValue.fixedLength(redeemers.map((e) => e.toCbor()).toList())
          .encode();
  return ScriptDataHash(QuickCrypto.blake2b256Hash([
    ...redeemersBytes,
    ...datums?.serialize() ?? <int>[],
    ...costmdls.languageViewEncoding().encode()
  ]));
}