From e08b4bdd087994aac39b08d444e689297c17aa1f Mon Sep 17 00:00:00 2001 From: Dudi Edri Date: Mon, 2 Sep 2024 17:33:25 +0300 Subject: [PATCH] Koios Alignment with 1.2.0 Bump Version to 1.19.0 + Bugfixes #161, #167 --- README.md | 64 ++++++- pom.xml | 2 +- .../api/account/impl/AccountServiceImpl.java | 72 ++------ .../api/account/model/AccountInfo.java | 29 ++- .../api/address/impl/AddressServiceImpl.java | 87 +++------ .../backend/api/asset/AssetService.java | 2 +- .../api/asset/impl/AssetServiceImpl.java | 104 ++--------- .../client/backend/api/base/BaseService.java | 85 +++++---- .../api/block/impl/BlockServiceImpl.java | 48 +---- .../api/epoch/impl/EpochServiceImpl.java | 62 ++----- .../backend/api/epoch/model/EpochParams.java | 110 ++++++++++++ .../api/governance/GovernanceService.java | 165 ++++++++++++++++++ .../api/governance/api/GovernanceApi.java | 165 ++++++++++++++++++ .../impl/GovernanceServiceImpl.java | 123 +++++++++++++ .../api/governance/model/CommitteeInfo.java | 49 ++++++ .../api/governance/model/CommitteeMember.java | 51 ++++++ .../api/governance/model/CommitteeVote.java | 57 ++++++ .../backend/api/governance/model/DRep.java | 37 ++++ .../api/governance/model/DRepDelegator.java | 42 +++++ .../governance/model/DRepEpochSummary.java | 32 ++++ .../api/governance/model/DRepInfo.java | 67 +++++++ .../api/governance/model/DRepMetadata.java | 67 +++++++ .../api/governance/model/DRepUpdate.java | 73 ++++++++ .../api/governance/model/DRepVote.java | 57 ++++++ .../api/governance/model/PoolVote.java | 57 ++++++ .../api/governance/model/Proposal.java | 129 ++++++++++++++ .../api/governance/model/ProposalVote.java | 57 ++++++ .../model/ProposalVotingSummary.java | 109 ++++++++++++ .../api/network/impl/NetworkServiceImpl.java | 56 ++---- .../api/pool/impl/PoolServiceImpl.java | 109 ++---------- .../client/backend/api/pool/model/Pool.java | 5 + .../backend/api/pool/model/PoolInfo.java | 5 + .../backend/api/pool/model/PoolMetadata.java | 5 - .../backend/api/pool/model/PoolRelay.java | 5 - .../api/script/impl/ScriptServiceImpl.java | 53 +----- .../api/transactions/TransactionsService.java | 13 ++ .../api/transactions/api/TransactionApi.java | 10 ++ .../impl/TransactionsServiceImpl.java | 79 ++++----- .../transactions/model/ProposalProcedure.java | 72 ++++++++ .../backend/api/transactions/model/RawTx.java | 33 ++++ .../api/transactions/model/TxInfo.java | 21 ++- .../transactions/model/VotingProcedure.java | 52 ++++++ .../backend/factory/BackendService.java | 7 + .../factory/impl/BackendServiceImpl.java | 6 +- .../java/rest/koios/client/utils/HexUtil.java | 75 ++++++++ .../AssetServiceMainnetIntegrationTest.java | 59 ++++++- .../AssetServicePreprodIntegrationTest.java | 2 +- .../AssetServicePreviewIntegrationTest.java | 2 +- ...vernanceServiceMainnetIntegrationTest.java | 149 ++++++++++++++++ 49 files changed, 2223 insertions(+), 597 deletions(-) create mode 100644 src/main/java/rest/koios/client/backend/api/governance/GovernanceService.java create mode 100644 src/main/java/rest/koios/client/backend/api/governance/api/GovernanceApi.java create mode 100644 src/main/java/rest/koios/client/backend/api/governance/impl/GovernanceServiceImpl.java create mode 100644 src/main/java/rest/koios/client/backend/api/governance/model/CommitteeInfo.java create mode 100644 src/main/java/rest/koios/client/backend/api/governance/model/CommitteeMember.java create mode 100644 src/main/java/rest/koios/client/backend/api/governance/model/CommitteeVote.java create mode 100644 src/main/java/rest/koios/client/backend/api/governance/model/DRep.java create mode 100644 src/main/java/rest/koios/client/backend/api/governance/model/DRepDelegator.java create mode 100644 src/main/java/rest/koios/client/backend/api/governance/model/DRepEpochSummary.java create mode 100644 src/main/java/rest/koios/client/backend/api/governance/model/DRepInfo.java create mode 100644 src/main/java/rest/koios/client/backend/api/governance/model/DRepMetadata.java create mode 100644 src/main/java/rest/koios/client/backend/api/governance/model/DRepUpdate.java create mode 100644 src/main/java/rest/koios/client/backend/api/governance/model/DRepVote.java create mode 100644 src/main/java/rest/koios/client/backend/api/governance/model/PoolVote.java create mode 100644 src/main/java/rest/koios/client/backend/api/governance/model/Proposal.java create mode 100644 src/main/java/rest/koios/client/backend/api/governance/model/ProposalVote.java create mode 100644 src/main/java/rest/koios/client/backend/api/governance/model/ProposalVotingSummary.java create mode 100644 src/main/java/rest/koios/client/backend/api/transactions/model/ProposalProcedure.java create mode 100644 src/main/java/rest/koios/client/backend/api/transactions/model/RawTx.java create mode 100644 src/main/java/rest/koios/client/backend/api/transactions/model/VotingProcedure.java create mode 100644 src/main/java/rest/koios/client/utils/HexUtil.java create mode 100644 src/test/java/rest/koios/client/backend/api/governance/GovernanceServiceMainnetIntegrationTest.java diff --git a/README.md b/README.md index 7677c9e..748b754 100644 --- a/README.md +++ b/README.md @@ -260,6 +260,63 @@ Resource and maintenance requirements for Cardano blockchain components (e.g. ca Asset Transactions Get the list of all asset transaction hashes (newest first) + + Governance + DReps Epoch Summary + Summary of voting power and DRep count for each epoch + + + DReps List + List of all active delegated representatives (DReps) + + + DReps Info + Get detailed information about requested delegated representatives (DReps) + + + DReps Metadata + List metadata for requested delegated representatives (DReps) + + + DReps Updates + List of updates for requested (or all) delegated representatives (DReps) + + + DReps Votes + List of all votes casted by requested delegated representative (DRep) + + + DReps Delegators + List of all delegators to requested delegated representative (DRep). + + + Committee Information + Information about active committee and its members + + + Committee Votes + List of all votes casted by given committee member or collective + + + Proposals List + List of all governance proposals + + + Voter's Proposal List + List of all governance proposals for specified DRep, SPO or Committee credential + + + Proposal Voting Summary + Summary of votes for given proposal + + + Proposal Votes + List of all votes cast on specified governance action + + + Pool Votes + List of all votes casted by a pool + Pool Pool List @@ -343,7 +400,8 @@ Resource and maintenance requirements for Cardano blockchain components (e.g. ca | Koios Instance | Koios Java Client | |:--------------:|:-----------------:| -| 1.1.1 | 1.18.2 | +| 1.2.0 | 1.19.0 | +| 1.1.2 | 1.18.2 | | 1.0.10 | 1.17.3 | | 1.0.9 | 1.16.3 | | 1.0.8 | 1.15.2 | @@ -360,13 +418,13 @@ Resource and maintenance requirements for Cardano blockchain components (e.g. ca io.github.cardano-community koios-java-client - 1.18.2 + 1.18.3 ``` - For Gradle, add the following dependency to build.gradle ``` -compile group: 'io.github.cardano-community', name: 'koios-java-client', version: '1.18.2' +compile group: 'io.github.cardano-community', name: 'koios-java-client', version: '1.18.3' ``` ### Get Koios Backend Service (No API Token) diff --git a/pom.xml b/pom.xml index eef5f83..dd18048 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 io.github.cardano-community koios-java-client - 1.18.2 + 1.19.0 ${project.groupId}:${project.artifactId} Koios Java Client is a Java REST Client library which allows interacting with Koios Server Instances using Java Objects https://github.com/cardano-community/koios-java-client diff --git a/src/main/java/rest/koios/client/backend/api/account/impl/AccountServiceImpl.java b/src/main/java/rest/koios/client/backend/api/account/impl/AccountServiceImpl.java index e9bc75e..117c6d0 100644 --- a/src/main/java/rest/koios/client/backend/api/account/impl/AccountServiceImpl.java +++ b/src/main/java/rest/koios/client/backend/api/account/impl/AccountServiceImpl.java @@ -9,9 +9,7 @@ import rest.koios.client.backend.api.base.exception.ApiException; import rest.koios.client.backend.factory.options.Options; import retrofit2.Call; -import retrofit2.Response; -import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -37,12 +35,7 @@ public AccountServiceImpl(String baseUrl, String apiToken) { @Override public Result> getAccountList(Options options) throws ApiException { Call> call = accountApi.getAccountList(optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override @@ -51,12 +44,7 @@ public Result> getAccountInformation(List stakeAddress validateBech32(address); } Call> call = accountApi.getAccountInformation(buildBody("_stake_addresses", stakeAddresses, null, null, null), optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override @@ -65,12 +53,7 @@ public Result> getCachedAccountInformation(List stakeA validateBech32(address); } Call> call = accountApi.getCachedAccountInformation(buildBody("_stake_addresses", stakeAddresses, null, null, null), optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override @@ -79,12 +62,7 @@ public Result> getAccountUTxOs(List stakeAddresses, boolean e validateBech32(stakeAddress); } Call> call = accountApi.getAccountUTxOs(buildBodyUTxOs(stakeAddresses, extended), optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override @@ -97,12 +75,7 @@ public Result> getAccountTxs(String stakeAddress, Integer afterB throw new ApiException("Non Positive \"afterBlockHeight\" Value"); } Call> call = accountApi.getAccountTxs(stakeAddress, afterBlockHeight, optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override @@ -114,12 +87,7 @@ public Result> getAccountRewards(List addressList, validateEpoch(epochNo); } Call> call = accountApi.getAccountRewards(buildBody("_stake_addresses", addressList, epochNo, null, null), optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override @@ -128,12 +96,7 @@ public Result> getAccountUpdates(List addressList, validateBech32(address); } Call> call = accountApi.getAccountUpdates(buildBody("_stake_addresses", addressList, null, null, null), optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override @@ -142,12 +105,7 @@ public Result> getAccountAddresses(List addressList validateBech32(address); } Call> call = accountApi.getAccountAddresses(buildBody("_stake_addresses", addressList, null, firstOnly, empty), optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override @@ -159,12 +117,7 @@ public Result> getAccountAssets(List addressList, Int validateEpoch(epochNo); } Call> call = accountApi.getAccountAssets(buildBody("_stake_addresses", addressList, epochNo, null, null), optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override @@ -176,12 +129,7 @@ public Result> getAccountHistory(List addressList, validateEpoch(epochNo); } Call> call = accountApi.getAccountHistory(buildBody("_stake_addresses", addressList, epochNo, null, null), optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } private Map buildBody(String arrayObjString, List list, Integer epochNo, Boolean firstOnly, Boolean empty) { diff --git a/src/main/java/rest/koios/client/backend/api/account/model/AccountInfo.java b/src/main/java/rest/koios/client/backend/api/account/model/AccountInfo.java index a677acc..e08513e 100644 --- a/src/main/java/rest/koios/client/backend/api/account/model/AccountInfo.java +++ b/src/main/java/rest/koios/client/backend/api/account/model/AccountInfo.java @@ -20,47 +20,58 @@ public class AccountInfo { private String stakeAddress; /** - * Account Status + * Stake address status + * Allowed: registered | not registered */ private String status; /** - * Delegated Pool + * Account's current delegation status to DRep ID in CIP-129 Bech32 format + */ + private String delegatedDrep; + + /** + * Delegated Pool ID (bech32 format) */ private String delegatedPool; /** - * Account Balance + * Total balance of the account including UTxO, rewards and MIRs (in number) */ private String totalBalance; /** - * Utxo Balance + * Total UTxO balance of the account */ private String utxo; /** - * Rewards Balance + * Total rewards earned by the account */ private String rewards; /** - * Withdrawals Amount + * Total rewards withdrawn by the account */ private String withdrawals; /** - * Rewards Available Amount + * Total rewards available for withdrawal */ private String rewardsAvailable; /** - * Reserves Amount + * Total deposit available for withdrawal + */ + private String deposit; + + /** + * Total reserves MIR value of the account */ private String reserves; /** - * Treasury Amount + * Total treasury MIR value of the account */ private String treasury; } diff --git a/src/main/java/rest/koios/client/backend/api/address/impl/AddressServiceImpl.java b/src/main/java/rest/koios/client/backend/api/address/impl/AddressServiceImpl.java index 6ae3b77..59f0623 100644 --- a/src/main/java/rest/koios/client/backend/api/address/impl/AddressServiceImpl.java +++ b/src/main/java/rest/koios/client/backend/api/address/impl/AddressServiceImpl.java @@ -12,9 +12,7 @@ import rest.koios.client.backend.factory.options.Options; import rest.koios.client.backend.factory.options.SortType; import retrofit2.Call; -import retrofit2.Response; -import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -30,7 +28,7 @@ public class AddressServiceImpl extends BaseService implements AddressService { /** * Address Service Implementation Constructor * - * @param baseUrl Base Url + * @param baseUrl Base Url * @param apiToken Authorization Bearer JWT Token */ public AddressServiceImpl(String baseUrl, String apiToken) { @@ -42,16 +40,11 @@ public AddressServiceImpl(String baseUrl, String apiToken) { public Result getAddressInformation(String address) throws ApiException { validateBech32(address); Call> call = addressApi.getAddressInformation(buildBody("_addresses", List.of(address), null), optionsToParamMap(Options.EMPTY)); - try { - Response> response = (Response) execute(call); - Result result = processResponseGetOne(response); - if (result.isSuccessful()) { - result.getValue().setUtxoSet(new TreeSet<>(result.getValue().getUtxoSet())); - } - return result; - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); + Result result = processResponseGetOne(call); + if (result.isSuccessful()) { + result.getValue().setUtxoSet(new TreeSet<>(result.getValue().getUtxoSet())); } + return result; } @Override @@ -60,22 +53,17 @@ public Result> getAddressInformation(List addressList, validateBech32(address); } Call> call = addressApi.getAddressInformation(buildBody("_addresses", addressList, null), optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - Result> result = processResponse(response); - if (result.isSuccessful()) { - result.getValue().forEach(addressInfo -> { - if (utxoSortType == SortType.DESC) { - addressInfo.setUtxoSet(new TreeSet<>(addressInfo.getUtxoSet()).descendingSet()); - } else { - addressInfo.setUtxoSet(new TreeSet<>(addressInfo.getUtxoSet())); - } - }); - } - return result; - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + Result> result = processResponse(call); + if (result.isSuccessful()) { + result.getValue().forEach(addressInfo -> { + if (utxoSortType == SortType.DESC) { + addressInfo.setUtxoSet(new TreeSet<>(addressInfo.getUtxoSet()).descendingSet()); + } else { + addressInfo.setUtxoSet(new TreeSet<>(addressInfo.getUtxoSet())); + } + }); + } + return result; } @Override @@ -84,12 +72,7 @@ public Result> getAddressUTxOs(List addresses, boolean extend validateBech32(address); } Call> call = addressApi.getAddressUTxOs(buildBodyUTxOs(addresses, extended), optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override @@ -98,17 +81,12 @@ public Result> getUTxOsFromPaymentCredentials(List paymentCre validateHexFormat(address); } Call> call = addressApi.getUTxOsFromPaymentCredentials(buildBodyUTxOsFromPaymentCredentials(paymentCredentials, extended), optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override public Result> getAddressTransactions(List addressList, Options options) throws ApiException { - return getAddressTransactions(addressList,0,options); + return getAddressTransactions(addressList, 0, options); } @Override @@ -120,12 +98,7 @@ public Result> getAddressTransactions(List addressList, Int validateBech32(address); } Call> call = addressApi.getAddressTransactions(buildBody("_addresses", addressList, afterBlockHeight), optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override @@ -134,12 +107,7 @@ public Result> getAddressAssets(List addressList, Opt validateBech32(address); } Call> call = addressApi.getAddressAssets(buildBody("_addresses", addressList, null), optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override @@ -156,17 +124,12 @@ public Result> getTransactionsByPaymentCredentials(List pay validateHexFormat(paymentCredentials); } Call> call = addressApi.getTransactionsByPaymentCredentials(buildBody("_payment_credentials", paymentCredentialsList, afterBlockHeight), optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } - private Map buildBody(String arrayObjString, List list, Integer afterBlockHeight) { - Map bodyMap = new HashMap<>(); - bodyMap.put(arrayObjString,list); + private Map buildBody(String arrayObjString, List list, Integer afterBlockHeight) { + Map bodyMap = new HashMap<>(); + bodyMap.put(arrayObjString, list); if (afterBlockHeight != null) { bodyMap.put("_after_block_height", afterBlockHeight); } diff --git a/src/main/java/rest/koios/client/backend/api/asset/AssetService.java b/src/main/java/rest/koios/client/backend/api/asset/AssetService.java index 3f6126a..7ec4ccb 100644 --- a/src/main/java/rest/koios/client/backend/api/asset/AssetService.java +++ b/src/main/java/rest/koios/client/backend/api/asset/AssetService.java @@ -115,7 +115,7 @@ public interface AssetService { * @return Result of Type List of {@link AssetInformation} * @throws ApiException if an error occurs while attempting to invoke the API */ - Result getAssetInformationBulk(List> assetList, Options options) throws ApiException; + Result> getAssetInformationBulk(List> assetList, Options options) throws ApiException; /** * Asset UTxOs diff --git a/src/main/java/rest/koios/client/backend/api/asset/impl/AssetServiceImpl.java b/src/main/java/rest/koios/client/backend/api/asset/impl/AssetServiceImpl.java index 904f469..b27a6f1 100644 --- a/src/main/java/rest/koios/client/backend/api/asset/impl/AssetServiceImpl.java +++ b/src/main/java/rest/koios/client/backend/api/asset/impl/AssetServiceImpl.java @@ -11,9 +11,7 @@ import rest.koios.client.backend.factory.options.Options; import rest.koios.client.utils.Tuple; import retrofit2.Call; -import retrofit2.Response; -import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -29,7 +27,7 @@ public class AssetServiceImpl extends BaseService implements AssetService { /** * Asset Service Implementation Constructor * - * @param baseUrl Base Url + * @param baseUrl Base Url * @param apiToken Authorization Bearer JWT Token */ public AssetServiceImpl(String baseUrl, String apiToken) { @@ -40,23 +38,13 @@ public AssetServiceImpl(String baseUrl, String apiToken) { @Override public Result> getAssetList(Options options) throws ApiException { Call> call = assetApi.getAssetList(optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override public Result> getAssetTokenRegistry(Options options) throws ApiException { Call> call = assetApi.getAssetTokenRegistry(optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override @@ -64,12 +52,7 @@ public Result> getAssetsAddresses(String assetPolicy, String validateHexFormat(assetPolicy); validateHexFormat(assetName); Call> call = assetApi.getAssetsAddresses(assetPolicy, assetName, optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override @@ -77,24 +60,14 @@ public Result> getNFTAddress(String assetPolicy, String ass validateHexFormat(assetPolicy); validateHexFormat(assetName); Call> call = assetApi.getNFTAddress(assetPolicy, assetName, optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override public Result> getPolicyAssetAddressList(String assetPolicy, Options options) throws ApiException { validateHexFormat(assetPolicy); Call> call = assetApi.getPolicyAssetAddressList(assetPolicy, optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override @@ -102,16 +75,11 @@ public Result getAssetInformation(String assetPolicy, String a validateHexFormat(assetPolicy); validateHexFormat(assetName); Call> call = assetApi.getAssetInformation(assetPolicy, assetName); - try { - Response> response = (Response) execute(call); - return processResponseGetOne(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponseGetOne(call); } @Override - public Result getAssetInformationBulk(List> assetList, Options options) throws ApiException { + public Result> getAssetInformationBulk(List> assetList, Options options) throws ApiException { if (assetList == null) { return badRequestResult("The server cannot process the request due to invalid input"); } @@ -120,12 +88,7 @@ public Result getAssetInformationBulk(List> call = assetApi.getAssetInformationBulk(buildBody("_asset_list", assetList), optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponseGetOne(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override @@ -138,12 +101,7 @@ public Result> getAssetUTxOs(List> assetList, B validateHexFormat(tuple._2); } Call> call = assetApi.getAssetUTxOs(buildBodyUTxOs(assetList, extended), optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override @@ -151,48 +109,28 @@ public Result> getAssetHistory(String assetPolicy, String ass validateHexFormat(assetPolicy); validateHexFormat(assetName); Call> call = assetApi.getAssetHistory(assetPolicy, assetName, optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override public Result> getPolicyAssetInformation(String assetPolicy, Options options) throws ApiException { validateHexFormat(assetPolicy); Call> call = assetApi.getPolicyAssetInformation(assetPolicy, optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override public Result> getPolicyAssetMints(String assetPolicy, Options options) throws ApiException { validateHexFormat(assetPolicy); Call> call = assetApi.getPolicyAssetMints(assetPolicy, optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override public Result> getPolicyAssetList(String assetPolicy, Options options) throws ApiException { validateHexFormat(assetPolicy); Call> call = assetApi.getPolicyAssetList(assetPolicy, optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override @@ -200,12 +138,7 @@ public Result getAssetSummary(String assetPolicy, String assetName validateHexFormat(assetPolicy); validateHexFormat(assetName); Call> call = assetApi.getAssetSummary(assetPolicy, assetName); - try { - Response> response = (Response) execute(call); - return processResponseGetOne(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponseGetOne(call); } @Override @@ -218,12 +151,7 @@ public Result> getAssetTransactions(String assetPolicy, String asse validateHexFormat(assetPolicy); validateHexFormat(assetName); Call> call = assetApi.getAssetTransactionHistory(assetPolicy, assetName, afterBlockHeight, history, optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } private Map buildBody(String arrayObjString, List> list) { diff --git a/src/main/java/rest/koios/client/backend/api/base/BaseService.java b/src/main/java/rest/koios/client/backend/api/base/BaseService.java index 79aefd1..825e3a9 100644 --- a/src/main/java/rest/koios/client/backend/api/base/BaseService.java +++ b/src/main/java/rest/koios/client/backend/api/base/BaseService.java @@ -35,11 +35,11 @@ public class BaseService { private final Retrofit retrofit; private int retriesCount = 5; - private static final int SLEEP_TIME_MILLIS = 2000; private boolean retryOnTimeout = true; private final String apiToken; private int readTimeoutSec = 300; private int connectTimeoutSec = 300; + private int sleepTimeSec = 60; private boolean gzipCompression = true; /** @@ -54,7 +54,7 @@ public BaseService(String baseUrl) { /** * Base Service Constructor * - * @param baseUrl Base URL + * @param baseUrl Base URL * @param apiToken Authorization Bearer JWT Token */ public BaseService(String baseUrl, String apiToken) { @@ -93,7 +93,7 @@ public okhttp3.Response intercept(@NotNull Chain chain) throws IOException { Request original = chain.request(); Request request = original.newBuilder() - .header("Authorization", "Bearer "+apiToken) + .header("Authorization", "Bearer " + apiToken) .method(original.method(), original.body()) .build(); return chain.proceed(request); @@ -116,23 +116,33 @@ public okhttp3.Response intercept(@NotNull Chain chain) throws IOException { if (retryOnTimeoutEnv != null && !Boolean.parseBoolean(retryOnTimeoutEnv)) { retryOnTimeout = false; } + + String sleepTimeSecEnv = System.getenv("KOIOS_JAVA_LIB_RETRY_SLEEP_TIME_SEC"); + if (sleepTimeSecEnv != null && !sleepTimeSecEnv.isEmpty()) { + sleepTimeSec = Math.max(Integer.parseInt(sleepTimeSecEnv), 60); + } ObjectMapper objectMapper = new ObjectMapper(); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); retrofit = new Retrofit.Builder().baseUrl(baseUrl).client(okHttpClientBuilder.build()).addConverterFactory(JacksonConverterFactory .create(objectMapper)).build(); } - protected Result processResponseGetOne(Response> response) throws IOException { - if (response.isSuccessful()) { - if (response.body() != null && !response.body().isEmpty()) { - return (Result) Result.builder().successful(true).response(response.toString()).value(response.body().get(0)).code(response.code()).build(); - } else if (response.body() != null) { - return (Result) Result.builder().successful(false).response("Response Body is Empty").code(404).build(); + protected Result processResponseGetOne(Call> call) throws ApiException { + try { + Response> response = (Response>) execute(call); + if (response.isSuccessful()) { + if (response.body() != null && !response.body().isEmpty()) { + return (Result) Result.builder().successful(true).response(response.toString()).value(response.body().get(0)).code(response.code()).build(); + } else if (response.body() != null) { + return (Result) Result.builder().successful(false).response("Response Body is Empty").code(404).build(); + } else { + return (Result) Result.builder().successful(false).response("Response Body is Invalid").code(500).build(); + } } else { - return (Result) Result.builder().successful(false).response("Response Body is Invalid").code(500).build(); + return (Result) Result.builder().successful(false).response(Objects.requireNonNull(response.errorBody()).string()).code(response.code()).build(); } - } else { - return (Result) Result.builder().successful(false).response(Objects.requireNonNull(response.errorBody()).string()).code(response.code()).build(); + } catch (IOException e) { + throw new ApiException(e.getMessage(), e); } } @@ -143,16 +153,21 @@ protected Result badRequestResult(String responseText) { /** * processResponse * - * @param response the Response to process - * @param Type Of Response + * @param call the call to execute + * @param Type Of Response * @return Result of Response - * @throws IOException upon null Response Error Body + * @throws ApiException upon null Response Error Body */ - protected Result processResponse(Response response) throws IOException { - if (response.isSuccessful()) - return (Result) Result.builder().successful(true).response(response.toString()).value(response.body()).code(response.code()).build(); - else - return (Result) Result.builder().successful(false).response(Objects.requireNonNull(response.errorBody()).string()).code(response.code()).build(); + protected Result processResponse(Call call) throws ApiException { + try { + Response response = (Response) execute(call); + if (response.isSuccessful()) + return (Result) Result.builder().successful(true).response(response.toString()).value(response.body()).code(response.code()).build(); + else + return (Result) Result.builder().successful(false).response(Objects.requireNonNull(response.errorBody()).string()).code(response.code()).build(); + } catch (IOException e) { + throw new ApiException(e.getMessage(), e); + } } /** @@ -163,31 +178,35 @@ protected Result processResponse(Response response) throws IOException * @throws ApiException if an error occurs while attempting to invoke the API * @throws IOException if an error occurs while attempting to invoke the API */ - public Response execute(Call call) throws ApiException, IOException { + public Response execute(Call call) throws ApiException, IOException { int tryCount = 1; - while (tryCount <= retriesCount) { + Response response = null; + while (tryCount < retriesCount) { try { - Response response = (Response) call.clone().execute(); + response = call.clone().execute(); if (response.code() == 429) { log.warn("429 Too Many Requests."); - tryCount = retry(tryCount); + tryCount = retry(tryCount, response.code()); } else if (response.code() == 504) { log.warn(response.message()); - tryCount = retry(tryCount); + tryCount = retry(tryCount, response.code()); } else { return response; } } catch (SocketTimeoutException e) { log.warn(e.getMessage()); if (retryOnTimeout) { - tryCount = retry(tryCount); + tryCount = retry(tryCount, null); } else { throw new ApiException("Timeout Error"); } } } - throw new ApiException("Retry Count Exceeded (" + tryCount + "/" + retriesCount + ")."); - + if (response != null) { + throw new ApiException("Retry Count Exceeded (" + tryCount + "/" + retriesCount + "). Reason: " + response); + } else { + throw new ApiException("Retry Count Exceeded (" + tryCount + "/" + retriesCount + ")."); + } } private void sleep(int timeMillis) { @@ -198,11 +217,15 @@ private void sleep(int timeMillis) { } } - private int retry(int tryCount) { + private int retry(int tryCount, Integer responseCode) throws ApiException { tryCount++; if (tryCount < retriesCount) { - log.info("Retrying in {}s ... (" + tryCount + "/" + retriesCount + ")", SLEEP_TIME_MILLIS * tryCount / 1000); - sleep(SLEEP_TIME_MILLIS * tryCount); + log.info("Retrying in {}s ... (" + tryCount + "/" + retriesCount + ")", getSleepTimeSec() * tryCount); + sleep(getSleepTimeSec() * tryCount); + } else if (responseCode == null) { + throw new ApiException("Timeout Error"); + } else if (responseCode == 429) { + throw new ApiException("429 Too Many Requests."); } return tryCount; } diff --git a/src/main/java/rest/koios/client/backend/api/block/impl/BlockServiceImpl.java b/src/main/java/rest/koios/client/backend/api/block/impl/BlockServiceImpl.java index 9ad1d46..0287d87 100644 --- a/src/main/java/rest/koios/client/backend/api/block/impl/BlockServiceImpl.java +++ b/src/main/java/rest/koios/client/backend/api/block/impl/BlockServiceImpl.java @@ -3,8 +3,8 @@ import rest.koios.client.backend.api.base.BaseService; import rest.koios.client.backend.api.base.Result; import rest.koios.client.backend.api.base.exception.ApiException; -import rest.koios.client.backend.api.block.api.BlockApi; import rest.koios.client.backend.api.block.BlockService; +import rest.koios.client.backend.api.block.api.BlockApi; import rest.koios.client.backend.api.block.model.Block; import rest.koios.client.backend.api.block.model.BlockInfo; import rest.koios.client.backend.api.block.model.BlockTxHash; @@ -12,9 +12,7 @@ import rest.koios.client.backend.factory.options.Limit; import rest.koios.client.backend.factory.options.Options; import retrofit2.Call; -import retrofit2.Response; -import java.io.IOException; import java.util.*; /** @@ -27,7 +25,7 @@ public class BlockServiceImpl extends BaseService implements BlockService { /** * Block Service Implementation Constructor * - * @param baseUrl Base Url + * @param baseUrl Base Url * @param apiToken Authorization Bearer JWT Token */ public BlockServiceImpl(String baseUrl, String apiToken) { @@ -39,35 +37,20 @@ public BlockServiceImpl(String baseUrl, String apiToken) { public Result getLatestBlock() throws ApiException { Options options = Options.builder().option(Limit.of(1)).build(); Call> call = blockApi.getBlockList(optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponseGetOne(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponseGetOne(call); } @Override public Result> getBlockList(Options options) throws ApiException { Call> call = blockApi.getBlockList(optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override public Result getBlockInformation(String blockHash) throws ApiException { validateHexFormat(blockHash); Call> call = blockApi.getBlockInformation(buildBody(List.of(blockHash)), Collections.emptyMap()); - try { - Response> response = (Response) execute(call); - return processResponseGetOne(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponseGetOne(call); } @Override @@ -76,12 +59,7 @@ public Result> getBlocksInformation(List blockHashes, Op validateHexFormat(blockHash); } Call> call = blockApi.getBlockInformation(buildBody(blockHashes), optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override @@ -90,12 +68,7 @@ public Result> getBlockTransactions(List blockHashes, validateHexFormat(blockHash); } Call> call = blockApi.getBlockTransactions(buildBody(blockHashes), optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override @@ -104,12 +77,7 @@ public Result> getBlockTransactionsInfo(List blockHashes, B validateHexFormat(blockHash); } Call> call = blockApi.getBlockTransactionsInfo(buildBodyBlockTxInfo(blockHashes, inputs, metadata, assets, withdrawals, certs, scripts), optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } private Map buildBodyBlockTxInfo(List blockHashes, Boolean inputs, Boolean metadata, Boolean assets, Boolean withdrawals, Boolean certs, Boolean scripts) { diff --git a/src/main/java/rest/koios/client/backend/api/epoch/impl/EpochServiceImpl.java b/src/main/java/rest/koios/client/backend/api/epoch/impl/EpochServiceImpl.java index 9bc04e0..8448966 100644 --- a/src/main/java/rest/koios/client/backend/api/epoch/impl/EpochServiceImpl.java +++ b/src/main/java/rest/koios/client/backend/api/epoch/impl/EpochServiceImpl.java @@ -4,16 +4,14 @@ import rest.koios.client.backend.api.base.Result; import rest.koios.client.backend.api.base.exception.ApiException; import rest.koios.client.backend.api.epoch.EpochService; +import rest.koios.client.backend.api.epoch.api.EpochApi; import rest.koios.client.backend.api.epoch.model.EpochBlockProtocols; import rest.koios.client.backend.api.epoch.model.EpochInfo; import rest.koios.client.backend.api.epoch.model.EpochParams; -import rest.koios.client.backend.api.epoch.api.EpochApi; import rest.koios.client.backend.factory.options.Limit; import rest.koios.client.backend.factory.options.Options; import retrofit2.Call; -import retrofit2.Response; -import java.io.IOException; import java.util.Collections; import java.util.List; @@ -27,7 +25,7 @@ public class EpochServiceImpl extends BaseService implements EpochService { /** * Epoch Service Implementation Constructor * - * @param baseUrl Base Url + * @param baseUrl Base Url * @param apiToken Authorization Bearer JWT Token */ public EpochServiceImpl(String baseUrl, String apiToken) { @@ -39,92 +37,52 @@ public EpochServiceImpl(String baseUrl, String apiToken) { public Result getLatestEpochInfo() throws ApiException { Options options = Options.builder().option(Limit.of(1)).build(); Call> call = epochApi.getEpochInformation(null, false, optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponseGetOne(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponseGetOne(call); } @Override public Result getEpochInformationByEpoch(Integer epochNo) throws ApiException { validateEpoch(epochNo); Call> call = epochApi.getEpochInformation(epochNo, false, Collections.emptyMap()); - try { - Response> response = (Response) execute(call); - return processResponseGetOne(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponseGetOne(call); } @Override public Result> getEpochInformation(boolean includeNextEpoch, Options options) throws ApiException { Call> call = epochApi.getEpochInformation(null, includeNextEpoch, optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override public Result getLatestEpochParameters() throws ApiException { Options options = Options.builder().option(Limit.of(1)).build(); Call> call = epochApi.getEpochParameters(optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponseGetOne(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponseGetOne(call); } @Override public Result getEpochParametersByEpoch(Integer epochNo) throws ApiException { validateEpoch(epochNo); Call> call = epochApi.getEpochParametersByEpoch(epochNo); - try { - Response> response = (Response) execute(call); - return processResponseGetOne(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponseGetOne(call); } @Override public Result> getEpochParameters(Options options) throws ApiException { Call> call = epochApi.getEpochParameters(optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override public Result getEpochBlockProtocolsByEpoch(Integer epochNo) throws ApiException { validateEpoch(epochNo); Call> call = epochApi.getEpochBlockProtocolsByEpoch(epochNo); - try { - Response> response = (Response) execute(call); - return processResponseGetOne(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponseGetOne(call); } @Override public Result> getEpochBlockProtocols(Options options) throws ApiException { Call> call = epochApi.getEpochBlockProtocols(optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } } diff --git a/src/main/java/rest/koios/client/backend/api/epoch/model/EpochParams.java b/src/main/java/rest/koios/client/backend/api/epoch/model/EpochParams.java index 28389c0..7c872a2 100644 --- a/src/main/java/rest/koios/client/backend/api/epoch/model/EpochParams.java +++ b/src/main/java/rest/koios/client/backend/api/epoch/model/EpochParams.java @@ -179,4 +179,114 @@ public class EpochParams { * The cost per UTxO size */ private String coinsPerUtxoSize = null; + + /** + * Pool Voting threshold for motion of no-confidence. + */ + private BigDecimal pvtMotionNoConfidence = null; + + /** + * Pool Voting threshold for new committee/threshold (normal state). + */ + private BigDecimal pvtCommitteeNormal = null; + + /** + * Pool Voting threshold for new committee/threshold (state of no-confidence). + */ + private BigDecimal pvtCommitteeNoConfidence = null; + + /** + * Pool Voting threshold for hard-fork initiation. + */ + private BigDecimal pvtHardForkInitiation = null; + + /** + * DRep Vote threshold for motion of no-confidence. + */ + private BigDecimal dvtMotionNoConfidence = null; + + /** + * DRep Vote threshold for new committee/threshold (normal state). + */ + private BigDecimal dvtCommitteeNormal = null; + + /** + * DRep Vote threshold for new committee/threshold (state of no-confidence). + */ + private BigDecimal dvtCommitteeNoConfidence = null; + + /** + * DRep Vote threshold for update to the Constitution. + */ + private BigDecimal dvtUpdateToConstitution = null; + + /** + * DRep Vote threshold for hard-fork initiation. + */ + private BigDecimal dvtHardForkInitiation = null; + + /** + * DRep Vote threshold for protocol parameter changes, network group. + */ + private BigDecimal dvtPPNetworkGroup = null; + + /** + * DRep Vote threshold for protocol parameter changes, economic group. + */ + private BigDecimal dvtPPEconomicGroup = null; + + /** + * DRep Vote threshold for protocol parameter changes, technical group. + */ + private BigDecimal dvtPPTechnicalGroup = null; + + /** + * DRep Vote threshold for protocol parameter changes, governance group. + */ + private BigDecimal dvtPPGovGroup = null; + + /** + * DRep Vote threshold for treasury withdrawal. + */ + private BigDecimal dvtTreasuryWithdrawal = null; + + /** + * Minimal constitutional committee size. + */ + private Integer committeeMinSize = null; + + /** + * Constitutional committee term limits. + */ + private Integer committeeMaxTermLength = null; + + /** + * Governance action expiration. + */ + private Integer govActionLifetime = null; + + /** + * Governance action deposit. + */ + private String govActionDeposit = null; + + /** + * DRep deposit amount. + */ + private String drepDeposit = null; + + /** + * DRep activity period. + */ + private Integer drepActivity = null; + + /** + * Pool Voting threshold for protocol parameter changes, security group. + */ + private BigDecimal pvtppSecurityGroup = null; + + /** + * Minimum Fee for Reference Script cost per byte. + */ + private BigDecimal minFeeRefScriptCostPerByte = null; } diff --git a/src/main/java/rest/koios/client/backend/api/governance/GovernanceService.java b/src/main/java/rest/koios/client/backend/api/governance/GovernanceService.java new file mode 100644 index 0000000..10f8af3 --- /dev/null +++ b/src/main/java/rest/koios/client/backend/api/governance/GovernanceService.java @@ -0,0 +1,165 @@ +package rest.koios.client.backend.api.governance; + +import rest.koios.client.backend.api.base.Result; +import rest.koios.client.backend.api.base.exception.ApiException; +import rest.koios.client.backend.api.governance.model.*; +import rest.koios.client.backend.factory.options.Options; + +import java.util.List; + +/** + * Governance Service + */ +public interface GovernanceService { + + /** + * DReps Epoch Summary + * Summary of voting power and DRep count for each epoch + * + * @param epochNo Epoch Number to fetch details for + * @param options Filtering Options (optional) + * @return Summary of voting power and DRep count for each epoch + * @throws ApiException if an error occurs while attempting to invoke the API + */ + Result> getDRepsEpochSummary(Integer epochNo, Options options) throws ApiException; + + /** + * DReps List + * List of all active delegated representatives (DReps) + * + * @param options Filtering Options (optional) + * @return List of all active delegated representatives (DReps) + * @throws ApiException if an error occurs while attempting to invoke the API + */ + Result> getDRepsList(Options options) throws ApiException; + + /** + * DReps Info + * Get detailed information about requested delegated representatives (DReps) + * + * @param drepIds List of DRep Ids + * @param options Filtering Options (optional) + * @return Detailed information about requested delegated representatives (DReps) + * @throws ApiException if an error occurs while attempting to invoke the API + */ + Result> getDRepsInfo(List drepIds, Options options) throws ApiException; + + /** + * DReps Metadata + * List metadata for requested delegated representatives (DReps) + * + * @param drepIds List of DRep Ids + * @param options Filtering Options (optional) + * @return Metadata for requested delegated representatives (DReps) + * @throws ApiException if an error occurs while attempting to invoke the API + */ + Result> getDRepsMetadata(List drepIds, Options options) throws ApiException; + + /** + * DReps Updates + * List of updates for requested (or all) delegated representatives (DReps) + * + * @param drepId DRep ID in bech32 format + * @param options Filtering Options (optional) + * @return List of updates for requested (or all) delegated representatives (DReps) + * @throws ApiException if an error occurs while attempting to invoke the API + */ + Result> getDRepsUpdates(String drepId, Options options) throws ApiException; + + /** + * DReps Votes + * List of all votes casted by requested delegated representative (DRep) + * + * @param drepId DRep ID in bech32 format + * @param options Filtering Options (optional) + * @return List of all votes casted by requested delegated representative (DRep) + * @throws ApiException if an error occurs while attempting to invoke the API + */ + Result> getDRepsVotes(String drepId, Options options) throws ApiException; + + /** + * DReps Delegators + * List of all delegators to requested delegated representative (DRep) + * + * @param drepId DRep ID in bech32 format + * @param options Filtering Options (optional) + * @return List of all delegators to requested delegated representative (DRep) + * @throws ApiException if an error occurs while attempting to invoke the API + */ + Result> getDRepsDelegators(String drepId, Options options) throws ApiException; + + /** + * Committee Information + * Information about active committee and its members + * + * @param options Filtering Options (optional) + * @return Current governance committee information + * @throws ApiException if an error occurs while attempting to invoke the API + */ + Result> getCommitteeInformation(Options options) throws ApiException; + + /** + * Committee Votes + * List of all votes casted by a given committee member or collective + * + * @param ccHotId Committee member hot key ID in Bech32 format (CIP-5 | CIP-129) + * @param options Filtering Options (optional) + * @return List of all votes casted by a given committee member or collective + * @throws ApiException if an error occurs while attempting to invoke the API + */ + Result> getCommitteeVotes(String ccHotId, Options options) throws ApiException; + + /** + * Proposals List + * List of all governance proposals + * + * @param options Filtering Options (optional) + * @return List of all governance action proposals + * @throws ApiException if an error occurs while attempting to invoke the API + */ + Result> getProposalList(Options options) throws ApiException; + + /** + * Voter's Proposal List + * List of all governance proposals for specified DRep, SPO or Committee credential + * + * @param voterId Voter ID (DRep, SPO, Committee Member) in Bech32 format (CIP-5 | CIP-129) + * @param options Filtering Options (optional) + * @return List of all governance action proposals for the specified voter + * @throws ApiException if an error occurs while attempting to invoke the API + */ + Result> getVoterProposals(String voterId, Options options) throws ApiException; + + /** + * Proposal Voting Summary + * Summary of votes for a given proposal + * + * @param proposalId Government proposal ID in CIP-129 Bech32 format + * @param options Filtering Options (optional) + * @return Summary of votes for the given proposal + * @throws ApiException if an error occurs while attempting to invoke the API + */ + Result> getProposalVotingSummary(String proposalId, Options options) throws ApiException; + + /** + * Proposal Votes + * List of all votes cast on a specified governance action + * + * @param proposalId Government proposal ID in CIP-129 Bech32 format + * @param options Filtering Options (optional) + * @return List of all votes cast on the specified governance action + * @throws ApiException if an error occurs while attempting to invoke the API + */ + Result> getProposalVotes(String proposalId, Options options) throws ApiException; + + /** + * Pool Votes + * List of all votes casted by a pool + * + * @param poolBech32 Pool ID in bech32 format + * @param options Filtering Options (optional) + * @return List of all votes casted by the requested pool + * @throws ApiException if an error occurs while attempting to invoke the API + */ + Result> getPoolVotes(String poolBech32, Options options) throws ApiException; +} diff --git a/src/main/java/rest/koios/client/backend/api/governance/api/GovernanceApi.java b/src/main/java/rest/koios/client/backend/api/governance/api/GovernanceApi.java new file mode 100644 index 0000000..2bc7255 --- /dev/null +++ b/src/main/java/rest/koios/client/backend/api/governance/api/GovernanceApi.java @@ -0,0 +1,165 @@ +package rest.koios.client.backend.api.governance.api; + +import rest.koios.client.backend.api.governance.model.*; +import retrofit2.Call; +import retrofit2.http.*; + +import java.util.List; +import java.util.Map; + +/** + * Governance API + */ +public interface GovernanceApi { + + /** + * DReps Epoch Summary + * Summary of voting power and DRep count for each epoch + * + * @param epochNo Epoch Number to fetch details for + * @param paramsMap Filtering Options Query Parameters + * @return Summary of voting power and DRep count for each epoch + */ + @GET("drep_epoch_summary") + Call> getDRepsEpochSummary(@Query("_epoch_no") Integer epochNo, @QueryMap Map paramsMap); + + /** + * DReps List + * List of all active delegated representatives (DReps) + * + * @param paramsMap Filtering Options Query Parameters + * @return List of all active delegated representatives (DReps) + */ + @GET("drep_list") + Call> getDRepsList(@QueryMap Map paramsMap); + + /** + * DReps Info + * Get detailed information about requested delegated representatives (DReps) + * + * @param requestBody Array of DRep Ids + * @param paramsMap Filtering Options Query Parameters + * @return Get detailed information about requested delegated representatives (DReps) + */ + @POST("drep_info") + Call> getDRepsInfo(@Body Map requestBody, @QueryMap Map paramsMap); + + /** + * DReps Metadata + * List metadata for requested delegated representatives (DReps) + * + * @param requestBody Array of DRep Ids + * @param paramsMap Filtering Options Query Parameters + * @return List metadata for requested delegated representatives (DReps) + */ + @POST("drep_metadata") + Call> getDRepsMetadata(@Body Map requestBody, @QueryMap Map paramsMap); + + /** + * DReps Updates + * List of updates for requested (or all) delegated representatives (DReps) + * + * @param drepId DRep ID in bech32 format + * @param paramsMap Filtering Options Query Parameters + * @return List of updates for requested (or all) delegated representatives (DReps) + */ + @GET("drep_updates") + Call> getDRepsUpdates(@Query("_drep_id") String drepId, @QueryMap Map paramsMap); + + /** + * DReps Votes + * List of all votes casted by requested delegated representative (DRep) + * + * @param drepId DRep ID in bech32 format + * @param paramsMap Filtering Options Query Parameters + * @return List of all votes casted by requested delegated representative (DRep) + */ + @GET("drep_votes") + Call> getDRepsVotes(@Query("_drep_id") String drepId, @QueryMap Map paramsMap); + + /** + * DReps Delegators + * List of all delegators to requested delegated representative (DRep). + * + * @param drepId DRep ID in bech32 format + * @param paramsMap Filtering Options Query Parameters + * @return List of all delegators to requested delegated representative (DRep). + */ + @GET("drep_delegators") + Call> getDRepsDelegators(@Query("_drep_id") String drepId, @QueryMap Map paramsMap); + + /** + * Committee Information + * Information about active committee and its members + * + * @param paramsMap Filtering Options Query Parameters + * @return Current governance committee + */ + @GET("committee_info") + Call> getCommitteeInformation(@QueryMap Map paramsMap); + + /** + * Committee Votes + * List of all votes casted by given committee member or collective + * + * @param ccHotId Committee member hot key ID in Bech32 format (CIP-5 | CIP-129) + * @param paramsMap Filtering Options Query Parameters + * @return List of all votes casted by requested delegated representative (DRep) + */ + @GET("committee_votes") + Call> getCommitteeVotes(@Query("_cc_hot_id") String ccHotId, @QueryMap Map paramsMap); + + /** + * Proposals List + * List of all governance proposals + * + * @param paramsMap Filtering Options Query Parameters + * @return List of all governance action proposals + */ + @GET("proposal_list") + Call> getProposalList(@QueryMap Map paramsMap); + + /** + * Voter's Proposal List + * List of all governance proposals for specified DRep, SPO or Committee credential + * + * @param voterId Voter ID (Drep, SPO, Committee Member) in Bech32 format (CIP-5 | CIP-129) + * @param paramsMap Filtering Options Query Parameters + * @return List of all governance action proposals + */ + @GET("voter_proposal_list") + Call> getVoterProposal(@Query("_voter_id") String voterId, @QueryMap Map paramsMap); + + /** + * Proposal Voting Summary + * Summary of votes for given proposal + * + * @param proposalId Government proposal ID in CIP-129 Bech32 format + * @param paramsMap Filtering Options Query Parameters + * @return Summary of votes for given proposal + */ + @GET("proposal_voting_summary") + Call> getProposalVotingSummary(@Query("_proposal_id") String proposalId, @QueryMap Map paramsMap); + + /** + * Proposal Votes + * List of all votes cast on specified governance action + * + * @param proposalId Government proposal ID in CIP-129 Bech32 format + * @param paramsMap Filtering Options Query Parameters + * @return List of all votes cast on specified governance action + */ + @GET("proposal_votes") + Call> getProposalVotes(@Query("_proposal_id") String proposalId, @QueryMap Map paramsMap); + + /** + * Pool Votes + * List of all votes casted by a pool + * + * @param poolBech32 Pool ID in bech32 format + * @param paramsMap Filtering Options Query Parameters + * @return List of all votes casted by requested pool + */ + @GET("pool_votes") + Call> getPoolVotes(@Query("_pool_bech32") String poolBech32, @QueryMap Map paramsMap); +} diff --git a/src/main/java/rest/koios/client/backend/api/governance/impl/GovernanceServiceImpl.java b/src/main/java/rest/koios/client/backend/api/governance/impl/GovernanceServiceImpl.java new file mode 100644 index 0000000..f3ebcd3 --- /dev/null +++ b/src/main/java/rest/koios/client/backend/api/governance/impl/GovernanceServiceImpl.java @@ -0,0 +1,123 @@ +package rest.koios.client.backend.api.governance.impl; + +import rest.koios.client.backend.api.base.BaseService; +import rest.koios.client.backend.api.base.Result; +import rest.koios.client.backend.api.base.exception.ApiException; +import rest.koios.client.backend.api.governance.GovernanceService; +import rest.koios.client.backend.api.governance.api.GovernanceApi; +import rest.koios.client.backend.api.governance.model.*; +import rest.koios.client.backend.factory.options.Options; +import retrofit2.Call; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Governance Service Implementation + */ +public class GovernanceServiceImpl extends BaseService implements GovernanceService { + + private final GovernanceApi governanceApi; + + /** + * Governance Service Implementation Constructor + * + * @param baseUrl Base Url + * @param apiToken Authorization Bearer JWT Token + */ + public GovernanceServiceImpl(String baseUrl, String apiToken) { + super(baseUrl, apiToken); + governanceApi = getRetrofit().create(GovernanceApi.class); + } + + @Override + public Result> getDRepsEpochSummary(Integer epochNo, Options options) throws ApiException { + Call> call = governanceApi.getDRepsEpochSummary(epochNo, optionsToParamMap(options)); + return processResponse(call); + } + + @Override + public Result> getDRepsList(Options options) throws ApiException { + Call> call = governanceApi.getDRepsList(optionsToParamMap(options)); + return processResponse(call); + } + + @Override + public Result> getDRepsInfo(List drepIds, Options options) throws ApiException { + Call> call = governanceApi.getDRepsInfo(buildBody(drepIds), optionsToParamMap(options)); + return processResponse(call); + } + + @Override + public Result> getDRepsMetadata(List drepIds, Options options) throws ApiException { + Call> call = governanceApi.getDRepsMetadata(buildBody(drepIds), optionsToParamMap(options)); + return processResponse(call); + } + + @Override + public Result> getDRepsUpdates(String drepId, Options options) throws ApiException { + Call> call = governanceApi.getDRepsUpdates(drepId, optionsToParamMap(options)); + return processResponse(call); + } + + @Override + public Result> getDRepsVotes(String drepId, Options options) throws ApiException { + Call> call = governanceApi.getDRepsVotes(drepId, optionsToParamMap(options)); + return processResponse(call); + } + + @Override + public Result> getDRepsDelegators(String drepId, Options options) throws ApiException { + Call> call = governanceApi.getDRepsDelegators(drepId, optionsToParamMap(options)); + return processResponse(call); + } + + @Override + public Result> getCommitteeInformation(Options options) throws ApiException { + Call> call = governanceApi.getCommitteeInformation(optionsToParamMap(options)); + return processResponse(call); + } + + @Override + public Result> getCommitteeVotes(String ccHotId, Options options) throws ApiException { + Call> call = governanceApi.getCommitteeVotes(ccHotId, optionsToParamMap(options)); + return processResponse(call); + } + + @Override + public Result> getProposalList(Options options) throws ApiException { + Call> call = governanceApi.getProposalList(optionsToParamMap(options)); + return processResponse(call); + } + + @Override + public Result> getVoterProposals(String voterId, Options options) throws ApiException { + Call> call = governanceApi.getVoterProposal(voterId, optionsToParamMap(options)); + return processResponse(call); + } + + @Override + public Result> getProposalVotingSummary(String proposalId, Options options) throws ApiException { + Call> call = governanceApi.getProposalVotingSummary(proposalId, optionsToParamMap(options)); + return processResponse(call); + } + + @Override + public Result> getProposalVotes(String proposalId, Options options) throws ApiException { + Call> call = governanceApi.getProposalVotes(proposalId, optionsToParamMap(options)); + return processResponse(call); + } + + @Override + public Result> getPoolVotes(String poolBech32, Options options) throws ApiException { + Call> call = governanceApi.getPoolVotes(poolBech32, optionsToParamMap(options)); + return processResponse(call); + } + + private Map buildBody(List txHashes) { + Map bodyMap = new HashMap<>(); + bodyMap.put("_drep_ids", txHashes); + return bodyMap; + } +} diff --git a/src/main/java/rest/koios/client/backend/api/governance/model/CommitteeInfo.java b/src/main/java/rest/koios/client/backend/api/governance/model/CommitteeInfo.java new file mode 100644 index 0000000..7b75e59 --- /dev/null +++ b/src/main/java/rest/koios/client/backend/api/governance/model/CommitteeInfo.java @@ -0,0 +1,49 @@ +package rest.koios.client.backend.api.governance.model; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import lombok.*; + +import java.util.List; + +/** + * Committee Info + */ +@Getter +@Setter +@ToString +@NoArgsConstructor +@EqualsAndHashCode +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class CommitteeInfo { + + /** + * Proposal Action ID in accordance with CIP-129 format + */ + private String proposalId; + + /** + * Hash identifier of the transaction + */ + private String proposalTxHash; + + /** + * Index of governance proposal in transaction + */ + private Integer proposalIndex; + + /** + * Quorum numerator for governance proposal + */ + private Integer quorumNumerator; + + /** + * Quorum denominator for governance proposal + */ + private Integer quorumDenominator; + + /** + * Array of all members part of active governance committee + */ + private List members; +} diff --git a/src/main/java/rest/koios/client/backend/api/governance/model/CommitteeMember.java b/src/main/java/rest/koios/client/backend/api/governance/model/CommitteeMember.java new file mode 100644 index 0000000..6fe75da --- /dev/null +++ b/src/main/java/rest/koios/client/backend/api/governance/model/CommitteeMember.java @@ -0,0 +1,51 @@ +package rest.koios.client.backend.api.governance.model; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import lombok.*; + +/** + * Committee Member + */ +@Getter +@Setter +@ToString +@NoArgsConstructor +@EqualsAndHashCode +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class CommitteeMember { + + /** + * Member authentication status (authorized, not_authorized, resigned) + */ + private String status; + + private String ccHotd; + + private String ccColdId; + + /** + * Committee member key hash from last valid hot key authorization certificate in hex format (null if not applicable) + */ + private String ccHotHex; + + /** + * Committee member cold key hash in hex format + */ + private String ccColdHex; + + /** + * Epoch number in which the committee member vote rights expire + */ + private Integer expirationEpoch; + + /** + * Flag which shows if this credential is a script hash (null if not applicable) + */ + private Boolean ccHotHasScript; + + /** + * Flag which shows if this credential is a script hash + */ + private Boolean ccColdHasScript; +} \ No newline at end of file diff --git a/src/main/java/rest/koios/client/backend/api/governance/model/CommitteeVote.java b/src/main/java/rest/koios/client/backend/api/governance/model/CommitteeVote.java new file mode 100644 index 0000000..2e34c8c --- /dev/null +++ b/src/main/java/rest/koios/client/backend/api/governance/model/CommitteeVote.java @@ -0,0 +1,57 @@ +package rest.koios.client.backend.api.governance.model; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import lombok.*; + +/** + * Committee Vote + */ +@Getter +@Setter +@ToString +@NoArgsConstructor +@EqualsAndHashCode +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class CommitteeVote { + + /** + * Proposal Action ID in accordance with CIP-129 format + */ + private String proposalId; + + /** + * Hash identifier of the proposal transaction + */ + private String proposalTxHash; + + /** + * Index of governance proposal in transaction + */ + private Integer proposalIndex; + + /** + * Hash identifier of the vote transaction + */ + private String voteTxHash; + + /** + * UNIX timestamp of the block + */ + private Long blockTime; + + /** + * Actual Vote casted (Yes, No, Abstain) + */ + private String vote; + + /** + * A URL to a JSON payload of metadata (null if not applicable) + */ + private String metaUrl; + + /** + * A hash of the contents of the metadata URL (null if not applicable) + */ + private String metaHash; +} diff --git a/src/main/java/rest/koios/client/backend/api/governance/model/DRep.java b/src/main/java/rest/koios/client/backend/api/governance/model/DRep.java new file mode 100644 index 0000000..5812094 --- /dev/null +++ b/src/main/java/rest/koios/client/backend/api/governance/model/DRep.java @@ -0,0 +1,37 @@ +package rest.koios.client.backend.api.governance.model; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import lombok.*; + +/** + * DRep + */ +@Getter +@Setter +@ToString +@NoArgsConstructor +@EqualsAndHashCode +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class DRep { + + /** + * DRep ID in CIP-129 bech32 format + */ + private String drepId; + + /** + * DRep ID in hex format + */ + private String hex; + + /** + * Flag which shows if this credential is a script hash + */ + private Boolean hasScript; + + /** + * Flag to show if the DRep is currently registered + */ + private Boolean registered; +} diff --git a/src/main/java/rest/koios/client/backend/api/governance/model/DRepDelegator.java b/src/main/java/rest/koios/client/backend/api/governance/model/DRepDelegator.java new file mode 100644 index 0000000..9a88d23 --- /dev/null +++ b/src/main/java/rest/koios/client/backend/api/governance/model/DRepDelegator.java @@ -0,0 +1,42 @@ +package rest.koios.client.backend.api.governance.model; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import lombok.*; + +/** + * DRep Delegator + */ +@Getter +@Setter +@ToString +@NoArgsConstructor +@EqualsAndHashCode +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class DRepDelegator { + + /** + * Cardano staking address (reward account) in bech32 format + */ + private String stakeAddress; + + /** + * Cardano staking address (reward account) in hex format + */ + private String stakeAddressHex; + + /** + * Script hash in case the stake address is locked by a script (null if not applicable) + */ + private String scriptHash; + + /** + * Epoch when vote delegation was made + */ + private Integer epochNo; + + /** + * Total balance of the account including UTxO, rewards, and MIRs (in number) + */ + private String amount; +} diff --git a/src/main/java/rest/koios/client/backend/api/governance/model/DRepEpochSummary.java b/src/main/java/rest/koios/client/backend/api/governance/model/DRepEpochSummary.java new file mode 100644 index 0000000..a33eba6 --- /dev/null +++ b/src/main/java/rest/koios/client/backend/api/governance/model/DRepEpochSummary.java @@ -0,0 +1,32 @@ +package rest.koios.client.backend.api.governance.model; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import lombok.*; + +/** + * DRep Epoch Summary + */ +@Getter +@Setter +@ToString +@NoArgsConstructor +@EqualsAndHashCode +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class DRepEpochSummary { + + /** + * Epoch number of the block + */ + private Integer epochNo; + + /** + * The total amount of voting power between all DReps including pre-defined roles for the epoch + */ + private String amount; + + /** + * The total number of DReps with vote power for the epoch + */ + private Integer dreps; +} diff --git a/src/main/java/rest/koios/client/backend/api/governance/model/DRepInfo.java b/src/main/java/rest/koios/client/backend/api/governance/model/DRepInfo.java new file mode 100644 index 0000000..a1a2d4e --- /dev/null +++ b/src/main/java/rest/koios/client/backend/api/governance/model/DRepInfo.java @@ -0,0 +1,67 @@ +package rest.koios.client.backend.api.governance.model; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import lombok.*; + +/** + * DRep Information + */ +@Getter +@Setter +@ToString +@NoArgsConstructor +@EqualsAndHashCode +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class DRepInfo { + + /** + * DRep ID in CIP-129 bech32 format + */ + private String drepId; + + /** + * DRep ID in hex format + */ + private String hex; + + /** + * Flag which shows if this credential is a script hash + */ + private Boolean hasScript; + + /** + * Flag to show if the DRep is currently registered + */ + private Boolean registered; + + /** + * DRep's registration deposit in number (null if not applicable) + */ + private String deposit; + + /** + * Flag to show if the DRep is active (i.e., not expired) + */ + private Boolean active; + + /** + * After which epoch DRep is considered inactive (null if not applicable) + */ + private Integer expiresEpochNo; + + /** + * The total amount of voting power this DRep is delegated + */ + private String amount; + + /** + * A URL to a JSON payload of metadata (null if not applicable) + */ + private String url; + + /** + * A hash of the contents of the metadata URL (null if not applicable) + */ + private String hash; +} diff --git a/src/main/java/rest/koios/client/backend/api/governance/model/DRepMetadata.java b/src/main/java/rest/koios/client/backend/api/governance/model/DRepMetadata.java new file mode 100644 index 0000000..e664fd1 --- /dev/null +++ b/src/main/java/rest/koios/client/backend/api/governance/model/DRepMetadata.java @@ -0,0 +1,67 @@ +package rest.koios.client.backend.api.governance.model; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import lombok.*; + +/** + * DRep Metadata + */ +@Getter +@Setter +@ToString +@NoArgsConstructor +@EqualsAndHashCode +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class DRepMetadata { + + /** + * DRep ID in CIP-129 bech32 format + */ + private String drepId; + + /** + * DRep ID in hex format + */ + private String hex; + + /** + * Flag which shows if this credential is a script hash + */ + private Boolean hasScript; + + /** + * A URL to a JSON payload of metadata (null if not applicable) + */ + private String url; + + /** + * A hash of the contents of the metadata URL (null if not applicable) + */ + private String hash; + + /** + * The raw bytes of the payload (null if not applicable) + */ + private String json; + + /** + * A warning that occurred while validating the metadata (null if not applicable) + */ + private String warning; + + /** + * The language described in the context of the metadata as per CIP-100 (null if not applicable) + */ + private String language; + + /** + * Comment attached to the metadata (null if not applicable) + */ + private String comment; + + /** + * Indicate whether data is invalid + */ + private Boolean isValid; +} diff --git a/src/main/java/rest/koios/client/backend/api/governance/model/DRepUpdate.java b/src/main/java/rest/koios/client/backend/api/governance/model/DRepUpdate.java new file mode 100644 index 0000000..e90adb0 --- /dev/null +++ b/src/main/java/rest/koios/client/backend/api/governance/model/DRepUpdate.java @@ -0,0 +1,73 @@ +package rest.koios.client.backend.api.governance.model; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import lombok.*; + +/** + * DRep Update + */ +@Getter +@Setter +@ToString +@NoArgsConstructor +@EqualsAndHashCode +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class DRepUpdate { + + /** + * DRep ID in CIP-129 bech32 format + */ + private String drepId; + + /** + * DRep ID in hex format + */ + private String hex; + + /** + * Flag which shows if this credential is a script hash + */ + private Boolean hasScript; + + /** + * Hash identifier of the transaction + */ + private String updateTxHash; + + /** + * The index of this certificate within the transaction + */ + private Integer certIndex; + + /** + * UNIX timestamp of the block + */ + private Long blockTime; + + /** + * Effective action for this DRep Update certificate (updated, registered, deregistered) + */ + private String action; + + /** + * DRep's registration deposit in number (null if not applicable) + */ + private String deposit; + + /** + * A URL to a JSON payload of metadata (null if not applicable) + */ + private String metaUrl; + + /** + * A hash of the contents of the metadata URL (null if not applicable) + */ + private String metaHash; + + /** + * JSON object containing the metadata payload + */ + private JsonNode metaJson; +} diff --git a/src/main/java/rest/koios/client/backend/api/governance/model/DRepVote.java b/src/main/java/rest/koios/client/backend/api/governance/model/DRepVote.java new file mode 100644 index 0000000..f9c6a4a --- /dev/null +++ b/src/main/java/rest/koios/client/backend/api/governance/model/DRepVote.java @@ -0,0 +1,57 @@ +package rest.koios.client.backend.api.governance.model; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import lombok.*; + +/** + * DRep Vote + */ +@Getter +@Setter +@ToString +@NoArgsConstructor +@EqualsAndHashCode +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class DRepVote { + + /** + * Proposal Action ID in accordance with CIP-129 format + */ + private String proposalId; + + /** + * Hash identifier of the proposal transaction + */ + private String proposalTxHash; + + /** + * Index of governance proposal in transaction + */ + private Integer proposalIndex; + + /** + * Hash identifier of the vote transaction + */ + private String voteTxHash; + + /** + * UNIX timestamp of the block + */ + private Long blockTime; + + /** + * Actual Vote casted (Yes, No, Abstain) + */ + private String vote; + + /** + * A URL to a JSON payload of metadata (null if not applicable) + */ + private String metaUrl; + + /** + * A hash of the contents of the metadata URL (null if not applicable) + */ + private String metaHash; +} diff --git a/src/main/java/rest/koios/client/backend/api/governance/model/PoolVote.java b/src/main/java/rest/koios/client/backend/api/governance/model/PoolVote.java new file mode 100644 index 0000000..3bea534 --- /dev/null +++ b/src/main/java/rest/koios/client/backend/api/governance/model/PoolVote.java @@ -0,0 +1,57 @@ +package rest.koios.client.backend.api.governance.model; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import lombok.*; + +/** + * Pool Vote + */ +@Getter +@Setter +@ToString +@NoArgsConstructor +@EqualsAndHashCode +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class PoolVote { + + /** + * Proposal Action ID in accordance with CIP-129 format + */ + private String proposalId; + + /** + * Hash identifier of the proposal transaction + */ + private String proposalTxHash; + + /** + * Index of governance proposal in transaction + */ + private Integer proposalIndex; + + /** + * Hash identifier of the vote transaction + */ + private String voteTxHash; + + /** + * UNIX timestamp of the block + */ + private Long blockTime; + + /** + * Actual Vote casted (Yes, No, Abstain) + */ + private String vote; + + /** + * A URL to a JSON payload of metadata (null if not applicable) + */ + private String metaUrl; + + /** + * A hash of the contents of the metadata URL (null if not applicable) + */ + private String metaHash; +} diff --git a/src/main/java/rest/koios/client/backend/api/governance/model/Proposal.java b/src/main/java/rest/koios/client/backend/api/governance/model/Proposal.java new file mode 100644 index 0000000..2d28360 --- /dev/null +++ b/src/main/java/rest/koios/client/backend/api/governance/model/Proposal.java @@ -0,0 +1,129 @@ +package rest.koios.client.backend.api.governance.model; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import lombok.*; +import rest.koios.client.backend.api.transactions.model.TxWithdrawal; + +/** + * Proposal + */ +@Getter +@Setter +@ToString +@NoArgsConstructor +@EqualsAndHashCode +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class Proposal { + + /** + * UNIX timestamp of the block + */ + private Long blockTime; + + /** + * Proposal Action ID in accordance with CIP-129 format + */ + private String proposalId; + + /** + * Hash identifier of the transaction + */ + private String proposalTxHash; + + /** + * Index of governance proposal in transaction + */ + private Integer proposalIndex; + + /** + * Proposal Action Type (ParameterChange, HardForkInitiation, TreasuryWithdrawals, NoConfidence, NewCommittee, NewConstitution, InfoAction) + */ + private String proposalType; + + /** + * Description for Proposal Action + */ + private JsonNode proposalDescription; + + /** + * DRep's registration deposit in number (null if not applicable) + */ + private String deposit; + + /** + * The StakeAddress index of the reward address to receive the deposit when it is repaid + */ + private String returnAddress; + + /** + * Shows the epoch at which this governance action was proposed + */ + private Integer proposedEpoch; + + /** + * If not null, then this proposal has been ratified at the specified epoch + */ + private Integer ratifiedEpoch; + + /** + * If not null, then this proposal has been enacted at the specified epoch + */ + private Integer enactedEpoch; + + /** + * If not null, then this proposal has been dropped (expired/enacted) at the specified epoch + */ + private Integer droppedEpoch; + + /** + * If not null, then this proposal has been expired at the specified epoch + */ + private Integer expiredEpoch; + + /** + * Shows the epoch at which this governance action is expected to expire + */ + private Integer expiration; + + /** + * A URL to a JSON payload of metadata (null if not applicable) + */ + private String metaUrl; + + /** + * A hash of the contents of the metadata URL (null if not applicable) + */ + private String metaHash; + + /** + * JSON object containing the metadata payload + */ + private JsonNode metaJson; + + /** + * Comment attached to the metadata (null if not applicable) + */ + private String metaComment; + + /** + * The language described in the context of the metadata as per CIP-100 (null if not applicable) + */ + private String metaLanguage; + + /** + * Indicate whether data is invalid + */ + private Boolean metaIsValid; + + /** + * Object containing the withdrawal details or null if not applicable + */ + private TxWithdrawal withdrawal; + + /** + * Object containing parameter proposal details + */ + private JsonNode paramProposal; +} diff --git a/src/main/java/rest/koios/client/backend/api/governance/model/ProposalVote.java b/src/main/java/rest/koios/client/backend/api/governance/model/ProposalVote.java new file mode 100644 index 0000000..0507dc2 --- /dev/null +++ b/src/main/java/rest/koios/client/backend/api/governance/model/ProposalVote.java @@ -0,0 +1,57 @@ +package rest.koios.client.backend.api.governance.model; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import lombok.*; + +/** + * Proposal Vote + */ +@Getter +@Setter +@ToString +@NoArgsConstructor +@EqualsAndHashCode +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class ProposalVote { + + /** + * UNIX timestamp of the block + */ + private Long blockTime; + + /** + * The role of the voter (ConstitutionalCommittee, DRep, SPO) + */ + private String voterRole; + + /** + * Voter's DRep ID (CIP-129 bech32 format), pool ID (bech32 format) or committee hot ID (CIP-129 bech32 format) + */ + private String voterId; + + /** + * Voter's DRep ID, pool ID, or committee hash in hex format + */ + private String voterHex; + + /** + * Flag which shows if this credential is a script hash + */ + private Boolean voterHasScript; + + /** + * Actual Vote casted (Yes, No, Abstain) + */ + private String vote; + + /** + * A URL to a JSON payload of metadata (null if not applicable) + */ + private String metaUrl; + + /** + * A hash of the contents of the metadata URL (null if not applicable) + */ + private String metaHash; +} diff --git a/src/main/java/rest/koios/client/backend/api/governance/model/ProposalVotingSummary.java b/src/main/java/rest/koios/client/backend/api/governance/model/ProposalVotingSummary.java new file mode 100644 index 0000000..83e75b5 --- /dev/null +++ b/src/main/java/rest/koios/client/backend/api/governance/model/ProposalVotingSummary.java @@ -0,0 +1,109 @@ +package rest.koios.client.backend.api.governance.model; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import lombok.*; +import rest.koios.client.backend.api.transactions.model.TxWithdrawal; + +/** + * Proposal Voting Summary + */ +@Getter +@Setter +@ToString +@NoArgsConstructor +@EqualsAndHashCode +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class ProposalVotingSummary { + + /** + * Proposal Action Type (ParameterChange, HardForkInitiation, TreasuryWithdrawals, NoConfidence, NewCommittee, NewConstitution, InfoAction) + */ + private String proposalType; + + /** + * Epoch for which data was collated + */ + private Integer epochNo; + + /** + * Number of 'yes' votes casted by dreps + */ + private Integer drepYesVotesCast; + + /** + * Power of 'yes' votes from dreps + */ + private Integer drepYesVotePower; + + /** + * Percentage of 'yes' votes from dreps + */ + private Double drepYesPct; + + /** + * Number of 'no' votes casted by dreps + */ + private Integer drepNoVotesCast; + + /** + * Power of 'no' votes from dreps + */ + private Integer drepNoVotePower; + + /** + * Percentage of 'no' votes from dreps + */ + private Double drepNoPct; + + /** + * Number of 'yes' votes casted by pools + */ + private Integer poolYesVotesCast; + + /** + * Power of 'yes' votes from pools + */ + private Integer poolYesVotePower; + + /** + * Percentage of 'yes' votes from pools + */ + private Double poolYesPct; + + /** + * Number of 'no' votes casted by pools + */ + private Integer poolNoVotesCast; + + /** + * Power of 'no' votes from pools + */ + private Integer poolNoVotePower; + + /** + * Percentage of 'no' votes from pools + */ + private Double poolNoPct; + + /** + * Number of 'yes' votes casted by committee + */ + private Integer committeeYesVotesCast; + + /** + * Percentage of 'yes' votes from committee + */ + private Double committeeYesPct; + + /** + * Number of 'no' votes casted by committee + */ + private Integer committeeNoVotesCast; + + /** + * Percentage of 'no' votes from committee + */ + private Double committeeNoPct; +} diff --git a/src/main/java/rest/koios/client/backend/api/network/impl/NetworkServiceImpl.java b/src/main/java/rest/koios/client/backend/api/network/impl/NetworkServiceImpl.java index dfa9a90..b5c0da7 100644 --- a/src/main/java/rest/koios/client/backend/api/network/impl/NetworkServiceImpl.java +++ b/src/main/java/rest/koios/client/backend/api/network/impl/NetworkServiceImpl.java @@ -3,14 +3,12 @@ import rest.koios.client.backend.api.base.BaseService; import rest.koios.client.backend.api.base.Result; import rest.koios.client.backend.api.base.exception.ApiException; +import rest.koios.client.backend.api.network.NetworkService; import rest.koios.client.backend.api.network.api.NetworkApi; import rest.koios.client.backend.api.network.model.*; -import rest.koios.client.backend.api.network.NetworkService; import rest.koios.client.backend.factory.options.Options; import retrofit2.Call; -import retrofit2.Response; -import java.io.IOException; import java.util.List; /** @@ -23,7 +21,7 @@ public class NetworkServiceImpl extends BaseService implements NetworkService { /** * Network Service Implementation Constructor * - * @param baseUrl Base Url + * @param baseUrl Base Url * @param apiToken Authorization Bearer JWT Token */ public NetworkServiceImpl(String baseUrl, String apiToken) { @@ -34,78 +32,44 @@ public NetworkServiceImpl(String baseUrl, String apiToken) { @Override public Result getChainTip() throws ApiException { Call> call = networkApi.getChainTip(); - try { - Response> response = (Response) execute(call); - return processResponseGetOne(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponseGetOne(call); } @Override public Result getGenesisInfo() throws ApiException { Call> call = networkApi.getGenesisInfo(); - try { - Response> response = (Response) execute(call); - return processResponseGetOne(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponseGetOne(call); } @Override public Result getHistoricalTokenomicStatsByEpoch(Integer epochNo) throws ApiException { validateEpoch(epochNo); Call> call = networkApi.getHistoricalTokenomicStatsByEpoch(epochNo); - try { - Response> response = (Response) execute(call); - return processResponseGetOne(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponseGetOne(call); } @Override public Result> getHistoricalTokenomicStats(Options options) throws ApiException { Call> call = networkApi.getHistoricalTokenomicStats(optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override public Result> getParamUpdateProposals(Options options) throws ApiException { Call> call = networkApi.getParamUpdateProposals(optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + ; + return processResponse(call); } @Override public Result> getReserveWithdrawals(Options options) throws ApiException { Call> call = networkApi.getReserveWithdrawals(optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override public Result> getTreasuryWithdrawals(Options options) throws ApiException { Call> call = networkApi.getTreasuryWithdrawals(optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } } diff --git a/src/main/java/rest/koios/client/backend/api/pool/impl/PoolServiceImpl.java b/src/main/java/rest/koios/client/backend/api/pool/impl/PoolServiceImpl.java index 8b3c9df..5562c18 100644 --- a/src/main/java/rest/koios/client/backend/api/pool/impl/PoolServiceImpl.java +++ b/src/main/java/rest/koios/client/backend/api/pool/impl/PoolServiceImpl.java @@ -8,9 +8,7 @@ import rest.koios.client.backend.api.pool.model.*; import rest.koios.client.backend.factory.options.Options; import retrofit2.Call; -import retrofit2.Response; -import java.io.IOException; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -26,7 +24,7 @@ public class PoolServiceImpl extends BaseService implements PoolService { /** * Pool Service Implementation Constructor * - * @param baseUrl Base Url + * @param baseUrl Base Url * @param apiToken Authorization Bearer JWT Token */ public PoolServiceImpl(String baseUrl, String apiToken) { @@ -37,12 +35,7 @@ public PoolServiceImpl(String baseUrl, String apiToken) { @Override public Result> getPoolList(Options options) throws ApiException { Call> call = poolApi.getPoolList(optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override @@ -51,36 +44,21 @@ public Result> getPoolInformation(List poolIds, Options o validateBech32(poolId); } Call> call = poolApi.getPoolInformation(buildBody(poolIds), optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override public Result> getPoolStakeSnapshot(String poolBech32, Options options) throws ApiException { validateBech32(poolBech32); Call> call = poolApi.getPoolStakeSnapshot(poolBech32, optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override public Result> getPoolDelegatorsList(String poolBech32, Options options) throws ApiException { validateBech32(poolBech32); Call> call = poolApi.getPoolDelegatorsList(poolBech32, optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override @@ -90,12 +68,7 @@ public Result> getPoolDelegatorsHistory(String poolBe } validateBech32(poolBech32); Call> call = poolApi.getPoolDelegatorsHistory(poolBech32, epochNo, optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override @@ -103,24 +76,14 @@ public Result> getPoolBlocksByEpoch(String poolBech32, Integer e validateEpoch(epochNo); validateBech32(poolBech32); Call> call = poolApi.getPoolBlocksByEpoch(poolBech32, epochNo, optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override public Result> getPoolBlocks(String poolBech32, Options options) throws ApiException { validateBech32(poolBech32); Call> call = poolApi.getPoolBlocks(poolBech32, optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override @@ -128,80 +91,45 @@ public Result getPoolHistoryByEpoch(String poolBech32, Integer epoc validateBech32(poolBech32); validateEpoch(epochNo); Call> call = poolApi.getPoolHistoryByEpoch(poolBech32, epochNo, optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponseGetOne(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponseGetOne(call); } @Override public Result> getPoolHistory(String poolBech32, Options options) throws ApiException { validateBech32(poolBech32); Call> call = poolApi.getPoolHistory(poolBech32, optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override public Result> getPoolUpdatesByPoolBech32(String poolBech32, Options options) throws ApiException { validateBech32(poolBech32); Call> call = poolApi.getPoolUpdatesByPoolBech32(poolBech32, optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override public Result> getPoolUpdates(Options options) throws ApiException { Call> call = poolApi.getPoolUpdates(optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override public Result> getPoolRegistrations(Integer epochNo, Options options) throws ApiException { Call> call = poolApi.getPoolRegistrations(epochNo, optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override public Result> getPoolRetirements(Integer epochNo, Options options) throws ApiException { Call> call = poolApi.getPoolRetirements(epochNo, optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override public Result> getPoolRelays(Options options) throws ApiException { Call> call = poolApi.getPoolRelays(optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override @@ -215,12 +143,7 @@ public Result> getPoolMetadata(List poolIds, Options validateBech32(poolId); } Call> call = poolApi.getPoolMetadata(buildBody(poolIds), optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } private Map buildBody(List poolIds) { diff --git a/src/main/java/rest/koios/client/backend/api/pool/model/Pool.java b/src/main/java/rest/koios/client/backend/api/pool/model/Pool.java index 8cbcce2..0bfc711 100644 --- a/src/main/java/rest/koios/client/backend/api/pool/model/Pool.java +++ b/src/main/java/rest/koios/client/backend/api/pool/model/Pool.java @@ -49,6 +49,11 @@ public class Pool { */ private String pledge; + /** + * Pool's registration deposit in number + */ + private String deposit; + /** * Pool reward address */ diff --git a/src/main/java/rest/koios/client/backend/api/pool/model/PoolInfo.java b/src/main/java/rest/koios/client/backend/api/pool/model/PoolInfo.java index b092be7..baf9824 100644 --- a/src/main/java/rest/koios/client/backend/api/pool/model/PoolInfo.java +++ b/src/main/java/rest/koios/client/backend/api/pool/model/PoolInfo.java @@ -54,6 +54,11 @@ public class PoolInfo { */ private String pledge; + /** + * Pool's registration deposit in number + */ + private String deposit; + /** * Pool reward address */ diff --git a/src/main/java/rest/koios/client/backend/api/pool/model/PoolMetadata.java b/src/main/java/rest/koios/client/backend/api/pool/model/PoolMetadata.java index c5ac057..eb4950b 100644 --- a/src/main/java/rest/koios/client/backend/api/pool/model/PoolMetadata.java +++ b/src/main/java/rest/koios/client/backend/api/pool/model/PoolMetadata.java @@ -33,9 +33,4 @@ public class PoolMetadata { * Metadata Json Object */ private MetaJson metaJson; - - /** - * Pool Status: registered | retiring | retired - */ - private String poolStatus; } diff --git a/src/main/java/rest/koios/client/backend/api/pool/model/PoolRelay.java b/src/main/java/rest/koios/client/backend/api/pool/model/PoolRelay.java index 292c00a..57bffab 100644 --- a/src/main/java/rest/koios/client/backend/api/pool/model/PoolRelay.java +++ b/src/main/java/rest/koios/client/backend/api/pool/model/PoolRelay.java @@ -25,9 +25,4 @@ public class PoolRelay { * Relays */ private ArrayList relays; - - /** - * Pool Status: registered | retiring | retired - */ - private String poolStatus; } diff --git a/src/main/java/rest/koios/client/backend/api/script/impl/ScriptServiceImpl.java b/src/main/java/rest/koios/client/backend/api/script/impl/ScriptServiceImpl.java index ceed554..ca46123 100644 --- a/src/main/java/rest/koios/client/backend/api/script/impl/ScriptServiceImpl.java +++ b/src/main/java/rest/koios/client/backend/api/script/impl/ScriptServiceImpl.java @@ -5,15 +5,13 @@ import rest.koios.client.backend.api.base.common.UTxO; import rest.koios.client.backend.api.base.exception.ApiException; import rest.koios.client.backend.api.script.ScriptService; -import rest.koios.client.backend.api.script.model.*; import rest.koios.client.backend.api.script.api.ScriptApi; +import rest.koios.client.backend.api.script.model.*; import rest.koios.client.backend.factory.options.Options; import rest.koios.client.backend.factory.options.filters.Filter; import rest.koios.client.backend.factory.options.filters.FilterType; import retrofit2.Call; -import retrofit2.Response; -import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -42,23 +40,13 @@ public Result> getScriptInformation(List scriptHashes, validateHexFormat(scriptHash); } Call> call = scriptApi.getScriptInformation(buildBody("_script_hashes", scriptHashes), optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override public Result> getNativeScriptList(Options options) throws ApiException { Call> call = scriptApi.getNativeScriptList(optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override @@ -66,47 +54,27 @@ public Result getNativeScriptByScriptHash(String scriptHash) throw Call> call = scriptApi.getNativeScriptList(optionsToParamMap(Options.builder() .option(Filter.of("script_hash", FilterType.EQ, scriptHash)) .build())); - try { - Response> response = (Response) execute(call); - return processResponseGetOne(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponseGetOne(call); } @Override public Result> getPlutusScriptList(Options options) throws ApiException { Call> call = scriptApi.getPlutusScriptList(optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override public Result> getScriptRedeemers(String scriptHash, Options options) throws ApiException { validateHexFormat(scriptHash); Call> call = scriptApi.getScriptRedeemers(scriptHash, optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override public Result> getScriptUTxOs(String scriptHash, Boolean extended, Options options) throws ApiException { validateHexFormat(scriptHash); Call> call = scriptApi.getScriptUTxOs(scriptHash, extended, optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override @@ -115,12 +83,7 @@ public Result> getDatumInformation(List datumHashes, Opt validateHexFormat(datumHash); } Call> call = scriptApi.getDatumInformation(buildBody("_datum_hashes", datumHashes), optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } private Map buildBody(String arrayObjString, List list) { diff --git a/src/main/java/rest/koios/client/backend/api/transactions/TransactionsService.java b/src/main/java/rest/koios/client/backend/api/transactions/TransactionsService.java index e86363d..55afeea 100644 --- a/src/main/java/rest/koios/client/backend/api/transactions/TransactionsService.java +++ b/src/main/java/rest/koios/client/backend/api/transactions/TransactionsService.java @@ -26,6 +26,19 @@ public interface TransactionsService { */ Result> getUTxOInfo(List utxoRefs, boolean extended) throws ApiException; + /** + * Raw Transaction (CBOR) + * Get raw transaction(s) in CBOR format + *

200 - Raw Transaction(s) in CBOR format + *

401 - The selected server has restricted the endpoint to be only usable via authentication. The authentication supplied was not authorized to access the endpoint + *

404 - The server does not recognise the combination of endpoint and parameters provided + * + * @param txHashes List of Cardano Transaction hashes + * @param options Filtering and Pagination options (optional) + * @return Result of Type List of {@link RawTx} Raw Transaction(s) in CBOR format + * @throws ApiException if an error occurs while attempting to invoke the API + */ + Result> getRawTransaction(List txHashes, Options options) throws ApiException; /** * Transaction Information for Specific Transaction diff --git a/src/main/java/rest/koios/client/backend/api/transactions/api/TransactionApi.java b/src/main/java/rest/koios/client/backend/api/transactions/api/TransactionApi.java index 3b22002..4f3566a 100644 --- a/src/main/java/rest/koios/client/backend/api/transactions/api/TransactionApi.java +++ b/src/main/java/rest/koios/client/backend/api/transactions/api/TransactionApi.java @@ -24,6 +24,16 @@ public interface TransactionApi { @POST("utxo_info") Call> getUTxOInfo(@Body Map requestBody, @QueryMap Map paramsMap); + /** + * Get Raw Transaction (CBOR) + * + * @param requestBody Json Body containing Array of Cardano Transaction hashes + * @param paramsMap Filtering Options Query Parameters + * @return detailed information about transaction(s) + */ + @POST("tx_cbor") + Call> getRawTransaction(@Body Map requestBody, @QueryMap Map paramsMap); + /** * Get Transaction Information * diff --git a/src/main/java/rest/koios/client/backend/api/transactions/impl/TransactionsServiceImpl.java b/src/main/java/rest/koios/client/backend/api/transactions/impl/TransactionsServiceImpl.java index c98cdbe..2a9fdc7 100644 --- a/src/main/java/rest/koios/client/backend/api/transactions/impl/TransactionsServiceImpl.java +++ b/src/main/java/rest/koios/client/backend/api/transactions/impl/TransactionsServiceImpl.java @@ -6,14 +6,12 @@ import rest.koios.client.backend.api.base.Result; import rest.koios.client.backend.api.base.common.UTxO; import rest.koios.client.backend.api.base.exception.ApiException; +import rest.koios.client.backend.api.transactions.TransactionsService; import rest.koios.client.backend.api.transactions.api.TransactionApi; import rest.koios.client.backend.api.transactions.model.*; -import rest.koios.client.backend.api.transactions.TransactionsService; import rest.koios.client.backend.factory.options.Options; import retrofit2.Call; -import retrofit2.Response; -import java.io.IOException; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -29,7 +27,7 @@ public class TransactionsServiceImpl extends BaseService implements Transactions /** * Transaction Service Implementation Constructor * - * @param baseUrl Base Url + * @param baseUrl Base Url * @param apiToken Authorization Bearer JWT Token */ public TransactionsServiceImpl(String baseUrl, String apiToken) { @@ -40,24 +38,23 @@ public TransactionsServiceImpl(String baseUrl, String apiToken) { @Override public Result> getUTxOInfo(List utxoRefs, boolean extended) throws ApiException { Call> call = transactionApi.getUTxOInfo(buildBodyUTxOs(utxoRefs, extended), Collections.emptyMap()); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); + return processResponse(call); + } + + @Override + public Result> getRawTransaction(List txHashes, Options options) throws ApiException { + for (String tx : txHashes) { + validateHexFormat(tx); } + Call> call = transactionApi.getRawTransaction(buildBody(txHashes), optionsToParamMap(options)); + return processResponse(call); } @Override public Result getTransactionInformation(String txHash) throws ApiException { validateHexFormat(txHash); - Call> call = transactionApi.getTransactionInformation(buildBody(List.of(txHash)), Collections.emptyMap()); - try { - Response> response = (Response) execute(call); - return processResponseGetOne(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + Call> call = transactionApi.getTransactionInformation(buildTxInfoBody(List.of(txHash)), Collections.emptyMap()); + return processResponseGetOne(call); } @Override @@ -65,13 +62,8 @@ public Result> getTransactionInformation(List txHashes, Opt for (String tx : txHashes) { validateHexFormat(tx); } - Call> call = transactionApi.getTransactionInformation(buildBody(txHashes), optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + Call> call = transactionApi.getTransactionInformation(buildTxInfoBody(txHashes), optionsToParamMap(options)); + return processResponse(call); } @Override @@ -80,35 +72,20 @@ public Result> getTransactionMetadata(List txHashes, Op validateHexFormat(tx); } Call> call = transactionApi.getTransactionMetadata(buildBody(txHashes), optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override public Result> getTransactionMetadataLabels(Options options) throws ApiException { Call> call = transactionApi.getTransactionMetadataLabels(optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); } @Override public Result submitTx(byte[] cborData) throws ApiException { RequestBody requestBody = RequestBody.create(cborData, MediaType.parse("application/cbor")); Call txnCall = transactionApi.submitTx(requestBody); - try { - Response response = txnCall.execute(); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(txnCall); } @Override @@ -117,12 +94,20 @@ public Result> getTransactionStatus(List txHashes, Option validateHexFormat(tx); } Call> call = transactionApi.getTransactionStatus(buildBody(txHashes), optionsToParamMap(options)); - try { - Response> response = (Response) execute(call); - return processResponse(response); - } catch (IOException e) { - throw new ApiException(e.getMessage(), e); - } + return processResponse(call); + } + + private Map buildTxInfoBody(List txHashes) { + Map bodyMap = new HashMap<>(); + bodyMap.put("_tx_hashes", txHashes); + bodyMap.put("_inputs", true); + bodyMap.put("_metadata", true); + bodyMap.put("_assets", true); + bodyMap.put("_withdrawals", true); + bodyMap.put("_certs", true); + bodyMap.put("_scripts", true); + bodyMap.put("_bytecode", true); + return bodyMap; } private Map buildBody(List txHashes) { diff --git a/src/main/java/rest/koios/client/backend/api/transactions/model/ProposalProcedure.java b/src/main/java/rest/koios/client/backend/api/transactions/model/ProposalProcedure.java new file mode 100644 index 0000000..99e13d6 --- /dev/null +++ b/src/main/java/rest/koios/client/backend/api/transactions/model/ProposalProcedure.java @@ -0,0 +1,72 @@ +package rest.koios.client.backend.api.transactions.model; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +import java.util.List; + +/** + * Proposal Procedure + */ +@Getter +@Setter +@ToString +@NoArgsConstructor +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class ProposalProcedure { + + /** + * Index of governance proposal in transaction + */ + private Integer index; + + /** + * Proposal Action Type + * Allowed: ParameterChange|HardForkInitiation|TreasuryWithdrawals|NoConfidence|NewCommittee|NewConstitution|InfoAction + */ + private String type; + + /** + * Description for Proposal Action + */ + private Object description; + + /** + * DRep's registration deposit in number + */ + private String deposit; + + /** + * The StakeAddress index of the reward address to receive the deposit when it is repaid. + */ + private String returnAddress; + + /** + * Shows the epoch at which this governance action is expected to expire. + */ + private Long expiration; + + /** + * A URL to a JSON payload of metadata + */ + private String metaUrl; + + /** + * A hash of the contents of the metadata URL + */ + private String metaHash; + + /** + * If not null, the amount withdrawn from treasury into stake address by this this proposal + */ + private List withdrawal; + + /** + * If not null, the proposed new parameter set + */ + private List paramProposal; +} diff --git a/src/main/java/rest/koios/client/backend/api/transactions/model/RawTx.java b/src/main/java/rest/koios/client/backend/api/transactions/model/RawTx.java new file mode 100644 index 0000000..f5e9e2f --- /dev/null +++ b/src/main/java/rest/koios/client/backend/api/transactions/model/RawTx.java @@ -0,0 +1,33 @@ +package rest.koios.client.backend.api.transactions.model; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import rest.koios.client.backend.api.base.common.Asset; + +import java.util.List; + +/** + * Raw Transaction + */ +@Getter +@Setter +@ToString +@NoArgsConstructor +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class RawTx { + + /** + * Hash identifier of the transaction + */ + private String txHash = null; + + /** + * Raw Tx in CBOR format + */ + private String cbor = null; +} diff --git a/src/main/java/rest/koios/client/backend/api/transactions/model/TxInfo.java b/src/main/java/rest/koios/client/backend/api/transactions/model/TxInfo.java index 99993ea..ddc1f81 100644 --- a/src/main/java/rest/koios/client/backend/api/transactions/model/TxInfo.java +++ b/src/main/java/rest/koios/client/backend/api/transactions/model/TxInfo.java @@ -34,7 +34,7 @@ public class TxInfo { /** * Block height */ - private Integer blockHeight = null; + private Long blockHeight = null; /** * Epoch number of the block @@ -49,12 +49,12 @@ public class TxInfo { /** * Absolute slot number of the block */ - private Integer absoluteSlot = null; + private Long absoluteSlot = null; /** * UNIX timestamp of the transaction */ - private Integer txTimestamp = null; + private Long txTimestamp = null; /** * Index of transaction within block @@ -76,6 +76,11 @@ public class TxInfo { */ private String fee = null; + /** + * Total Donation to on-chain treasury (in numbers) + */ + private String treasuryDonation; + /** * Total Deposits included in transaction (for example, if it is registering a pool/key) */ @@ -145,4 +150,14 @@ public class TxInfo { * Plutus contracts present in transaction (if any) */ private List plutusContracts; + + /** + * Governance votes in a transaction (if any) + */ + private List votingProcedures; + + /** + * Governance proposals in a transaction (if any) + */ + private List proposalProcedures; } diff --git a/src/main/java/rest/koios/client/backend/api/transactions/model/VotingProcedure.java b/src/main/java/rest/koios/client/backend/api/transactions/model/VotingProcedure.java new file mode 100644 index 0000000..d237b8e --- /dev/null +++ b/src/main/java/rest/koios/client/backend/api/transactions/model/VotingProcedure.java @@ -0,0 +1,52 @@ +package rest.koios.client.backend.api.transactions.model; + + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +/** + * Voting Procedure + */ +@Getter +@Setter +@ToString +@NoArgsConstructor +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class VotingProcedure { + + /** + * Hash identifier of the transaction + */ + private String proposalTxHash; + + /** + * Index of governance proposal in transaction + */ + private Integer proposalIndex; + + /** + * The role of the voter + * Allowed: ConstitutionalCommittee|DRep|SPO + */ + private String voterRole; + + /** + * Voter's DRep ID (CIP-129 bech32 format), pool ID (bech32 format) or committee hot ID (CIP-129 bech32 format) + */ + private String voter; + + /** + * Voter's DRep ID , pool ID or committee hash in hex format + */ + private String voterHex; + + /** + * Actual Vote casted + * Allowed: Yes|No|Abstain + */ + private String vote; +} diff --git a/src/main/java/rest/koios/client/backend/factory/BackendService.java b/src/main/java/rest/koios/client/backend/factory/BackendService.java index 0a10f49..80f96bc 100644 --- a/src/main/java/rest/koios/client/backend/factory/BackendService.java +++ b/src/main/java/rest/koios/client/backend/factory/BackendService.java @@ -5,6 +5,7 @@ import rest.koios.client.backend.api.asset.AssetService; import rest.koios.client.backend.api.block.BlockService; import rest.koios.client.backend.api.epoch.EpochService; +import rest.koios.client.backend.api.governance.GovernanceService; import rest.koios.client.backend.api.network.NetworkService; import rest.koios.client.backend.api.pool.PoolService; import rest.koios.client.backend.api.script.ScriptService; @@ -69,4 +70,10 @@ public interface BackendService { * @return {@link ScriptService} */ ScriptService getScriptService(); + + /** + * Get Governance Service + * @return {@link GovernanceService} + */ + GovernanceService getGovernanceService(); } diff --git a/src/main/java/rest/koios/client/backend/factory/impl/BackendServiceImpl.java b/src/main/java/rest/koios/client/backend/factory/impl/BackendServiceImpl.java index ecff132..016e8fd 100644 --- a/src/main/java/rest/koios/client/backend/factory/impl/BackendServiceImpl.java +++ b/src/main/java/rest/koios/client/backend/factory/impl/BackendServiceImpl.java @@ -13,6 +13,8 @@ import rest.koios.client.backend.api.block.impl.BlockServiceImpl; import rest.koios.client.backend.api.epoch.EpochService; import rest.koios.client.backend.api.epoch.impl.EpochServiceImpl; +import rest.koios.client.backend.api.governance.GovernanceService; +import rest.koios.client.backend.api.governance.impl.GovernanceServiceImpl; import rest.koios.client.backend.api.network.NetworkService; import rest.koios.client.backend.api.network.impl.NetworkServiceImpl; import rest.koios.client.backend.api.pool.PoolService; @@ -42,6 +44,7 @@ public class BackendServiceImpl implements BackendService { private final AssetService assetService; private final PoolService poolService; private final ScriptService scriptService; + private final GovernanceService governanceService; /** * Backend Service Implementation Constructor @@ -58,7 +61,7 @@ public BackendServiceImpl(String baseUrl) { * @param baseUrl baseUrl */ public BackendServiceImpl(String baseUrl, String apiToken) { - log.info("Koios URL: " + baseUrl); + log.info("Koios URL: {}", baseUrl); this.networkService = new NetworkServiceImpl(baseUrl, apiToken); this.epochService = new EpochServiceImpl(baseUrl, apiToken); this.blockService = new BlockServiceImpl(baseUrl, apiToken); @@ -68,6 +71,7 @@ public BackendServiceImpl(String baseUrl, String apiToken) { this.assetService = new AssetServiceImpl(baseUrl, apiToken); this.poolService = new PoolServiceImpl(baseUrl, apiToken); this.scriptService = new ScriptServiceImpl(baseUrl, apiToken); + this.governanceService = new GovernanceServiceImpl(baseUrl, apiToken); } /** diff --git a/src/main/java/rest/koios/client/utils/HexUtil.java b/src/main/java/rest/koios/client/utils/HexUtil.java new file mode 100644 index 0000000..ef7d9f0 --- /dev/null +++ b/src/main/java/rest/koios/client/utils/HexUtil.java @@ -0,0 +1,75 @@ +package rest.koios.client.utils; + +public class HexUtil { + public static String encodeHexString(byte[] byteArray) { + if (byteArray == null) + return null; + + return encodeHexString(byteArray, false); + } + + public static String encodeHexString(byte[] byteArray, boolean withPrefix) { + if (byteArray == null) + return null; + + StringBuilder hexStringBuffer = new StringBuilder(); + for (byte b : byteArray) { + hexStringBuffer.append(byteToHex(b)); + } + String hexString = hexStringBuffer.toString(); + + if(withPrefix) + return "0x" + hexString; + else + return hexString; + } + + public static byte[] decodeHexString(String hexString) { + if(hexString != null && hexString.startsWith("0x")) + hexString = hexString.substring(2); + + if (hexString.length() % 2 == 1) { + throw new IllegalArgumentException( + "Invalid hexadecimal String supplied. " + hexString); + } + + byte[] bytes = new byte[hexString.length() / 2]; + for (int i = 0; i < hexString.length(); i += 2) { + bytes[i / 2] = hexToByte(hexString.substring(i, i + 2)); + } + return bytes; + } + + public static byte hexToByte(String hexString) { + int firstDigit = toDigit(hexString.charAt(0)); + int secondDigit = toDigit(hexString.charAt(1)); + return (byte) ((firstDigit << 4) + secondDigit); + } + + public static String byteToHex(byte num) { + char[] hexDigits = new char[2]; + hexDigits[0] = Character.forDigit((num >> 4) & 0xF, 16); + hexDigits[1] = Character.forDigit((num & 0xF), 16); + return new String(hexDigits); + } + + private static int toDigit(char hexChar) { + int digit = Character.digit(hexChar, 16); + if(digit == -1) { + throw new IllegalArgumentException( + "Invalid Hexadecimal Character: "+ hexChar); + } + return digit; + } + + public static void main(String[] args) { + String hexValue = "4123d70f66414cc921f6ffc29a899aafc7137a99a0fd453d6b200863ef5702d6"; + + byte[] bytes = decodeHexString(hexValue); + + String newVal = encodeHexString(bytes); + + System.out.printf(newVal); + + } +} diff --git a/src/test/java/rest/koios/client/backend/api/asset/AssetServiceMainnetIntegrationTest.java b/src/test/java/rest/koios/client/backend/api/asset/AssetServiceMainnetIntegrationTest.java index ceb6727..f88e566 100644 --- a/src/test/java/rest/koios/client/backend/api/asset/AssetServiceMainnetIntegrationTest.java +++ b/src/test/java/rest/koios/client/backend/api/asset/AssetServiceMainnetIntegrationTest.java @@ -5,6 +5,7 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; +import org.junit.platform.commons.util.StringUtils; import rest.koios.client.backend.api.asset.model.*; import rest.koios.client.backend.api.base.common.TxHash; import rest.koios.client.backend.api.base.Result; @@ -12,13 +13,20 @@ import rest.koios.client.backend.api.base.exception.ApiException; import rest.koios.client.backend.factory.BackendFactory; import rest.koios.client.backend.factory.options.Limit; +import rest.koios.client.backend.factory.options.Offset; import rest.koios.client.backend.factory.options.Options; import rest.koios.client.backend.factory.options.filters.Filter; import rest.koios.client.backend.factory.options.filters.FilterType; +import rest.koios.client.utils.HexUtil; import rest.koios.client.utils.Tuple; import java.math.BigInteger; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; import java.util.List; +import java.util.StringJoiner; +import java.util.stream.Collectors; import static org.junit.jupiter.api.Assertions.*; @@ -136,7 +144,7 @@ void getAssetInformationBadRequestTest() { void getAssetInformationBulkTest() throws ApiException { List> tupleList = List.of(new Tuple<>("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501", "424f4f4b"), new Tuple<>("f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a", "6b6f696f732e72657374")); - Result assetInformationBulkResult = assetService.getAssetInformationBulk(tupleList, Options.EMPTY); + Result> assetInformationBulkResult = assetService.getAssetInformationBulk(tupleList, Options.EMPTY); Assertions.assertTrue(assetInformationBulkResult.isSuccessful()); Assertions.assertNotNull(assetInformationBulkResult.getValue()); log.info(assetInformationBulkResult.getValue().toString()); @@ -237,4 +245,53 @@ void getAssetTxsBadRequestTest() { ApiException exception = assertThrows(ApiException.class, () -> assetService.getAssetTransactions(assetPolicy, assetNameHex, Options.EMPTY)); assertInstanceOf(ApiException.class, exception); } + + + @Test + void getNFTArrivalDate() throws ApiException { + String assetPolicy = "2edd9753b85e908ac63c5ae7b3bb013ad871da4a450b5f21a5218c46"; + List policyAssets = getAllPolicyAssetList(assetPolicy); + policyAssets.forEach(policyAsset -> { + Result> listResult; + try { + listResult = assetService.getNFTAddress(assetPolicy, policyAsset.getAssetName(), Options.EMPTY); + Assertions.assertTrue(listResult.isSuccessful()); + List paymentAddresses = listResult.getValue(); + System.out.println(policyAsset.getFingerprint()+","+new String(HexUtil.decodeHexString(policyAsset.getAssetName()))+","+paymentAddresses); +// addresses.addAll(paymentAddresses.stream().map(PaymentAddress::toString).collect(Collectors.toList())); + } catch (ApiException e) { + throw new RuntimeException(e); + } + }); + } + + public List getAllPolicyAssetList(String assetPolicy) throws ApiException { + List policyAssets = new ArrayList<>(); + int page = 1; + Options options = Options.builder() + .option(Limit.of(1000)) + .option(Offset.of(0)) + .build(); + Result> policyAssetList = assetService.getPolicyAssetList(assetPolicy, options); + while (policyAssetList.isSuccessful()) { + policyAssets.addAll(policyAssetList.getValue()); + if (policyAssetList.getValue().size() != 1000) { + break; + } else { + page++; + options = Options.builder() + .option(Limit.of(1000)) + .option(Offset.of((long) (page - 1) * 1000)) + .build(); + policyAssetList = assetService.getPolicyAssetList(assetPolicy, options); + } + } + if (!policyAssetList.isSuccessful()) { + return policyAssetList.getValue(); + } else { + return policyAssets; + } + } + + } diff --git a/src/test/java/rest/koios/client/backend/api/asset/AssetServicePreprodIntegrationTest.java b/src/test/java/rest/koios/client/backend/api/asset/AssetServicePreprodIntegrationTest.java index 5edf326..486c386 100644 --- a/src/test/java/rest/koios/client/backend/api/asset/AssetServicePreprodIntegrationTest.java +++ b/src/test/java/rest/koios/client/backend/api/asset/AssetServicePreprodIntegrationTest.java @@ -123,7 +123,7 @@ void getAssetInformationBadRequestTest() { void getAssetInformationBulkTest() throws ApiException { List> tupleList = List.of(new Tuple<>("c6e65ba7878b2f8ea0ad39287d3e2fd256dc5c4160fc19bdf4c4d87e", "7447454e53"), new Tuple<>("777e6b4903dab74963ae581d39875c5dac16c09bb1f511c0af1ddda8", "6141414441")); - Result assetInformationBulkResult = assetService.getAssetInformationBulk(tupleList, Options.EMPTY); + Result> assetInformationBulkResult = assetService.getAssetInformationBulk(tupleList, Options.EMPTY); Assertions.assertTrue(assetInformationBulkResult.isSuccessful()); Assertions.assertNotNull(assetInformationBulkResult.getValue()); log.info(assetInformationBulkResult.getValue().toString()); diff --git a/src/test/java/rest/koios/client/backend/api/asset/AssetServicePreviewIntegrationTest.java b/src/test/java/rest/koios/client/backend/api/asset/AssetServicePreviewIntegrationTest.java index 2d999a0..0ea5d15 100644 --- a/src/test/java/rest/koios/client/backend/api/asset/AssetServicePreviewIntegrationTest.java +++ b/src/test/java/rest/koios/client/backend/api/asset/AssetServicePreviewIntegrationTest.java @@ -123,7 +123,7 @@ void getAssetInformationBadRequestTest() { void getAssetInformationBulkTest() throws ApiException { List> tupleList = List.of(new Tuple<>("065270479316f1d92e00f7f9f095ebeaac9d009c878dc35ce36d3404", "433374"), new Tuple<>("189e2c53985411addb8df0f3e09f70e343da69f06746c408aba672a8", "15fc257714a51769e192761d674db2ee2e80137428e522f9b914debb5f785301")); - Result assetInformationBulkResult = assetService.getAssetInformationBulk(tupleList, Options.EMPTY); + Result> assetInformationBulkResult = assetService.getAssetInformationBulk(tupleList, Options.EMPTY); Assertions.assertTrue(assetInformationBulkResult.isSuccessful()); Assertions.assertNotNull(assetInformationBulkResult.getValue()); log.info(assetInformationBulkResult.getValue().toString()); diff --git a/src/test/java/rest/koios/client/backend/api/governance/GovernanceServiceMainnetIntegrationTest.java b/src/test/java/rest/koios/client/backend/api/governance/GovernanceServiceMainnetIntegrationTest.java new file mode 100644 index 0000000..8e0d013 --- /dev/null +++ b/src/test/java/rest/koios/client/backend/api/governance/GovernanceServiceMainnetIntegrationTest.java @@ -0,0 +1,149 @@ +package rest.koios.client.backend.api.governance; + +import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import rest.koios.client.backend.api.base.Result; +import rest.koios.client.backend.api.base.exception.ApiException; +import rest.koios.client.backend.api.governance.model.*; +import rest.koios.client.backend.factory.BackendFactory; +import rest.koios.client.backend.factory.options.Options; + +import java.util.List; + +@Slf4j +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class GovernanceServiceMainnetIntegrationTest { + + private GovernanceService governanceService; + + @BeforeAll + public void setup() { + governanceService = BackendFactory.getKoiosMainnetService().getGovernanceService(); + } + + @Test + void getDRepsEpochSummaryTest() throws ApiException { + Integer epochNo = 320; + Result> result = governanceService.getDRepsEpochSummary(epochNo, Options.EMPTY); + Assertions.assertTrue(result.isSuccessful()); + Assertions.assertNotNull(result.getValue()); + log.info(result.getValue().toString()); + } + + @Test + void getDRepsListTest() throws ApiException { + Result> result = governanceService.getDRepsList(Options.EMPTY); + Assertions.assertTrue(result.isSuccessful()); + Assertions.assertNotNull(result.getValue()); + log.info(result.getValue().toString()); + } + + @Test + void getDRepsInfoTest() throws ApiException { + List drepIds = List.of("drep17l6sywnwqu9aedd6aumev42w39ln5zfl9nw7j4ak6u8swyrwvz3", "drep1s9q5uyddsvza4uk2n9wswy90n8wx9d2jmrq4zgcvlyv055007av"); + Result> result = governanceService.getDRepsInfo(drepIds, Options.EMPTY); + Assertions.assertTrue(result.isSuccessful()); + Assertions.assertNotNull(result.getValue()); + log.info(result.getValue().toString()); + } + + @Test + void getDRepsMetadataTest() throws ApiException { + List drepIds = List.of("drep17l6sywnwqu9aedd6aumev42w39ln5zfl9nw7j4ak6u8swyrwvz3", "drep1s9q5uyddsvza4uk2n9wswy90n8wx9d2jmrq4zgcvlyv055007av"); + Result> result = governanceService.getDRepsMetadata(drepIds, Options.EMPTY); + Assertions.assertTrue(result.isSuccessful()); + Assertions.assertNotNull(result.getValue()); + log.info(result.getValue().toString()); + } + + @Test + void getDRepsUpdatesTest() throws ApiException { + String drepId = "drep17l6sywnwqu9aedd6aumev42w39ln5zfl9nw7j4ak6u8swyrwvz3"; + Result> result = governanceService.getDRepsUpdates(drepId, Options.EMPTY); + Assertions.assertTrue(result.isSuccessful()); + Assertions.assertNotNull(result.getValue()); + log.info(result.getValue().toString()); + } + + @Test + void getDRepsVotesTest() throws ApiException { + String drepId = "drep17l6sywnwqu9aedd6aumev42w39ln5zfl9nw7j4ak6u8swyrwvz3"; + Result> result = governanceService.getDRepsVotes(drepId, Options.EMPTY); + Assertions.assertTrue(result.isSuccessful()); + Assertions.assertNotNull(result.getValue()); + log.info(result.getValue().toString()); + } + + @Test + void getDRepsDelegatorsTest() throws ApiException { + String drepId = "drep17l6sywnwqu9aedd6aumev42w39ln5zfl9nw7j4ak6u8swyrwvz3"; + Result> result = governanceService.getDRepsDelegators(drepId, Options.EMPTY); + Assertions.assertTrue(result.isSuccessful()); + Assertions.assertNotNull(result.getValue()); + log.info(result.getValue().toString()); + } + + @Test + void getCommitteeInformationTest() throws ApiException { + Result> result = governanceService.getCommitteeInformation(Options.EMPTY); + Assertions.assertTrue(result.isSuccessful()); + Assertions.assertNotNull(result.getValue()); + log.info(result.getValue().toString()); + } + + @Test + void getCommitteeVotesTest() throws ApiException { + String ccHotId = "cc_hot1qgqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqvcdjk7"; + Result> result = governanceService.getCommitteeVotes(ccHotId, Options.EMPTY); + Assertions.assertTrue(result.isSuccessful()); + Assertions.assertNotNull(result.getValue()); + log.info(result.getValue().toString()); + } + + @Test + void getProposalListTest() throws ApiException { + Result> result = governanceService.getProposalList(Options.EMPTY); + Assertions.assertTrue(result.isSuccessful()); + Assertions.assertNotNull(result.getValue()); + log.info(result.getValue().toString()); + } + + @Test + void getVoterProposalsTest() throws ApiException { + String voterId = "drep17l6sywnwqu9aedd6aumev42w39ln5zfl9nw7j4ak6u8swyrwvz3"; + Result> result = governanceService.getVoterProposals(voterId, Options.EMPTY); + Assertions.assertTrue(result.isSuccessful()); + Assertions.assertNotNull(result.getValue()); + log.info(result.getValue().toString()); + } + + @Test + void getProposalVotingSummaryTest() throws ApiException { + String proposalId = "gov_action1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqpzklpgpf"; + Result> result = governanceService.getProposalVotingSummary(proposalId, Options.EMPTY); + Assertions.assertTrue(result.isSuccessful()); + Assertions.assertNotNull(result.getValue()); + log.info(result.getValue().toString()); + } + + @Test + void getProposalVotesTest() throws ApiException { + String proposalId = "gov_action1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqpzklpgpf"; + Result> result = governanceService.getProposalVotes(proposalId, Options.EMPTY); + Assertions.assertTrue(result.isSuccessful()); + Assertions.assertNotNull(result.getValue()); + log.info(result.getValue().toString()); + } + + @Test + void getPoolVotesTest() throws ApiException { + String poolBech32 = "pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc"; + Result> result = governanceService.getPoolVotes(poolBech32, Options.EMPTY); + Assertions.assertTrue(result.isSuccessful()); + Assertions.assertNotNull(result.getValue()); + log.info(result.getValue().toString()); + } +}