Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/slot config tx evaluation #22

Merged
merged 3 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
group = com.bloxbean.cardano
artifactId = aiken-java-binding
version = 0.0.9-rc1
version = 0.0.9-rc2

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import com.bloxbean.cardano.client.backend.api.BackendService;
import com.bloxbean.cardano.client.backend.api.DefaultProtocolParamsSupplier;
import com.bloxbean.cardano.client.backend.api.DefaultUtxoSupplier;
import com.bloxbean.cardano.client.common.model.SlotConfig;
import com.bloxbean.cardano.client.common.model.SlotConfigs;
import com.bloxbean.cardano.client.plutus.spec.*;
import com.bloxbean.cardano.client.transaction.spec.Transaction;
import com.bloxbean.cardano.client.transaction.spec.TransactionInput;
Expand All @@ -35,15 +37,29 @@ public class AikenTransactionEvaluator implements TransactionEvaluator {
private UtxoSupplier utxoSupplier;
private ProtocolParamsSupplier protocolParamsSupplier;
private ScriptSupplier scriptSupplier;
private final SlotConfig slotConfig;

/**
* Constructor
* Constructor for mainnet.
* Use AikenTransactionEvaluator(@NonNull BackendService backendService, SlotConfig slotConfig)
* if you need to run TransactionEvaluation for any non-mainnet network instead
*
* @param backendService Backend service
*/
public AikenTransactionEvaluator(@NonNull BackendService backendService) {
this(backendService, SlotConfigs.mainnet());
}

/**
* Constructor
*
* @param backendService Backend service
* @param slotConfig the slot config to use, useful for non-mainnet network tx evaluation
*/
public AikenTransactionEvaluator(@NonNull BackendService backendService, SlotConfig slotConfig) {
this.utxoSupplier = new DefaultUtxoSupplier(backendService.getUtxoService());
this.protocolParamsSupplier = new DefaultProtocolParamsSupplier(backendService.getEpochService());
this.slotConfig = slotConfig;
}

/**
Expand All @@ -55,6 +71,7 @@ public AikenTransactionEvaluator(@NonNull BackendService backendService, ScriptS
this.utxoSupplier = new DefaultUtxoSupplier(backendService.getUtxoService());
this.protocolParamsSupplier = new DefaultProtocolParamsSupplier(backendService.getEpochService());
this.scriptSupplier = scriptSupplier;
this.slotConfig = SlotConfigs.mainnet();
}

/**
Expand All @@ -66,6 +83,7 @@ public AikenTransactionEvaluator(@NonNull BackendService backendService, ScriptS
public AikenTransactionEvaluator(@NonNull UtxoSupplier utxoSupplier, @NonNull ProtocolParamsSupplier protocolParamsSupplier) {
this.utxoSupplier = utxoSupplier;
this.protocolParamsSupplier = protocolParamsSupplier;
this.slotConfig = SlotConfigs.mainnet();
}

/**
Expand All @@ -76,9 +94,23 @@ public AikenTransactionEvaluator(@NonNull UtxoSupplier utxoSupplier, @NonNull Pr
*/
public AikenTransactionEvaluator(@NonNull UtxoSupplier utxoSupplier, @NonNull ProtocolParamsSupplier protocolParamsSupplier,
ScriptSupplier scriptSupplier) {
this(utxoSupplier, protocolParamsSupplier, scriptSupplier, SlotConfigs.mainnet());
}


/**
* Constructor
* @param utxoSupplier Utxo supplier
* @param protocolParamsSupplier Protocol params supplier
* @param scriptSupplier Script supplier to provide additional scripts (e.g; scripts in reference inputs) to evaluate
* * @param slotConfig the slot config to use, useful for non-mainnet network tx evaluation
*/
public AikenTransactionEvaluator(@NonNull UtxoSupplier utxoSupplier, @NonNull ProtocolParamsSupplier protocolParamsSupplier,
ScriptSupplier scriptSupplier, SlotConfig slotConfig) {
this.utxoSupplier = utxoSupplier;
this.protocolParamsSupplier = protocolParamsSupplier;
this.scriptSupplier = scriptSupplier;
this.slotConfig = slotConfig;
}

@Override
Expand Down Expand Up @@ -129,7 +161,7 @@ public Result<List<EvaluationResult>> evaluateTx(byte[] cbor, Set<Utxo> inputUtx
CostMdls costMdls = new CostMdls();
costMdls.add(costModelOptional.get());

TxEvaluator txEvaluator = new TxEvaluator();
TxEvaluator txEvaluator = new TxEvaluator(getSlotConfig());
List<Redeemer> redeemers = txEvaluator.evaluateTx(transaction, utxos, additionalScripts, costMdls);
if (redeemers == null)
return Result.success("Error evaluating transaction");
Expand All @@ -144,4 +176,12 @@ public Result<List<EvaluationResult>> evaluateTx(byte[] cbor, Set<Utxo> inputUtx
throw new ApiException("Error evaluating transaction", e);
}
}

private com.bloxbean.cardano.aiken.tx.evaluator.SlotConfig getSlotConfig() {
com.bloxbean.cardano.aiken.tx.evaluator.SlotConfig.SlotConfigByReference slotConfig = new com.bloxbean.cardano.aiken.tx.evaluator.SlotConfig.SlotConfigByReference();
slotConfig.zero_time = this.slotConfig.getZeroTime();
slotConfig.zero_slot = this.slotConfig.getZeroSlot();
slotConfig.slot_length = this.slotConfig.getSlotLength();
return slotConfig;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,29 @@ public TxEvaluator(InitialBudgetConfig initialBudgetConfig) {
this.initialBudgetConfig.cpu = initialBudgetConfig.cpu;
}

/**
* Construct instance of TxEvaluator with an initial transaction budget config.
* Those values are typically present on protocol-parameters.json.
*
* "maxTxExecutionUnits": {
* "memory": 14000000,
* "steps": 10000000000
* }
*
* Typical scenario to override those values is where one uses L2 solution, e.g. Hydra
* with custom config or custom dev network (e.g. using yaci-devkit).
*
* @param slotConfig - slot config values as specified during shelley genesis era
*/
public TxEvaluator(SlotConfig slotConfig) {
this.slotConfig = new SlotConfig.SlotConfigByReference();
this.slotConfig.zero_slot = slotConfig.zero_slot;
this.slotConfig.zero_time = slotConfig.zero_time;
this.slotConfig.slot_length = slotConfig.slot_length;

this.initialBudgetConfig = getDefaultInitialBudgetConfig();
}

/**
* Construct instance of TxEvaluator with an initial transaction budget config.
* Those values are typically present on
Expand Down
Loading