Struct cardano_serialization_lib::MintAssets
source · pub struct MintAssets(_);
Implementations§
source§impl MintAssets
impl MintAssets
sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
More examples
src/tx_builder/mint_builder.rs (line 111)
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
pub fn build(&self) -> Mint {
let mut mint = Mint::new();
for (_, script_mint) in self.mints.iter() {
match script_mint {
ScriptMint::Native(native_mints) => {
let mut mint_asset = MintAssets::new();
for (asset_name, amount) in &native_mints.mints {
mint_asset.insert(asset_name, amount.clone());
}
mint.insert(&native_mints.script.hash(), &mint_asset);
},
ScriptMint::Plutus(plutus_mints) => {
for (_, redeemer_mints) in &plutus_mints.redeemer_mints {
let mut mint_asset = MintAssets::new();
for (asset_name, amount) in redeemer_mints {
mint_asset.insert(asset_name, amount.clone());
}
mint.insert(&plutus_mints.script.script_hash(), &mint_asset);
}
}
}
}
mint
}
sourcepub fn new_from_entry(key: &AssetName, value: Int) -> Self
pub fn new_from_entry(key: &AssetName, value: Int) -> Self
Examples found in repository?
src/tx_builder.rs (line 1185)
1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227
pub fn add_mint_asset_and_output(
&mut self,
policy_script: &NativeScript,
asset_name: &AssetName,
amount: Int,
output_builder: &TransactionOutputAmountBuilder,
output_coin: &Coin,
) -> Result<(), JsError> {
if !amount.is_positive() {
return Err(JsError::from_str("Output value must be positive!"));
}
let policy_id: PolicyID = policy_script.hash();
self.add_mint_asset(policy_script, asset_name, amount.clone());
let multiasset = Mint::new_from_entry(
&policy_id,
&MintAssets::new_from_entry(asset_name, amount.clone()),
)
.as_positive_multiasset();
self.add_output(
&output_builder
.with_coin_and_asset(&output_coin, &multiasset)
.build()?,
)
}
/// Add a mint entry together with an output to this builder
/// Using a PolicyID, AssetName, Int for amount, and Address objects
/// The asset will be securely added to existing or new Mint in this builder
/// A new output will be added with the specified Address and the minted asset
/// The output will be set to contain the minimum required amount of Coin
pub fn add_mint_asset_and_output_min_required_coin(
&mut self,
policy_script: &NativeScript,
asset_name: &AssetName,
amount: Int,
output_builder: &TransactionOutputAmountBuilder,
) -> Result<(), JsError> {
if !amount.is_positive() {
return Err(JsError::from_str("Output value must be positive!"));
}
let policy_id: PolicyID = policy_script.hash();
self.add_mint_asset(policy_script, asset_name, amount.clone());
let multiasset = Mint::new_from_entry(
&policy_id,
&MintAssets::new_from_entry(asset_name, amount.clone()),
)
.as_positive_multiasset();
self.add_output(
&output_builder
.with_asset_and_min_required_coin_by_utxo_cost(
&multiasset,
&self.config.utxo_cost(),
)?
.build()?,
)
}
pub fn len(&self) -> usize
sourcepub fn insert(&mut self, key: &AssetName, value: Int) -> Option<Int>
pub fn insert(&mut self, key: &AssetName, value: Int) -> Option<Int>
Examples found in repository?
More examples
src/tx_builder/mint_builder.rs (line 113)
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
pub fn build(&self) -> Mint {
let mut mint = Mint::new();
for (_, script_mint) in self.mints.iter() {
match script_mint {
ScriptMint::Native(native_mints) => {
let mut mint_asset = MintAssets::new();
for (asset_name, amount) in &native_mints.mints {
mint_asset.insert(asset_name, amount.clone());
}
mint.insert(&native_mints.script.hash(), &mint_asset);
},
ScriptMint::Plutus(plutus_mints) => {
for (_, redeemer_mints) in &plutus_mints.redeemer_mints {
let mut mint_asset = MintAssets::new();
for (asset_name, amount) in redeemer_mints {
mint_asset.insert(asset_name, amount.clone());
}
mint.insert(&plutus_mints.script.script_hash(), &mint_asset);
}
}
}
}
mint
}
pub fn get(&self, key: &AssetName) -> Option<Int>
pub fn keys(&self) -> AssetNames
Trait Implementations§
source§impl Clone for MintAssets
impl Clone for MintAssets
source§fn clone(&self) -> MintAssets
fn clone(&self) -> MintAssets
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 MintAssets
impl Debug for MintAssets
source§impl<'de> Deserialize<'de> for MintAssets
impl<'de> Deserialize<'de> for MintAssets
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 MintAssets
impl Deserialize for MintAssets
fn deserialize<R: BufRead + Seek>(
raw: &mut Deserializer<R>
) -> Result<Self, DeserializeError>
source§impl JsonSchema for MintAssets
impl JsonSchema for MintAssets
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 MintAssets
impl Ord for MintAssets
source§fn cmp(&self, other: &MintAssets) -> Ordering
fn cmp(&self, other: &MintAssets) -> 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<MintAssets> for MintAssets
impl PartialEq<MintAssets> for MintAssets
source§fn eq(&self, other: &MintAssets) -> bool
fn eq(&self, other: &MintAssets) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd<MintAssets> for MintAssets
impl PartialOrd<MintAssets> for MintAssets
source§fn partial_cmp(&self, other: &MintAssets) -> Option<Ordering>
fn partial_cmp(&self, other: &MintAssets) -> 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