bloxbean / cardano-client-lib

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

Incompatibility with Rest.Kois #370

Closed amelongo closed 7 months ago

amelongo commented 7 months ago

Dear Developers,

For a couple of days now I try to resolve an issue in my code only to find out this is due to an incompabitibilty in your code between your class, ProtocolParams, and that of Rest.Kois, EpochParams. The incompabitibility is at line 133 in the KoiosEpochService class. It is due to the fact that costModels is private Map<String, Map<String, Long>> costModels; where as in EpochParams, this is: private JsonNode costModels = null;

The error thrown is :

java.lang.NoSuchMethodError: 'java.util.Map rest.koios.client.backend.api.epoch.model.EpochParams.getCostModels()' at com.bloxbean.cardano.client.backend.koios.KoiosEpochService.convertToProtocolParams(KoiosEpochService.java:146) ~[cardano-client-backend-koios-0.5.0.jar!/:na] at com.bloxbean.cardano.client.backend.koios.KoiosEpochService.getProtocolParameters(KoiosEpochService.java:77) ~[cardano-client-backend-koios-0.5.0.jar!/:na]

And when I tried to use your version of EpochParams available in Rest.Kiois 1.17.3, I get this error:

error getting cardano events class com.fasterxml.jackson.databind.node.ObjectNode cannot be cast to class com.fasterxml.jackson.databind.node.TextNode (com.fasterxml.jackson.databind.node.ObjectNode and com.fasterxml.jackson.databind.node.TextNode are in unnamed module of loader org.springframework.boot.loader.LaunchedURLClassLoader @7ef20235) (through reference chain: java.util.ArrayList[0]->rest.koios.client.backend.api.epoch.model.EpochParams["cost_models"])

private Result<ProtocolParams> convertToProtocolParams(EpochParams epochParams) {
        ProtocolParams protocolParams = new ProtocolParams();
        protocolParams.setMinFeeA(epochParams.getMinFeeA());
        protocolParams.setMinFeeB(epochParams.getMinFeeB());
        protocolParams.setMaxBlockSize(epochParams.getMaxBlockSize());
        protocolParams.setMaxTxSize(epochParams.getMaxTxSize());
        protocolParams.setMaxBlockHeaderSize(epochParams.getMaxBhSize());
        protocolParams.setKeyDeposit(epochParams.getKeyDeposit());
        protocolParams.setPoolDeposit(epochParams.getPoolDeposit());
        protocolParams.setEMax(epochParams.getMaxEpoch());
        protocolParams.setNOpt(epochParams.getOptimalPoolCount());
        protocolParams.setA0(epochParams.getInfluence());
        protocolParams.setRho(epochParams.getMonetaryExpandRate());
        protocolParams.setTau(epochParams.getTreasuryGrowthRate());
        protocolParams.setDecentralisationParam(epochParams.getDecentralisation());
        protocolParams.setExtraEntropy(epochParams.getExtraEntropy());
        protocolParams.setProtocolMajorVer(epochParams.getProtocolMajor());
        protocolParams.setProtocolMinorVer(epochParams.getProtocolMinor());
        protocolParams.setMinUtxo(epochParams.getMinUtxoValue());
        protocolParams.setMinPoolCost(epochParams.getMinPoolCost());
        protocolParams.setNonce(epochParams.getNonce());
        if (epochParams.getPriceMem() != null) {
            protocolParams.setPriceMem(epochParams.getPriceMem());
        }

        if (epochParams.getPriceStep() != null) {
            protocolParams.setPriceStep(epochParams.getPriceStep());
        }

        if (epochParams.getMaxTxExMem() != null) {
            protocolParams.setMaxTxExMem(epochParams.getMaxTxExMem());
        }

        if (epochParams.getMaxTxExSteps() != null) {
            protocolParams.setMaxTxExSteps(epochParams.getMaxTxExSteps());
        }

        if (epochParams.getMaxBlockExMem() != null) {
            protocolParams.setMaxBlockExMem(epochParams.getMaxBlockExMem());
        }

        if (epochParams.getMaxBlockExSteps() != null) {
            protocolParams.setMaxBlockExSteps(epochParams.getMaxBlockExSteps());
        }

        if (epochParams.getMaxValSize() != null) {
            protocolParams.setMaxValSize(epochParams.getMaxValSize());
        }

        if (epochParams.getCollateralPercent() != null) {
            protocolParams.setCollateralPercent(BigDecimal.valueOf((long)epochParams.getCollateralPercent()));
        }

        if (epochParams.getMaxCollateralInputs() != null) {
            protocolParams.setMaxCollateralInputs(epochParams.getMaxCollateralInputs());
        }

        **if (epochParams.getCostModels() != null) {
            protocolParams.setCostModels(epochParams.getCostModels());
        }**

        if (epochParams.getCoinsPerUtxoWord() != null) {
            protocolParams.setCoinsPerUtxoWord(epochParams.getCoinsPerUtxoWord());
        }

        if (epochParams.getCoinsPerUtxoSize() != null) {
            protocolParams.setCoinsPerUtxoSize(epochParams.getCoinsPerUtxoSize());
        }

        return Result.success("OK").withValue(protocolParams).code(200);
    }

Please correct and if you have a temporary fix for this, please advise.

Thanks

satran004 commented 7 months ago

@amelongo

This is a known issue, due to a format change in the protocol parameters in one of the node release.

We are currently testing the next release, 0.5.1, which should be out very soon, in a week or two.

In the meantime, we have pushed a preview release, 0.5.1-preview1, which includes the latest koios-java-client (1.18.1). This should fix the above issue.

You may want to use 0.5.1-preview1 for both the cardano-client-lib core components and the koios backend service. Alternatively, you can just use the Koios backend service from the preview version (0.5.1-preview1). Both options should work.

       <dependency>
            <groupId>com.bloxbean.cardano</groupId>
            <artifactId>cardano-client-lib</artifactId>
            <version>0.5.0</version>
        </dependency>
        <dependency>
            <groupId>com.bloxbean.cardano</groupId>
            <artifactId>cardano-client-backend-koios</artifactId>
            <version>0.5.1-preview1</version>
        </dependency>
amelongo commented 7 months ago

Will do.

Thanks so much for the assistance.

amelongo commented 7 months ago

It works perfectly now.

Thanks for the assistance and good job on the work you put on developing this api