cardano-client-lib
cardano-client-lib copied to clipboard
QuickTx: Add ScriptTx.collectFrom(List<Utxo>) without redeemer
Currently, the ScriptTx.collectUtxo method accepts utxo/List<Utxo> and redeemer data as parameters. However, in some scenarios, the redeemer is not required, but a specific utxo is needed as input.
For example,
- A minting script only mints if certain utxo is present in inputs
Currently, to include a utxo, we must also pass the redeemer. However, when redeemer data is provided as an argument, the QuickTx builder creates a redeemer in the witness. As a result, we need to remove that extra redeemer (spend) in the preBalance
method.
This is a workaround for now.
ScriptTx scriptTx = new ScriptTx()
.collectFrom(utxo, PlutusData.unit())
.mintAsset(giftPlutusScript, new Asset(tokenName, BigInteger.valueOf(1)), mintAction, senderAddress);
Result<String> result = new QuickTxBuilder(backendService)
.compose(scriptTx)
.feePayer(senderAddress)
.withSigner(SignerProviders.signerFrom(sender))
.withTxEvaluator(new AikenTransactionEvaluator(backendService))
.preBalanceTx((context, txn) -> {
txn.getWitnessSet().getRedeemers().removeIf(redeemer -> redeemer.getTag() == RedeemerTag.Spend);
}).completeAndWait(System.out::println);
Solution
ScriptTx should introduce a new method, collectUtxo(List<Utxo>), that doesn't require redeemer data. In this scenario, the builder should simply balance the transaction.