Skip to content

Commit 1916982

Browse files
committed
min-ada calculation update
1 parent afffba7 commit 1916982

File tree

5 files changed

+9
-7
lines changed

5 files changed

+9
-7
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.4",
3+
"version": "11.0.1-alpha.5",
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.4"
3+
version = "11.0.1-alpha.5"
44
edition = "2018"
55
authors = ["EMURGO"]
66
license = "MIT"

rust/src/utils.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,31 +1378,33 @@ impl MinOutputAdaCalculator {
13781378
}
13791379

13801380
pub fn calculate_ada(&self) -> Result<BigNum, JsError> {
1381+
let has_data_hash = self.output.has_data_hash().clone();
13811382
let coins_per_byte = self.data_cost.coins_per_byte();
13821383
let mut output: TransactionOutput = self.output.clone();
13831384
fn calc_required_coin(
13841385
output: &TransactionOutput,
13851386
coins_per_byte: &Coin,
1387+
has_data_hash: bool,
13861388
) -> Result<Coin, JsError> {
13871389
// Adding extra words to the estimate
13881390
// <TODO:REMOVE_AFTER_BABBAGE>
1389-
let compatibility_extra_bytes = 80;
1391+
let compatibility_extra_bytes = if has_data_hash { 160 } else { 80 };
13901392
//according to https://hydra.iohk.io/build/15339994/download/1/babbage-changes.pdf
13911393
//See on the page 9 getValue txout
13921394
BigNum::from(output.to_bytes().len())
13931395
.checked_add(&to_bignum(160 + compatibility_extra_bytes))?
13941396
.checked_mul(&coins_per_byte)
13951397
}
13961398
for _ in 0..3 {
1397-
let required_coin = calc_required_coin(&output, &coins_per_byte)?;
1399+
let required_coin = calc_required_coin(&output, &coins_per_byte, has_data_hash)?;
13981400
if output.amount.coin.less_than(&required_coin) {
13991401
output.amount.coin = required_coin.clone();
14001402
} else {
14011403
return Ok(required_coin);
14021404
}
14031405
}
14041406
output.amount.coin = to_bignum(u64::MAX);
1405-
calc_required_coin(&output, &coins_per_byte)
1407+
calc_required_coin(&output, &coins_per_byte, has_data_hash)
14061408
}
14071409

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

0 commit comments

Comments
 (0)