feat(primitives): Add ToHash to DatumOption (#163)

This commit is contained in:
Sebastien Guillemot 2022-08-07 03:29:17 +09:00 committed by GitHub
parent dde9f96595
commit a4873c404e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,6 @@
use crate::ToHash;
use super::{Header, PlutusV2Script, TransactionBody};
use super::{Header, PlutusV2Script, TransactionBody, DatumOption};
use pallas_codec::utils::KeepRaw;
use pallas_crypto::hash::{Hash, Hasher};
@ -28,6 +28,15 @@ impl ToHash<32> for KeepRaw<'_, TransactionBody> {
}
}
impl ToHash<32> for DatumOption {
fn to_hash(&self) -> Hash<32> {
match self {
DatumOption::Hash(hash) => *hash,
DatumOption::Data(data) => data.to_hash()
}
}
}
#[cfg(test)]
mod tests {
use pallas_codec::minicbor;