-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: #378 Initial implementation to support PlutusV3 * chore: #378 Cost model sorting logic updated for int keys * fix: Add redeemer only if there is no redeemer for the policy id * feat: #402 Add Tx Evaluator implementation to return constant cost * chore: Update PlutusV3 cost * feat: Add fee calculation for reference script * feat: Add withReferenceScripts() to QuickTx Builder * feat: Take protocol param as parameter to Tx api * refactor: Int setter for index * feat: Script related methods added for registerDRep, unregisterDRep, createProposal, vote, vote delegation * feat: Added plutus v3 * feat: ScriptSupplier interface * fix: Added reference script to fix fee calculation * chore: New overloaded methods * chore: GovTx script transactions unit tests * chore: cleanup
- Loading branch information
Showing
36 changed files
with
2,482 additions
and
140 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
common-spec/src/main/java/com/bloxbean/cardano/client/spec/EraSerializationConfig.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.bloxbean.cardano.client.spec; | ||
|
||
public enum EraSerializationConfig { | ||
INSTANCE(); | ||
|
||
private boolean useConwayEraFormat = false; | ||
|
||
EraSerializationConfig() { | ||
} | ||
|
||
public boolean useConwayEraFormat() { | ||
return useConwayEraFormat; | ||
} | ||
|
||
public void setUseConwayEraFormat(boolean useConwayEraFormat) { | ||
this.useConwayEraFormat = useConwayEraFormat; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
core-api/src/main/java/com/bloxbean/cardano/client/api/ScriptSupplier.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.bloxbean.cardano.client.api; | ||
|
||
import com.bloxbean.cardano.client.plutus.spec.PlutusScript; | ||
|
||
/** | ||
* Implement this interface to provide PlutusScript | ||
*/ | ||
@FunctionalInterface | ||
public interface ScriptSupplier { | ||
PlutusScript getScript(String scriptHash); | ||
} |
80 changes: 80 additions & 0 deletions
80
core-api/src/main/java/com/bloxbean/cardano/client/api/impl/StaticTransactionEvaluator.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package com.bloxbean.cardano.client.api.impl; | ||
|
||
import com.bloxbean.cardano.client.api.TransactionEvaluator; | ||
import com.bloxbean.cardano.client.api.exception.ApiException; | ||
import com.bloxbean.cardano.client.api.model.EvaluationResult; | ||
import com.bloxbean.cardano.client.api.model.Result; | ||
import com.bloxbean.cardano.client.api.model.Utxo; | ||
import com.bloxbean.cardano.client.exception.CborDeserializationException; | ||
import com.bloxbean.cardano.client.plutus.spec.ExUnits; | ||
import com.bloxbean.cardano.client.transaction.spec.Transaction; | ||
import com.bloxbean.cardano.client.util.JsonUtil; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
/** | ||
* A static implementation of {@link TransactionEvaluator} which returns a static list of {@link EvaluationResult} | ||
*/ | ||
public class StaticTransactionEvaluator implements TransactionEvaluator { | ||
private List<ExUnits> exUnits; | ||
|
||
/** | ||
* Constructor | ||
* @param exUnits List of {@link ExUnits} to be returned as evaluation result. The number of ExUnits should match the | ||
* number of redeemers in the transaction in the order they appear in the transaction | ||
*/ | ||
public StaticTransactionEvaluator(List<ExUnits> exUnits) { | ||
this.exUnits = exUnits; | ||
} | ||
|
||
@Override | ||
public Result<List<EvaluationResult>> evaluateTx(byte[] cbor, Set<Utxo> inputUtxos) throws ApiException { | ||
var evaluationResults = getEvaluationResults(cbor); | ||
return Result.success(JsonUtil.getPrettyJson(evaluationResults)).withValue(evaluationResults); | ||
} | ||
|
||
@Override | ||
public Result<List<EvaluationResult>> evaluateTx(byte[] cbor) throws ApiException { | ||
var evaluationResults = getEvaluationResults(cbor); | ||
return Result.success(JsonUtil.getPrettyJson(evaluationResults)).withValue(evaluationResults); | ||
} | ||
|
||
@Override | ||
public Result<List<EvaluationResult>> evaluateTx(Transaction transaction, Set<Utxo> inputUtxos) throws ApiException { | ||
var evaluationResults = getEvaluationResults(transaction); | ||
return Result.success(JsonUtil.getPrettyJson(evaluationResults)).withValue(evaluationResults); | ||
} | ||
|
||
private List<EvaluationResult> getEvaluationResults(byte[] txCbor) { | ||
Transaction transaction = null; | ||
try { | ||
transaction = Transaction.deserialize(txCbor); | ||
} catch (CborDeserializationException e) { | ||
throw new IllegalArgumentException("Invalid transaction cbor. Cost cannot be returned"); | ||
} | ||
return getEvaluationResults(transaction); | ||
} | ||
|
||
private List<EvaluationResult> getEvaluationResults(Transaction transaction) { | ||
if (transaction.getWitnessSet().getRedeemers() == null) | ||
throw new IllegalArgumentException("Transaction doesn't have redeemers. Cost cannot be returned"); | ||
|
||
if (transaction.getWitnessSet().getRedeemers().size() != exUnits.size()) | ||
throw new IllegalArgumentException("Number of redeemers in the transaction doesn't match the number of exUnits provided"); | ||
|
||
List<EvaluationResult> evaluationResults = new ArrayList<>(); | ||
for (int i = 0; i < transaction.getWitnessSet().getRedeemers().size(); i++) { | ||
var redeemer = transaction.getWitnessSet().getRedeemers().get(i); | ||
var evaluationResult = new EvaluationResult(); | ||
evaluationResult.setExUnits(exUnits.get(i)); | ||
evaluationResult.setIndex(redeemer.getIndex().intValue()); | ||
evaluationResult.setRedeemerTag(redeemer.getTag()); | ||
|
||
evaluationResults.add(evaluationResult); | ||
} | ||
|
||
return evaluationResults; | ||
} | ||
} |
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
Oops, something went wrong.