essential_types/
contract.rs1use std::ops::{Deref, DerefMut};
6
7use serde::{Deserialize, Serialize};
8
9use crate::{predicate::Predicate, serde::hash, Hash, Signature};
10
11#[cfg(feature = "schema")]
12use schemars::JsonSchema;
13
14#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
19pub struct SignedContract {
20 pub contract: Contract,
22 pub signature: Signature,
29}
30
31#[derive(Default, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
32#[cfg_attr(feature = "schema", derive(JsonSchema))]
33pub struct Contract {
35 pub predicates: Vec<Predicate>,
37 #[serde(
38 serialize_with = "hash::serialize",
39 deserialize_with = "hash::deserialize"
40 )]
41 pub salt: Hash,
43}
44
45impl Contract {
46 pub const MAX_PREDICATES: usize = 100;
48
49 pub fn without_salt(predicates: Vec<Predicate>) -> Self {
51 Self {
52 predicates,
53 ..Default::default()
54 }
55 }
56}
57
58impl From<Vec<Predicate>> for Contract {
59 fn from(predicates: Vec<Predicate>) -> Self {
60 Self {
61 predicates,
62 ..Default::default()
63 }
64 }
65}
66
67impl AsRef<[Predicate]> for Contract {
68 fn as_ref(&self) -> &[Predicate] {
69 &self.predicates
70 }
71}
72
73impl Deref for Contract {
74 type Target = Vec<Predicate>;
75
76 fn deref(&self) -> &Self::Target {
77 &self.predicates
78 }
79}
80
81impl DerefMut for Contract {
82 fn deref_mut(&mut self) -> &mut Self::Target {
83 &mut self.predicates
84 }
85}