amaru_kernel/cardano/
required_script.rs1use std::cmp::Ordering;
16
17use crate::{AsIndex, Hash, MemoizedDatum, RedeemerKey, ScriptPurpose, size::SCRIPT};
18
19#[derive(Clone, Eq, PartialEq, Debug, serde::Deserialize)]
20pub struct RequiredScript {
21 pub hash: Hash<SCRIPT>,
22 pub index: u32,
23 pub purpose: ScriptPurpose,
24 pub datum: MemoizedDatum,
25}
26
27impl PartialOrd for RequiredScript {
28 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
29 Some(self.cmp(other))
30 }
31}
32
33impl From<&RequiredScript> for Hash<SCRIPT> {
34 fn from(value: &RequiredScript) -> Self {
35 value.hash
36 }
37}
38
39impl Ord for RequiredScript {
40 fn cmp(&self, other: &Self) -> Ordering {
41 match self.hash.cmp(&other.hash) {
42 Ordering::Equal => match self.purpose.as_index().cmp(&other.purpose.as_index()) {
43 Ordering::Equal => self.index.cmp(&other.index),
44 by_purpose @ Ordering::Less | by_purpose @ Ordering::Greater => by_purpose,
45 },
46 by_hash @ Ordering::Less | by_hash @ Ordering::Greater => by_hash,
47 }
48 }
49}
50
51impl From<&RequiredScript> for RedeemerKey {
52 fn from(value: &RequiredScript) -> Self {
53 RedeemerKey { tag: value.purpose, index: value.index }
54 }
55}