From 36cda41b5bc225aceacd0fef9c90b1a216370fe9 Mon Sep 17 00:00:00 2001 From: dzung pham Date: Wed, 29 May 2024 18:34:15 +0700 Subject: [PATCH] fix ledger --- packages/translucent/src/translucent/tx.ts | 26 +++++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/packages/translucent/src/translucent/tx.ts b/packages/translucent/src/translucent/tx.ts index a22f0cb..1fae55f 100644 --- a/packages/translucent/src/translucent/tx.ts +++ b/packages/translucent/src/translucent/tx.ts @@ -330,10 +330,16 @@ export class Tx { parseInt(output.output().amount().coin().to_str()), Number(assets.lovelace || 0), ); - valueBuilder = valueBuilder.with_coin_and_asset( - C.BigNum.from_str(coin.toString()), - masset, - ); + if (masset.len() > 0) { + valueBuilder = valueBuilder.with_coin_and_asset( + C.BigNum.from_str(coin.toString()), + masset, + ); + } else { + valueBuilder = valueBuilder.with_coin( + C.BigNum.from_str(coin.toString()) + ); + } } let output = valueBuilder.build(); that.txBuilder.add_output(output); @@ -870,11 +876,19 @@ export class Tx { let params = this.translucent.provider ? await this.translucent.provider.getProtocolParameters() : PROTOCOL_PARAMETERS_DEFAULT; - let multiAsset = foundUtxo.output().amount().multiasset(); + let multiAsset = foundUtxo.output().amount().multiasset() + multiAsset = multiAsset ?? C.MultiAsset.new(); amtBuilder = amtBuilder.with_asset_and_min_required_coin( - multiAsset || C.MultiAsset.new(), + multiAsset, C.BigNum.from_str(params.coinsPerUtxoByte.toString()), ); + let amtBuilderResult = amtBuilder.build(); + if (multiAsset.len() == 0) { + const collateralCoin = amtBuilderResult.output().amount().coin().to_str(); + amtBuilder = amtBuilder.with_coin( + C.BigNum.from_str(collateralCoin) + ); + } const collateralReturn = amtBuilder.build().output(); this.txBuilder.add_collateral(collateralUTxO); this.txBuilder.set_collateral_return(collateralReturn);