Skip to content

Commit 56ba7f1

Browse files
authored
Merge pull request #100 from mlabs-haskell/szg251/minor
Minor update
2 parents eee9b94 + 4471f88 commit 56ba7f1

File tree

7 files changed

+109
-56
lines changed

7 files changed

+109
-56
lines changed

plutus-ledger-api/CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@
55
This changelog is based on [Keep A
66
Changelog](https://keepachangelog.com/en/1.1.0).
77

8+
## 3.1.0
9+
10+
### Added
11+
12+
- Add `insert_ada_mut` to `Value`
13+
- Add `insert_token_mut` to `Value`
14+
- Add `Copy` derive macro to `Extended<T>` and `Vote`
15+
- Update all dependencies (including cardano-serialization-lib 15.0.1)
16+
17+
## v3.0.4
18+
19+
### Changed
20+
21+
- Updating all dependencies to latest minor versions
22+
823
## v3.0.3
924

1025
### Changed

plutus-ledger-api/Cargo.lock

Lines changed: 37 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plutus-ledger-api/Cargo.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "plutus-ledger-api"
3-
version = "3.0.4"
3+
version = "3.1.0"
44
edition = "2021"
55
license = "Apache-2.0"
66
description = "Plutus Ledger types and utilities implemented in Rust"
@@ -9,20 +9,20 @@ repository = "https://github.com/mlabs-haskell/plutus-ledger-api-rust"
99
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1010

1111
[dependencies]
12-
proptest = "^1.7.0"
12+
proptest = "^1.8.0"
1313
lbr-prelude = { version = "0.1.3", optional = true }
14-
serde_json = { version = "1.0.142", optional = true }
14+
serde_json = { version = "1.0.145", optional = true }
1515
num-bigint = "~0.4"
16-
serde = { version = "^1.0.219", features = ["derive"], optional = true }
16+
serde = { version = "^1.0.228", features = ["derive"], optional = true }
1717
data-encoding = "^2.9.0"
1818
thiserror = "^1.0.69"
1919
linked-hash-map = "~0.5.6"
2020
num-traits = "~0.2.19"
2121
impl_ops = "0.1.1"
22-
chrono = { version = "0.4.41", optional = true }
23-
cardano-serialization-lib = "14.1.2"
22+
chrono = { version = "0.4.42", optional = true }
23+
cardano-serialization-lib = "15.0.1"
2424
is-plutus-data-derive = { version = "1.0.0", path = ".extras/is-plutus-data-derive-0" }
25-
anyhow = "1.0.98"
25+
anyhow = "1.0.100"
2626
nom = "7.1.3"
2727

2828
[features]

plutus-ledger-api/src/v1/interval.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ where
356356
//////////////
357357

358358
/// A set extended with a positive and negative infinity.
359-
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
359+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
360360
#[cfg_attr(feature = "lbf", derive(Json))]
361361
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
362362
pub enum Extended<T>
@@ -416,11 +416,11 @@ where
416416
{
417417
fn to_plutus_data(&self) -> PlutusData {
418418
match self {
419-
Extended::NegInf => PlutusData::Constr(BigInt::from(0), Vec::with_capacity(0)),
419+
Extended::NegInf => PlutusData::Constr(BigInt::from(0), Vec::new()),
420420
Extended::Finite(value) => {
421421
PlutusData::Constr(BigInt::from(1), vec![value.to_plutus_data()])
422422
}
423-
Extended::PosInf => PlutusData::Constr(BigInt::from(2), Vec::with_capacity(0)),
423+
Extended::PosInf => PlutusData::Constr(BigInt::from(2), Vec::new()),
424424
}
425425
}
426426

plutus-ledger-api/src/v1/value.rs

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl IsPlutusData for CurrencySymbol {
112112
fn to_plutus_data(&self) -> PlutusData {
113113
match self {
114114
CurrencySymbol::NativeToken(policy_hash) => policy_hash.to_plutus_data(),
115-
CurrencySymbol::Ada => PlutusData::Bytes(Vec::with_capacity(0)),
115+
CurrencySymbol::Ada => PlutusData::Bytes(Vec::new()),
116116
}
117117
}
118118

@@ -262,23 +262,51 @@ impl Value {
262262
self.get_token_amount(&CurrencySymbol::Ada, &TokenName::ada())
263263
}
264264

265-
/// Insert a new token into the value, or replace the existing quantity.
266-
pub fn insert_token(&self, cs: &CurrencySymbol, tn: &TokenName, a: &BigInt) -> Self {
267-
let mut result_map = self.0.clone();
265+
/// Insert ada into a value by inserting or replacing old value
266+
pub fn insert_ada_mut(&mut self, amount: BigInt) {
267+
self.0.insert(
268+
CurrencySymbol::Ada,
269+
BTreeMap::from([(TokenName::ada(), amount)]),
270+
);
271+
}
268272

269-
result_map
270-
.entry(cs.clone())
271-
.and_modify(|tn_map| {
272-
tn_map
273-
.entry(tn.clone())
274-
.and_modify(|old_a| {
275-
old_a.clone_from(a);
276-
})
277-
.or_insert_with(|| a.clone());
278-
})
279-
.or_insert_with(|| singleton((tn.clone(), a.clone())));
273+
/// Create a new value by inserting a new token or replacing the existing quantity.
274+
pub fn insert_token(
275+
&self,
276+
currency_symbol: &CurrencySymbol,
277+
token_name: &TokenName,
278+
amount: &BigInt,
279+
) -> Self {
280+
let mut result_map = self.clone();
280281

281-
Self(result_map)
282+
result_map.insert_token_mut(currency_symbol.clone(), token_name.clone(), amount.clone());
283+
284+
result_map
285+
}
286+
/// Insert a new token into the value, or replace the existing quantity.
287+
pub fn insert_token_mut(
288+
&mut self,
289+
currency_symbol: CurrencySymbol,
290+
token_name: TokenName,
291+
amount: BigInt,
292+
) {
293+
let tn_map = self.0.get_mut(&currency_symbol);
294+
295+
match tn_map {
296+
None => {
297+
self.0
298+
.insert(currency_symbol, singleton((token_name, amount)));
299+
}
300+
Some(tn_map) => {
301+
let val = tn_map.get_mut(&token_name);
302+
match val {
303+
None => {
304+
tn_map.insert(token_name, amount);
305+
}
306+
Some(old_amount) => *old_amount = amount,
307+
}
308+
}
309+
}
282310
}
283311

284312
/// Return true if the value don't have any entries.
@@ -698,7 +726,7 @@ pub struct TokenName(pub LedgerBytes);
698726
impl TokenName {
699727
/// Ada tokenname (empty bytestring)
700728
pub fn ada() -> TokenName {
701-
TokenName(LedgerBytes(Vec::with_capacity(0)))
729+
TokenName(LedgerBytes(Vec::new()))
702730
}
703731

704732
pub fn is_empty(&self) -> bool {

plutus-ledger-api/src/v2/datum.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub enum OutputDatum {
4040
impl Json for OutputDatum {
4141
fn to_json(&self) -> serde_json::Value {
4242
match self {
43-
OutputDatum::None => json::json_constructor("NoOutputDatum", Vec::with_capacity(0)),
43+
OutputDatum::None => json::json_constructor("NoOutputDatum", Vec::new()),
4444
OutputDatum::DatumHash(dat_hash) => {
4545
json::json_constructor("OutputDatumHash", vec![dat_hash.to_json()])
4646
}

plutus-ledger-api/src/v3/transaction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ pub enum Voter {
326326
// Voter //
327327
///////////
328328

329-
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, IsPlutusData)]
329+
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, IsPlutusData)]
330330
#[is_plutus_data_derive_strategy = "Constr"]
331331
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
332332
#[cfg_attr(feature = "lbf", derive(Json))]

0 commit comments

Comments
 (0)