Struct cardano_serialization_lib::plutus::PlutusScripts
source · pub struct PlutusScripts(_);
Implementations§
source§impl PlutusScripts
impl PlutusScripts
pub fn from_bytes(bytes: Vec<u8>) -> Result<PlutusScripts, DeserializeError>
source§impl PlutusScripts
impl PlutusScripts
pub fn from_hex(hex_str: &str) -> Result<PlutusScripts, DeserializeError>
source§impl PlutusScripts
impl PlutusScripts
source§impl PlutusScripts
impl PlutusScripts
sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
More examples
src/tx_builder/tx_inputs_builder.rs (line 213)
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
pub(crate) fn collect(&self) -> (PlutusScripts, Option<PlutusList>, Redeemers) {
let mut used_scripts = BTreeSet::new();
let mut used_datums = BTreeSet::new();
let mut used_redeemers = BTreeSet::new();
let mut s = PlutusScripts::new();
let mut d : Option<PlutusList> = None;
let mut r = Redeemers::new();
self.0.iter().for_each(|w| {
if let PlutusScriptSourceEnum::Script(script) = &w.script {
if used_scripts.insert(script.clone()) {
s.add(script);
}
}
if let Some(DatumSourceEnum::Datum(datum)) = &w.datum {
if used_datums.insert(datum) {
match d {
Some(ref mut d) => d.add(datum),
None => d = {
let mut initial_list = PlutusList::new();
initial_list.add(datum);
Some(initial_list)
}
}
}
}
if used_redeemers.insert(w.redeemer.clone()) {
r.add(&w.redeemer);
}
});
(s, d, r)
}
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Examples found in repository?
src/metadata.rs (line 1012)
972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019
fn serialize<'se, W: Write>(
&self,
serializer: &'se mut Serializer<W>,
) -> cbor_event::Result<&'se mut Serializer<W>> {
// we still serialize using the shelley-mary era format as it is still supported
// and it takes up less space on-chain so this should be better for scaling.
// Plus the code was already written for shelley-mary anyway
if !self.prefer_alonzo_format && self.metadata.is_some() && self.plutus_scripts.is_none() {
match &self.native_scripts() {
Some(native_scripts) => {
serializer.write_array(cbor_event::Len::Len(2))?;
self.metadata.as_ref().unwrap().serialize(serializer)?;
native_scripts.serialize(serializer)
}
None => self.metadata.as_ref().unwrap().serialize(serializer),
}
} else {
let plutus_added_length = match &self.plutus_scripts {
Some(scripts) => 1 + (scripts.has_version(&Language::new_plutus_v2()) as u64),
_ => 0,
};
// new format with plutus support
serializer.write_tag(259u64)?;
serializer.write_map(cbor_event::Len::Len(
opt64(&self.metadata) + opt64(&self.native_scripts) + plutus_added_length,
))?;
if let Some(metadata) = &self.metadata {
serializer.write_unsigned_integer(0)?;
metadata.serialize(serializer)?;
}
if let Some(native_scripts) = &self.native_scripts {
serializer.write_unsigned_integer(1)?;
native_scripts.serialize(serializer)?;
}
if let Some(plutus_scripts) = &self.plutus_scripts {
serializer.write_unsigned_integer(2)?;
plutus_scripts
.by_version(&Language::new_plutus_v1())
.serialize(serializer)?;
let v2 = plutus_scripts.by_version(&Language::new_plutus_v2());
if v2.len() > 0 {
serializer.write_unsigned_integer(3)?;
v2.serialize(serializer)?;
}
}
Ok(serializer)
}
}
pub fn get(&self, index: usize) -> PlutusScript
sourcepub fn add(&mut self, elem: &PlutusScript)
pub fn add(&mut self, elem: &PlutusScript)
Examples found in repository?
src/plutus.rs (line 196)
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
pub(crate) fn merge(&self, other: &PlutusScripts) -> PlutusScripts {
let mut res = self.clone();
for s in &other.0 {
res.add(s);
}
res
}
pub(crate) fn map_as_version(&self, language: &Language) -> PlutusScripts {
let mut res = PlutusScripts::new();
for s in &self.0 {
res.add(&s.clone_as_version(language));
}
res
}
More examples
src/tx_builder/tx_inputs_builder.rs (line 219)
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
pub(crate) fn collect(&self) -> (PlutusScripts, Option<PlutusList>, Redeemers) {
let mut used_scripts = BTreeSet::new();
let mut used_datums = BTreeSet::new();
let mut used_redeemers = BTreeSet::new();
let mut s = PlutusScripts::new();
let mut d : Option<PlutusList> = None;
let mut r = Redeemers::new();
self.0.iter().for_each(|w| {
if let PlutusScriptSourceEnum::Script(script) = &w.script {
if used_scripts.insert(script.clone()) {
s.add(script);
}
}
if let Some(DatumSourceEnum::Datum(datum)) = &w.datum {
if used_datums.insert(datum) {
match d {
Some(ref mut d) => d.add(datum),
None => d = {
let mut initial_list = PlutusList::new();
initial_list.add(datum);
Some(initial_list)
}
}
}
}
if used_redeemers.insert(w.redeemer.clone()) {
r.add(&w.redeemer);
}
});
(s, d, r)
}
Trait Implementations§
source§impl Clone for PlutusScripts
impl Clone for PlutusScripts
source§fn clone(&self) -> PlutusScripts
fn clone(&self) -> PlutusScripts
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for PlutusScripts
impl Debug for PlutusScripts
source§impl<'de> Deserialize<'de> for PlutusScripts
impl<'de> Deserialize<'de> for PlutusScripts
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl Deserialize for PlutusScripts
impl Deserialize for PlutusScripts
fn deserialize<R: BufRead + Seek>(
raw: &mut Deserializer<R>
) -> Result<Self, DeserializeError>
source§impl JsonSchema for PlutusScripts
impl JsonSchema for PlutusScripts
source§fn schema_name() -> String
fn schema_name() -> String
The name of the generated JSON Schema. Read more
source§fn json_schema(gen: &mut SchemaGenerator) -> Schema
fn json_schema(gen: &mut SchemaGenerator) -> Schema
Generates a JSON Schema for this type. Read more
source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
Whether JSON Schemas generated for this type should be re-used where possible using the
$ref
keyword. Read moresource§impl Ord for PlutusScripts
impl Ord for PlutusScripts
source§fn cmp(&self, other: &PlutusScripts) -> Ordering
fn cmp(&self, other: &PlutusScripts) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
source§impl PartialEq<PlutusScripts> for PlutusScripts
impl PartialEq<PlutusScripts> for PlutusScripts
source§fn eq(&self, other: &PlutusScripts) -> bool
fn eq(&self, other: &PlutusScripts) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd<PlutusScripts> for PlutusScripts
impl PartialOrd<PlutusScripts> for PlutusScripts
source§fn partial_cmp(&self, other: &PlutusScripts) -> Option<Ordering>
fn partial_cmp(&self, other: &PlutusScripts) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read more