-
Notifications
You must be signed in to change notification settings - Fork 46
/
witnesses.rs
85 lines (74 loc) · 2.69 KB
/
witnesses.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
use pallas_primitives::{
alonzo::{self, BootstrapWitness, NativeScript, PlutusData, Redeemer, VKeyWitness},
babbage::{self, PlutusV2Script},
};
use crate::MultiEraWitnesses;
impl<'b> MultiEraWitnesses<'b> {
pub fn as_alonzo(&self) -> Option<&alonzo::TransactionWitnessSet> {
match self {
Self::AlonzoCompatible(x) => Some(x),
_ => None,
}
}
pub fn as_babbage(&self) -> Option<&babbage::TransactionWitnessSet> {
match self {
Self::Babbage(x) => Some(x),
_ => None,
}
}
pub fn vkeywitness(&self) -> Option<&[VKeyWitness]> {
match self {
Self::AlonzoCompatible(x) => x.vkeywitness.as_ref().map(|x| x.as_ref()),
Self::Babbage(x) => x.vkeywitness.as_ref().map(|x| x.as_ref()),
_ => None,
}
}
pub fn native_script(&self) -> Option<&[NativeScript]> {
match self {
Self::AlonzoCompatible(x) => x.native_script.as_ref().map(|x| x.as_ref()),
Self::Babbage(x) => x.native_script.as_ref().map(|x| x.as_ref()),
_ => None,
}
}
pub fn bootstrap_witness(&self) -> Option<&[BootstrapWitness]> {
match self {
Self::AlonzoCompatible(x) => x.bootstrap_witness.as_ref().map(|x| x.as_ref()),
Self::Babbage(x) => x.bootstrap_witness.as_ref().map(|x| x.as_ref()),
_ => None,
}
}
pub fn plutus_v1_script(&self) -> Option<&[alonzo::PlutusScript]> {
match self {
Self::AlonzoCompatible(x) => x.plutus_script.as_ref().map(|x| x.as_ref()),
Self::Babbage(x) => x.plutus_v1_script.as_ref().map(|x| x.as_ref()),
_ => None,
}
}
pub fn plutus_data(&self) -> Option<&[PlutusData]> {
match self {
Self::AlonzoCompatible(x) => x.plutus_data.as_ref().map(|x| x.as_ref()),
Self::Babbage(x) => x.plutus_data.as_ref().map(|x| x.as_ref()),
_ => None,
}
}
pub fn redeemer(&self) -> Option<&[Redeemer]> {
match self {
Self::AlonzoCompatible(x) => x.redeemer.as_ref().map(|x| x.as_ref()),
Self::Babbage(x) => x.redeemer.as_ref().map(|x| x.as_ref()),
_ => None,
}
}
pub fn plutus_v2_script(&self) -> Option<&[PlutusV2Script]> {
match self {
Self::Babbage(x) => x.plutus_v2_script.as_ref().map(|x| x.as_ref()),
_ => None,
}
}
pub fn cbor(&self) -> &[u8] {
match self {
MultiEraWitnesses::AlonzoCompatible(x) => x.raw_cbor(),
MultiEraWitnesses::Babbage(x) => x.raw_cbor(),
MultiEraWitnesses::Byron(x) => x.raw_cbor(),
}
}
}