bloxbean / cardano-client-lib

Cardano client library in Java
https://cardano-client.dev
MIT License
118 stars 47 forks source link

Decide cost model for PlutusV3 reference script #405

Open satran004 opened 2 months ago

satran004 commented 2 months ago

Currently, if the reference input is present, the cost model is set to PlutusV2. However, since the reference script can also be a Plutus V3, the library needs to decide the cost model accordingly.

ScriptDataHashCalculator.java

            if (costMdls.isEmpty()) { //Check if costmodel can be decided from other fields //TODO Impl : Check what to do for v3 reference scripts
                if (transaction.getBody().getReferenceInputs() != null
                        && transaction.getBody().getReferenceInputs().size() > 0) { //If reference input is there, then plutus v2
                    var refInputLanguage = ctx.getReferenceInputLanguage();
                    Optional<CostModel> costModel = CostModelUtil.getCostModelFromProtocolParams(ctx.getProtocolParams(), refInputLanguage);
                    costMdls.add(costModel.orElse(PlutusV2CostModel));
                }
            }

Option: 1

Since we have a new method in QuickTxBuilder, withReferenceScripts(PlutusScript ...), we can use this information from the context to determine the correct cost model.

Option: 2

Fetch reference script bytes from node and decide.