Skip to content

Commit

Permalink
Updated to use LargestFirst selection strategy and check added for Bl…
Browse files Browse the repository at this point in the history
…ockfrost backend
  • Loading branch information
satran004 committed Mar 30, 2022
1 parent fa67229 commit 5a35e3c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.bloxbean.cardano.client.api.UtxoSupplier;
import com.bloxbean.cardano.client.api.exception.ApiException;
import com.bloxbean.cardano.client.api.helper.FeeCalculationService;
import com.bloxbean.cardano.client.api.helper.TransactionBuilder;
import com.bloxbean.cardano.client.api.helper.TransactionHelperService;
import com.bloxbean.cardano.client.api.helper.model.TransactionResult;
import com.bloxbean.cardano.client.api.model.Result;
Expand All @@ -14,6 +15,7 @@
import com.bloxbean.cardano.client.cip.cip25.NFT;
import com.bloxbean.cardano.client.cip.cip25.NFTFile;
import com.bloxbean.cardano.client.cip.cip25.NFTMetadata;
import com.bloxbean.cardano.client.coinselection.impl.LargestFirstUtxoSelectionStrategy;
import com.bloxbean.cardano.client.common.model.Networks;
import com.bloxbean.cardano.client.function.*;
import com.bloxbean.cardano.client.function.helper.ChangeOutputAdjustments;
Expand Down Expand Up @@ -67,16 +69,19 @@ public class BatchTransactionsIT extends BaseITTest {
public void setup() {
backendService = getBackendService();
utxoService = backendService.getUtxoService();
transactionService = backendService.getTransactionService();
transactionHelperService = backendService.getTransactionHelperService();
blockService = backendService.getBlockService();
feeCalculationService = backendService.getFeeCalculationService();
epochService = backendService.getEpochService();
blockService = backendService.getBlockService();
transactionService = backendService.getTransactionService();

utxoSupplier = new DefaultUtxoSupplier(utxoService);
protocolParamsSupplier = new DefaultProtocolParamsSupplier(epochService);

String senderMnemonic = "race fetch slot fragile front fresh siege insane rapid foster gasp often cigar female match feel legend jazz winner advice depart crumble system rough";
//Create TransactionHelperService with LargestFirst
TransactionBuilder transactionBuilder = new TransactionBuilder(new LargestFirstUtxoSelectionStrategy(utxoSupplier), protocolParamsSupplier);
transactionHelperService = new TransactionHelperService(transactionBuilder, new DefaultTransactionProcessor(transactionService));
feeCalculationService = backendService.getFeeCalculationService(transactionHelperService);

String senderMnemonic = "capable venture stove poet great turtle hurdle photo improve tongue light bean orchard negative clog forest page coil never report hammer grid waste cigar";
sender = new Account(Networks.testnet(), senderMnemonic);
senderAddress = sender.baseAddress();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ void customDatumCustomRedeemerGuessContract() throws CborSerializationException,
.andThen(collateralFrom(collateral, collateralIndex))
.andThen(scriptCallContext(plutusScript, scriptUtxo, guess, guess, RedeemerTag.Spend, exUnits))
.andThen((context, txn) -> { //Evaluate ExUnits
txn.getBody().setFee(BigInteger.ZERO); //Setting it to 0, otherwise serialization will fail
//update estimate ExUnits
ExUnits estimatedExUnits;
try {
Expand Down Expand Up @@ -201,11 +200,18 @@ void customDatumCustomRedeemerGuessContract() throws CborSerializationException,
}

private ExUnits evaluateExUnits(Transaction transaction) throws ApiException, CborSerializationException {
Result<List<EvaluationResult>> evalResults = transactionService.evaluateTx(transaction.serialize());
if (evalResults.isSuccessful()) {
return evalResults.getValue().get(0).getExUnits();
if (backendType.equals(BLOCKFROST)) {
Result<List<EvaluationResult>> evalResults = transactionService.evaluateTx(transaction.serialize());
if (evalResults.isSuccessful()) {
return evalResults.getValue().get(0).getExUnits();
} else {
return null;
}
} else {
return null;
//Hard coded value for other backend types where evaluateTx is not yet supported
return ExUnits.builder()
.mem(BigInteger.valueOf(4676948))
.steps(BigInteger.valueOf(630892334)).build();
}
}

Expand Down

0 comments on commit 5a35e3c

Please sign in to comment.