Skip to content

Commit 0979c7a

Browse files
committed
min-ada calculation update, Version bump: 11.0.1
1 parent 1916982 commit 0979c7a

File tree

6 files changed

+19
-10
lines changed

6 files changed

+19
-10
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cardano-serialization-lib",
3-
"version": "11.0.1-alpha.5",
3+
"version": "11.0.1",
44
"description": "(De)serialization functions for the Cardano blockchain along with related utility functions",
55
"scripts": {
66
"rust:build-nodejs": "(rimraf ./rust/pkg && cd rust; wasm-pack build --target=nodejs; cd ..; npm run js:ts-json-gen; cd rust; wasm-pack pack) && npm run js:flowgen",

rust/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cardano-serialization-lib"
3-
version = "11.0.1-alpha.5"
3+
version = "11.0.1"
44
edition = "2018"
55
authors = ["EMURGO"]
66
license = "MIT"

rust/json-gen/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/src/utils.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,13 @@ impl Value {
408408
.unwrap_or(true)
409409
}
410410

411+
pub(crate) fn has_assets(&self) -> bool {
412+
match &self.multiasset {
413+
Some(ma) => { ma.len() > 0 }
414+
_ => false
415+
}
416+
}
417+
411418
pub fn coin(&self) -> Coin {
412419
self.coin
413420
}
@@ -1378,33 +1385,35 @@ impl MinOutputAdaCalculator {
13781385
}
13791386

13801387
pub fn calculate_ada(&self) -> Result<BigNum, JsError> {
1381-
let has_data_hash = self.output.has_data_hash().clone();
13821388
let coins_per_byte = self.data_cost.coins_per_byte();
13831389
let mut output: TransactionOutput = self.output.clone();
13841390
fn calc_required_coin(
13851391
output: &TransactionOutput,
13861392
coins_per_byte: &Coin,
1387-
has_data_hash: bool,
13881393
) -> Result<Coin, JsError> {
13891394
// Adding extra words to the estimate
13901395
// <TODO:REMOVE_AFTER_BABBAGE>
1391-
let compatibility_extra_bytes = if has_data_hash { 160 } else { 80 };
1396+
let compatibility_extra_bytes = if output.amount().has_assets() {
1397+
if output.has_data_hash() { 160 } else { 80 }
1398+
} else {
1399+
0
1400+
};
13921401
//according to https://hydra.iohk.io/build/15339994/download/1/babbage-changes.pdf
13931402
//See on the page 9 getValue txout
13941403
BigNum::from(output.to_bytes().len())
13951404
.checked_add(&to_bignum(160 + compatibility_extra_bytes))?
13961405
.checked_mul(&coins_per_byte)
13971406
}
13981407
for _ in 0..3 {
1399-
let required_coin = calc_required_coin(&output, &coins_per_byte, has_data_hash)?;
1408+
let required_coin = calc_required_coin(&output, &coins_per_byte)?;
14001409
if output.amount.coin.less_than(&required_coin) {
14011410
output.amount.coin = required_coin.clone();
14021411
} else {
14031412
return Ok(required_coin);
14041413
}
14051414
}
14061415
output.amount.coin = to_bignum(u64::MAX);
1407-
calc_required_coin(&output, &coins_per_byte, has_data_hash)
1416+
calc_required_coin(&output, &coins_per_byte)
14081417
}
14091418

14101419
fn create_fake_output() -> Result<TransactionOutput, JsError> {

0 commit comments

Comments
 (0)