Struct cardano_serialization_lib::Mint
source · pub struct Mint(_);
Implementations§
source§impl Mint
impl Mint
pub fn from_bytes(bytes: Vec<u8>) -> Result<Mint, DeserializeError>
source§impl Mint
impl Mint
sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
More examples
src/tx_builder/mint_builder.rs (line 107)
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: &PolicyID, value: &MintAssets) -> Self
pub fn new_from_entry(key: &PolicyID, value: &MintAssets) -> Self
Examples found in repository?
src/tx_builder.rs (lines 1183-1186)
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: &PolicyID, value: &MintAssets) -> Option<MintAssets>
pub fn insert(&mut self, key: &PolicyID, value: &MintAssets) -> Option<MintAssets>
Examples found in repository?
More examples
src/tx_builder/mint_builder.rs (line 115)
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 get(&self, key: &PolicyID) -> Option<MintAssets>
👎Deprecated since 11.2.0: Mint can store multiple entries for the same policy id. Use .get_all
instead.
pub fn get(&self, key: &PolicyID) -> Option<MintAssets>
.get_all
instead.!!! DEPRECATED !!!
Mint can store multiple entries for the same policy id.
Use .get_all
instead.
pub fn get_all(&self, key: &PolicyID) -> Option<MintsAssets>
sourcepub fn keys(&self) -> PolicyIDs
pub fn keys(&self) -> PolicyIDs
Examples found in repository?
src/tx_builder.rs (line 167)
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
fn assert_required_mint_scripts(
mint: &Mint,
maybe_mint_scripts: Option<&NativeScripts>,
) -> Result<(), JsError> {
if maybe_mint_scripts.is_none_or_empty() {
return Err(JsError::from_str(
"Mint is present in the builder, but witness scripts are not provided!",
));
}
let mint_scripts = maybe_mint_scripts.unwrap();
let witness_hashes: HashSet<ScriptHash> =
mint_scripts.0.iter().map(|script| script.hash()).collect();
for mint_hash in mint.keys().0.iter() {
if !witness_hashes.contains(mint_hash) {
return Err(JsError::from_str(&format!(
"No witness script is found for mint policy '{:?}'! Script is required!",
hex::encode(mint_hash.to_bytes()),
)));
}
}
Ok(())
}
sourcepub fn as_positive_multiasset(&self) -> MultiAsset
pub fn as_positive_multiasset(&self) -> MultiAsset
Returns the multiasset where only positive (minting) entries are present
Examples found in repository?
src/tx_builder.rs (line 1187)
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 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290
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 new(cfg: &TransactionBuilderConfig) -> Self {
Self {
config: cfg.clone(),
inputs: TxInputsBuilder::new(),
collateral: TxInputsBuilder::new(),
outputs: TransactionOutputs::new(),
fee: None,
ttl: None,
certs: None,
withdrawals: None,
auxiliary_data: None,
validity_start_interval: None,
mint: None,
script_data_hash: None,
required_signers: Ed25519KeyHashes::new(),
collateral_return: None,
total_collateral: None,
reference_inputs: HashSet::new(),
}
}
pub fn get_reference_inputs(&self) -> TransactionInputs {
let mut inputs = self.reference_inputs.clone();
for input in self.inputs.get_ref_inputs().0 {
inputs.insert(input);
}
let vec_inputs = inputs.into_iter().collect();
TransactionInputs(vec_inputs)
}
/// does not include refunds or withdrawals
pub fn get_explicit_input(&self) -> Result<Value, JsError> {
self.inputs
.iter()
.try_fold(Value::zero(), |acc, ref tx_builder_input| {
acc.checked_add(&tx_builder_input.amount)
})
}
/// withdrawals and refunds
pub fn get_implicit_input(&self) -> Result<Value, JsError> {
internal_get_implicit_input(
&self.withdrawals,
&self.certs,
&self.config.pool_deposit,
&self.config.key_deposit,
)
}
/// Returns mint as tuple of (mint_value, burn_value) or two zero values
fn get_mint_as_values(&self) -> (Value, Value) {
self.mint
.as_ref()
.map(|m| {
(
Value::new_from_assets(&m.build().as_positive_multiasset()),
Value::new_from_assets(&m.build().as_negative_multiasset()),
)
})
.unwrap_or((Value::zero(), Value::zero()))
}
sourcepub fn as_negative_multiasset(&self) -> MultiAsset
pub fn as_negative_multiasset(&self) -> MultiAsset
Returns the multiasset where only negative (burning) entries are present
Trait Implementations§
source§impl<'de> Deserialize<'de> for Mint
impl<'de> Deserialize<'de> for Mint
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 Mint
impl Deserialize for Mint
fn deserialize<R: BufRead + Seek>(
raw: &mut Deserializer<R>
) -> Result<Self, DeserializeError>
source§impl JsonSchema for Mint
impl JsonSchema for Mint
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 Mint
impl Ord for Mint
source§impl PartialEq<Mint> for Mint
impl PartialEq<Mint> for Mint
source§impl PartialOrd<Mint> for Mint
impl PartialOrd<Mint> for Mint
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