Skip to content

Commit

Permalink
feat: update stake endpoint when migrate with new ls schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Sotatek-DucPhung committed May 9, 2024
1 parent 8607142 commit bff777b
Show file tree
Hide file tree
Showing 44 changed files with 2,270 additions and 2,263 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.core.annotations.ParameterObject;

import org.cardanofoundation.explorer.api.common.enumeration.AnalyticType;
import org.cardanofoundation.explorer.api.config.LogMessage;
Expand All @@ -27,7 +28,6 @@
import org.cardanofoundation.explorer.common.validation.pagination.Pagination;
import org.cardanofoundation.explorer.common.validation.pagination.PaginationDefault;
import org.cardanofoundation.explorer.common.validation.pagination.PaginationValid;
import org.springdoc.core.annotations.ParameterObject;

@RestController
@RequestMapping("/api/v1/addresses")
Expand All @@ -40,22 +40,22 @@ public class AddressController {

private final TxService txService;

@GetMapping("/{address}")
@LogMessage
@Operation(
summary = "Get detail information of payment address",
description =
"Get detail information of payment address with balance, txs, token and check contract",
tags = {"address"})
public ResponseEntity<AddressResponse> getAddressDetail(
@PathVariable
@Parameter(
description =
"The human readable encoding of the output address."
+ " Will be Base58 for Byron era addresses and Bech32 for Shelley era.")
String address) {
return ResponseEntity.ok(addressService.getAddressDetail(address));
}
@GetMapping("/{address}")
@LogMessage
@Operation(
summary = "Get detail information of payment address",
description =
"Get detail information of payment address with balance, txs, token and check contract",
tags = {"address"})
public ResponseEntity<AddressResponse> getAddressDetail(
@PathVariable
@Parameter(
description =
"The human readable encoding of the output address."
+ " Will be Base58 for Byron era addresses and Bech32 for Shelley era.")
String address) {
return ResponseEntity.ok(addressService.getAddressDetail(address));
}

@GetMapping("/top-addresses")
@LogMessage
Expand All @@ -64,30 +64,33 @@ public ResponseEntity<AddressResponse> getAddressDetail(
tags = {"address"})
public ResponseEntity<BaseFilterResponse<AddressFilterResponse>> getTopAddress(
@ParameterObject
@PaginationDefault(
size = 20,
sort = {LatestTokenBalance_.QUANTITY},
direction = Sort.Direction.DESC)
@PaginationValid @PageZeroValid @Valid Pagination pagination) {
@PaginationDefault(
size = 20,
sort = {LatestTokenBalance_.QUANTITY},
direction = Sort.Direction.DESC)
@PaginationValid
@PageZeroValid
@Valid
Pagination pagination) {
return ResponseEntity.ok(addressService.getTopAddress(pagination.toPageable()));
}

@GetMapping("/analytics/{address}/{type}")
@LogMessage
@Operation(
summary = "Get analytics of address",
description = "Get analytics balance of address and time type",
tags = {"address"})
public ResponseEntity<AddressChartBalanceResponse> getAddressAnalytics(
@PathVariable
@Parameter(
description =
"The human readable encoding of the output address."
+ " Will be Base58 for Byron era addresses and Bech32 for Shelley era.")
String address,
@PathVariable @Parameter(description = "Type for analytics by time") AnalyticType type) {
return ResponseEntity.ok(addressService.getAddressAnalytics(address, type));
}
@GetMapping("/analytics/{address}/{type}")
@LogMessage
@Operation(
summary = "Get analytics of address",
description = "Get analytics balance of address and time type",
tags = {"address"})
public ResponseEntity<AddressChartBalanceResponse> getAddressAnalytics(
@PathVariable
@Parameter(
description =
"The human readable encoding of the output address."
+ " Will be Base58 for Byron era addresses and Bech32 for Shelley era.")
String address,
@PathVariable @Parameter(description = "Type for analytics by time") AnalyticType type) {
return ResponseEntity.ok(addressService.getAddressAnalytics(address, type));
}

// @GetMapping("/{address}/txs")
// @LogMessage
Expand All @@ -106,24 +109,24 @@ public ResponseEntity<AddressChartBalanceResponse> getAddressAnalytics(
// pagination.toPageable()));
// }

@GetMapping("/{address}/tokens")
@LogMessage
@Operation(
summary = "Get list token by address",
description =
"Get list token by address with search by display name, will return all token if display name is null or empty",
tags = {"address"})
public ResponseEntity<BaseFilterResponse<TokenAddressResponse>> getTokenByAddress(
@PathVariable
@Parameter(
description =
"The human readable encoding of the output address."
+ " Will be Base58 for Byron era addresses and Bech32 for Shelley era.")
String address,
@RequestParam(required = false) @Parameter(description = "Display name query for search")
String displayName,
@ParameterObject @PaginationValid @Valid Pagination pagination) {
return ResponseEntity.ok(
addressService.getTokenByDisplayName(pagination.toPageable(), address, displayName));
}
@GetMapping("/{address}/tokens")
@LogMessage
@Operation(
summary = "Get list token by address",
description =
"Get list token by address with search by display name, will return all token if display name is null or empty",
tags = {"address"})
public ResponseEntity<BaseFilterResponse<TokenAddressResponse>> getTokenByAddress(
@PathVariable
@Parameter(
description =
"The human readable encoding of the output address."
+ " Will be Base58 for Byron era addresses and Bech32 for Shelley era.")
String address,
@RequestParam(required = false) @Parameter(description = "Display name query for search")
String displayName,
@ParameterObject @PaginationValid @Valid Pagination pagination) {
return ResponseEntity.ok(
addressService.getTokenByDisplayName(pagination.toPageable(), address, displayName));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,23 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.cardanofoundation.explorer.api.model.response.script.nativescript.NativeScriptResponse;
import org.cardanofoundation.explorer.api.model.response.script.smartcontract.SmartContractDetailResponse;
import org.cardanofoundation.explorer.api.model.response.token.TokenAddressResponse;
import org.cardanofoundation.explorer.common.entity.ledgersync.TokenTxCount_;
import org.springdoc.core.annotations.ParameterObject;

import org.cardanofoundation.explorer.api.config.LogMessage;
import org.cardanofoundation.explorer.api.model.request.script.nativescript.NativeScriptFilterRequest;
import org.cardanofoundation.explorer.api.model.request.script.smartcontract.SmartContractFilterRequest;
import org.cardanofoundation.explorer.api.model.response.BaseFilterResponse;
import org.cardanofoundation.explorer.api.model.response.script.nativescript.NativeScriptFilterResponse;
import org.cardanofoundation.explorer.api.model.response.script.nativescript.NativeScriptResponse;
import org.cardanofoundation.explorer.api.model.response.script.smartcontract.SmartContractDetailResponse;
import org.cardanofoundation.explorer.api.model.response.script.smartcontract.SmartContractFilterResponse;
import org.cardanofoundation.explorer.api.model.response.script.smartcontract.SmartContractTxResponse;
import org.cardanofoundation.explorer.api.model.response.search.ScriptSearchResponse;
import org.cardanofoundation.explorer.api.model.response.token.TokenAddressResponse;
import org.cardanofoundation.explorer.api.model.response.token.TokenFilterResponse;
import org.cardanofoundation.explorer.api.service.ScriptService;
import org.cardanofoundation.explorer.common.entity.explorer.NativeScriptInfo_;
import org.cardanofoundation.explorer.common.entity.ledgersync.MultiAsset_;
import org.cardanofoundation.explorer.common.entity.ledgersync.TokenTxCount_;
import org.cardanofoundation.explorer.common.validation.pagination.Pagination;
import org.cardanofoundation.explorer.common.validation.pagination.PaginationDefault;
import org.cardanofoundation.explorer.common.validation.pagination.PaginationValid;
Expand Down Expand Up @@ -62,12 +61,12 @@ public ResponseEntity<BaseFilterResponse<NativeScriptFilterResponse>> getNativeS
scriptService.getNativeScripts(filterRequest, pagination.toPageable()));
}

@GetMapping("/native-scripts/{scriptHash}")
@LogMessage
public ResponseEntity<NativeScriptResponse> getNativeScriptDetail(
@PathVariable String scriptHash) {
return ResponseEntity.ok(scriptService.getNativeScriptDetail(scriptHash));
}
@GetMapping("/native-scripts/{scriptHash}")
@LogMessage
public ResponseEntity<NativeScriptResponse> getNativeScriptDetail(
@PathVariable String scriptHash) {
return ResponseEntity.ok(scriptService.getNativeScriptDetail(scriptHash));
}

@PostMapping("/native-scripts/{scriptHash}/verify")
@LogMessage
Expand All @@ -94,17 +93,17 @@ public ResponseEntity<BaseFilterResponse<TokenFilterResponse>> getTokens(
scriptService.getNativeScriptTokens(scriptHash, pagination.toPageable()));
}

@GetMapping("/native-scripts/{scriptHash}/holders")
@LogMessage
@Operation(
summary = "Get holders by policy",
description = "Get all holders of all tokens of policy")
public ResponseEntity<BaseFilterResponse<TokenAddressResponse>> getHolders(
@PathVariable @Parameter(description = "The native script hash") String scriptHash,
@ParameterObject @PaginationValid @Valid Pagination pagination) {
return ResponseEntity.ok(
scriptService.getNativeScriptHolders(scriptHash, pagination.toPageable()));
}
@GetMapping("/native-scripts/{scriptHash}/holders")
@LogMessage
@Operation(
summary = "Get holders by policy",
description = "Get all holders of all tokens of policy")
public ResponseEntity<BaseFilterResponse<TokenAddressResponse>> getHolders(
@PathVariable @Parameter(description = "The native script hash") String scriptHash,
@ParameterObject @PaginationValid @Valid Pagination pagination) {
return ResponseEntity.ok(
scriptService.getNativeScriptHolders(scriptHash, pagination.toPageable()));
}

@GetMapping("/contracts")
public ResponseEntity<BaseFilterResponse<SmartContractFilterResponse>> getSmartContracts(
Expand All @@ -122,15 +121,15 @@ public ResponseEntity<BaseFilterResponse<SmartContractFilterResponse>> getSmartC
scriptService.getSmartContracts(filterRequest, pagination.toPageable()));
}

@GetMapping("/contracts/{scriptHash}")
@LogMessage
@Operation(
summary = "Get smart contract detail",
tags = {"script"})
public ResponseEntity<SmartContractDetailResponse> getSmartContracts(
@PathVariable @Parameter(description = "The script hash") String scriptHash) {
return ResponseEntity.ok(scriptService.getSmartContractDetail(scriptHash));
}
@GetMapping("/contracts/{scriptHash}")
@LogMessage
@Operation(
summary = "Get smart contract detail",
tags = {"script"})
public ResponseEntity<SmartContractDetailResponse> getSmartContracts(
@PathVariable @Parameter(description = "The script hash") String scriptHash) {
return ResponseEntity.ok(scriptService.getSmartContractDetail(scriptHash));
}

@GetMapping("/contracts/{scriptHash}/txs")
@LogMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
import org.springdoc.core.annotations.ParameterObject;

import org.cardanofoundation.explorer.api.common.constant.CommonConstant;
import org.cardanofoundation.explorer.api.common.enumeration.AnalyticType;
import org.cardanofoundation.explorer.api.config.LogMessage;
import org.cardanofoundation.explorer.api.controller.validation.StakeKeyLengthValid;
import org.cardanofoundation.explorer.api.model.response.BaseFilterResponse;
import org.cardanofoundation.explorer.api.model.response.StakeAnalyticResponse;
import org.cardanofoundation.explorer.api.model.response.address.AddressChartBalanceResponse;
import org.cardanofoundation.explorer.api.model.response.address.AddressFilterResponse;
import org.cardanofoundation.explorer.api.model.response.address.StakeAddressResponse;
import org.cardanofoundation.explorer.api.model.response.address.StakeAddressRewardDistribution;
import org.cardanofoundation.explorer.api.model.response.stake.StakeAnalyticRewardResponse;
Expand All @@ -35,6 +38,7 @@
import org.cardanofoundation.explorer.api.projection.StakeWithdrawalProjection;
import org.cardanofoundation.explorer.api.service.StakeKeyService;
import org.cardanofoundation.explorer.api.service.TxService;
import org.cardanofoundation.explorer.common.entity.ledgersync.LatestAddressBalance_;
import org.cardanofoundation.explorer.common.entity.ledgersync.StakeDeregistration_;
import org.cardanofoundation.explorer.common.entity.ledgersync.StakeRegistration_;
import org.cardanofoundation.explorer.common.validation.pagination.PageZeroValid;
Expand Down Expand Up @@ -187,18 +191,23 @@ public BaseFilterResponse<StakeFilterResponse> getTopDelegators(
return stakeService.getTopDelegators(pagination.toPageable());
}

// @GetMapping("/{stakeKey}/list-address")
// @LogMessage
// @Operation(summary = "Get all address of stake", tags = "stake-key")
// public ResponseEntity<BaseFilterResponse<AddressFilterResponse>> getAddresses(
// @PathVariable
// @PrefixedValid(CommonConstant.PREFIXED_STAKE_KEY)
// @StakeKeyLengthValid
// @Parameter(description = "The Bech32 encoded version of the stake address.")
// String stakeKey,
// @ParameterObject @PaginationValid @Valid Pagination pagination) {
// return ResponseEntity.ok(stakeService.getAddresses(stakeKey, pagination.toPageable()));
// }
@GetMapping("/{stakeKey}/list-address")
@LogMessage
@Operation(summary = "Get all address of stake", tags = "stake-key")
public ResponseEntity<BaseFilterResponse<AddressFilterResponse>> getAddresses(
@PathVariable
@PrefixedValid(CommonConstant.PREFIXED_STAKE_KEY)
@StakeKeyLengthValid
@Parameter(description = "The Bech32 encoded version of the stake address.")
String stakeKey,
@PaginationDefault(
size = 20,
sort = {LatestAddressBalance_.QUANTITY},
direction = Sort.Direction.DESC)
@Valid
Pagination pagination) {
return ResponseEntity.ok(stakeService.getAddresses(stakeKey, pagination.toPageable()));
}

@GetMapping("/analytics")
@LogMessage
Expand All @@ -207,20 +216,18 @@ public ResponseEntity<StakeAnalyticResponse> getStakeAnalytics() {
return ResponseEntity.ok(stakeService.getStakeAnalytics());
}

// @GetMapping("/analytics-balance/{stakeKey}/{type}")
// @LogMessage
// @Operation(summary = "Get stake balance analytics", tags = "stake-key")
// public ResponseEntity<AddressChartBalanceResponse> getStakeBalanceAnalytics(
// @PathVariable
// @PrefixedValid(CommonConstant.PREFIXED_STAKE_KEY)
// @StakeKeyLengthValid
// @Parameter(description = "The Bech32 encoded version of the stake address.")
// String stakeKey,
// @PathVariable @Parameter(description = "Type analytics: 1d, 1w, 1m, 3m") AnalyticType
// type)
// throws ExecutionException, InterruptedException {
// return ResponseEntity.ok(stakeService.getStakeBalanceAnalytics(stakeKey, type));
// }
@GetMapping("/analytics-balance/{stakeKey}/{type}")
@LogMessage
@Operation(summary = "Get stake balance analytics", tags = "stake-key")
public ResponseEntity<AddressChartBalanceResponse> getStakeBalanceAnalytics(
@PathVariable
@PrefixedValid(CommonConstant.PREFIXED_STAKE_KEY)
@StakeKeyLengthValid
@Parameter(description = "The Bech32 encoded version of the stake address.")
String stakeKey,
@PathVariable @Parameter(description = "Type analytics: 1d, 1w, 1m, 3m") AnalyticType type) {
return ResponseEntity.ok(stakeService.getStakeBalanceAnalytics(stakeKey, type));
}

@GetMapping("/analytics-reward/{stakeKey}")
@LogMessage
Expand Down

0 comments on commit bff777b

Please sign in to comment.