Created
July 29, 2022 14:15
-
-
Save satran004/097259ef34c3daff4e6e4d4261a5f48e to your computer and use it in GitHub Desktop.
CL-PL9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TxBuilder contractTxBuilder = output.outputBuilder() | |
.buildInputs(InputBuilders.createFromUtxos(List.of(scriptUtxo))) | |
.andThen(InputBuilders.referenceInputsFromUtxos(List.of(refScriptUtxo))) //CIP-31 | |
.andThen(CollateralBuilders.collateralOutputs(senderAddress, Lists.newArrayList(collateralUtxos))) //CIP-40 | |
.andThen(ScriptCallContextProviders.createFromScriptCallContext(scriptCallContext)) | |
.andThen((context, txn) -> { | |
//Calculate ExUnit. It should be done before balanceTx for accurate fee calculation | |
//update estimate ExUnits | |
ExUnits estimatedExUnits; | |
try { | |
estimatedExUnits = evaluateExUnits(txn); | |
txn.getWitnessSet().getRedeemers().get(0).setExUnits(estimatedExUnits); | |
} catch (Exception e) { | |
throw new ApiRuntimeException("Script cost evaluation failed", e); | |
} | |
//Remove script from witnessset as we are using reference script input | |
txn.getWitnessSet().getPlutusV2Scripts().clear(); | |
}) | |
.andThen(BalanceTxBuilders.balanceTx(senderAddress, 2)); | |
TxBuilderContext txBuilderContext = TxBuilderContext.init(utxoSupplier, protocolParamsSupplier); | |
//Tx Build and Submit | |
TxSigner signer = signerFrom(sender); | |
Transaction signedTx = txBuilderContext.buildAndSign(contractTxBuilder, signer); | |
Result<String> result = backendService.getTransactionService().submitTransaction(signedTx.serialize()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment