1 | package org.cardanofoundation.explorer.api.controller; | |
2 | ||
3 | import java.util.List; | |
4 | ||
5 | import jakarta.validation.Valid; | |
6 | ||
7 | import lombok.RequiredArgsConstructor; | |
8 | ||
9 | import org.springframework.data.domain.Sort; | |
10 | import org.springframework.http.ResponseEntity; | |
11 | import org.springframework.validation.annotation.Validated; | |
12 | import org.springframework.web.bind.annotation.GetMapping; | |
13 | import org.springframework.web.bind.annotation.PathVariable; | |
14 | import org.springframework.web.bind.annotation.RequestMapping; | |
15 | import org.springframework.web.bind.annotation.RestController; | |
16 | ||
17 | import io.swagger.v3.oas.annotations.Operation; | |
18 | import io.swagger.v3.oas.annotations.Parameter; | |
19 | import io.swagger.v3.oas.annotations.tags.Tag; | |
20 | import org.springdoc.core.annotations.ParameterObject; | |
21 | ||
22 | import org.cardanofoundation.explorer.api.common.constant.CommonConstant; | |
23 | import org.cardanofoundation.explorer.api.common.enumeration.AnalyticType; | |
24 | import org.cardanofoundation.explorer.api.config.LogMessage; | |
25 | import org.cardanofoundation.explorer.api.controller.validation.StakeKeyLengthValid; | |
26 | import org.cardanofoundation.explorer.api.model.response.BaseFilterResponse; | |
27 | import org.cardanofoundation.explorer.api.model.response.StakeAnalyticResponse; | |
28 | import org.cardanofoundation.explorer.api.model.response.TxFilterResponse; | |
29 | import org.cardanofoundation.explorer.api.model.response.address.AddressChartBalanceResponse; | |
30 | import org.cardanofoundation.explorer.api.model.response.address.AddressFilterResponse; | |
31 | import org.cardanofoundation.explorer.api.model.response.address.StakeAddressResponse; | |
32 | import org.cardanofoundation.explorer.api.model.response.address.StakeAddressRewardDistribution; | |
33 | import org.cardanofoundation.explorer.api.model.response.stake.StakeAnalyticRewardResponse; | |
34 | import org.cardanofoundation.explorer.api.model.response.stake.StakeTxResponse; | |
35 | import org.cardanofoundation.explorer.api.projection.StakeDelegationProjection; | |
36 | import org.cardanofoundation.explorer.api.projection.StakeHistoryProjection; | |
37 | import org.cardanofoundation.explorer.api.projection.StakeInstantaneousRewardsProjection; | |
38 | import org.cardanofoundation.explorer.api.projection.StakeWithdrawalProjection; | |
39 | import org.cardanofoundation.explorer.api.service.StakeKeyService; | |
40 | import org.cardanofoundation.explorer.api.service.TxService; | |
41 | import org.cardanofoundation.explorer.common.entity.ledgersync.StakeDeregistration_; | |
42 | import org.cardanofoundation.explorer.common.entity.ledgersync.StakeRegistration_; | |
43 | import org.cardanofoundation.explorer.common.entity.ledgersyncsagg.AddressTxAmount_; | |
44 | import org.cardanofoundation.explorer.common.validation.pagination.Pagination; | |
45 | import org.cardanofoundation.explorer.common.validation.pagination.PaginationDefault; | |
46 | import org.cardanofoundation.explorer.common.validation.pagination.PaginationValid; | |
47 | import org.cardanofoundation.explorer.common.validation.prefixed.PrefixedValid; | |
48 | ||
49 | @RestController | |
50 | @RequestMapping("/api/v1/stakes") | |
51 | @RequiredArgsConstructor | |
52 | @Validated | |
53 | @Tag(name = "stake-key", description = "The Stake Key APIs") | |
54 | public class StakeKeyController { | |
55 | ||
56 | private final StakeKeyService stakeService; | |
57 | ||
58 | private final TxService txService; | |
59 | ||
60 | @GetMapping("/registration") | |
61 | @LogMessage | |
62 | @Operation(summary = "Get stake key registration", tags = "stake-key") | |
63 | public ResponseEntity<BaseFilterResponse<StakeTxResponse>> getDataForStakeRegistration( | |
64 | @ParameterObject | |
65 | @PaginationValid | |
66 | @PaginationDefault( | |
67 | size = 20, | |
68 | sort = {StakeRegistration_.TX_ID}, | |
69 | direction = Sort.Direction.DESC) | |
70 | @Valid | |
71 | Pagination pagination) { | |
72 |
1
1. getDataForStakeRegistration : replaced return value with null for org/cardanofoundation/explorer/api/controller/StakeKeyController::getDataForStakeRegistration → KILLED |
return ResponseEntity.ok(stakeService.getDataForStakeKeyRegistration(pagination.toPageable())); |
73 | } | |
74 | ||
75 | @GetMapping("/de-registration") | |
76 | @LogMessage | |
77 | @Operation(summary = "Get stake key de-registration", tags = "stake-key") | |
78 | public ResponseEntity<BaseFilterResponse<StakeTxResponse>> getDataForStakeDeRegistration( | |
79 | @ParameterObject | |
80 | @PaginationValid | |
81 | @PaginationDefault( | |
82 | size = 20, | |
83 | sort = {StakeDeregistration_.TX_ID}, | |
84 | direction = Sort.Direction.DESC) | |
85 | @Valid | |
86 | Pagination pagination) { | |
87 |
1
1. getDataForStakeDeRegistration : replaced return value with null for org/cardanofoundation/explorer/api/controller/StakeKeyController::getDataForStakeDeRegistration → KILLED |
return ResponseEntity.ok( |
88 | stakeService.getDataForStakeKeyDeRegistration(pagination.toPageable())); | |
89 | } | |
90 | ||
91 | @GetMapping("/address/{address}") | |
92 | @LogMessage | |
93 | @Operation(summary = "Get a stake detail by payment address", tags = "stake-key") | |
94 | public ResponseEntity<StakeAddressResponse> getStakeDetailByAddress( | |
95 | @PathVariable | |
96 | @Parameter( | |
97 | description = | |
98 | "The human readable encoding of the output address." | |
99 | + " Will be Base58 for Byron era addresses and Bech32 for Shelley era.") | |
100 | String address) { | |
101 |
1
1. getStakeDetailByAddress : replaced return value with null for org/cardanofoundation/explorer/api/controller/StakeKeyController::getStakeDetailByAddress → KILLED |
return ResponseEntity.ok(stakeService.getStakeByAddress(address)); |
102 | } | |
103 | ||
104 | @GetMapping("/{stakeKey}") | |
105 | @LogMessage | |
106 | @Operation(summary = "Get a stake detail by stake key", tags = "stake-key") | |
107 | public ResponseEntity<StakeAddressResponse> getStakeDetail( | |
108 | @PathVariable | |
109 | @StakeKeyLengthValid | |
110 | @Parameter(description = "The Bech32 encoded version of the stake address.") | |
111 | String stakeKey) { | |
112 |
1
1. getStakeDetail : replaced return value with null for org/cardanofoundation/explorer/api/controller/StakeKeyController::getStakeDetail → KILLED |
return ResponseEntity.ok(stakeService.getStake(stakeKey)); |
113 | } | |
114 | ||
115 | @GetMapping("/{stakeKey}/txs") | |
116 | @LogMessage | |
117 | @Operation(summary = "Get transactions of stake key", tags = "stake-key") | |
118 | public ResponseEntity<BaseFilterResponse<TxFilterResponse>> getTransactions( | |
119 | @PathVariable | |
120 | @PrefixedValid(CommonConstant.PREFIXED_STAKE_KEY) | |
121 | @StakeKeyLengthValid | |
122 | @Parameter(description = "The Bech32 encoded version of the stake address.") | |
123 | String stakeKey, | |
124 | @ParameterObject | |
125 | @PaginationDefault( | |
126 | size = 20, | |
127 | sort = {AddressTxAmount_.SLOT}, | |
128 | direction = Sort.Direction.DESC) | |
129 | @PaginationValid | |
130 | @Valid | |
131 | Pagination pagination) { | |
132 |
1
1. getTransactions : replaced return value with null for org/cardanofoundation/explorer/api/controller/StakeKeyController::getTransactions → NO_COVERAGE |
return ResponseEntity.ok(txService.getTransactionsByStake(stakeKey, pagination.toPageable())); |
133 | } | |
134 | ||
135 | @GetMapping("/{stakeKey}/delegation-history") | |
136 | @LogMessage | |
137 | @Operation(summary = "Get delegation history of stake key", tags = "stake-key") | |
138 | public ResponseEntity<BaseFilterResponse<StakeDelegationProjection>> getDelegationHistories( | |
139 | @PathVariable | |
140 | @PrefixedValid(CommonConstant.PREFIXED_STAKE_KEY) | |
141 | @StakeKeyLengthValid | |
142 | @Parameter(description = "The Bech32 encoded version of the stake address.") | |
143 | String stakeKey, | |
144 | @ParameterObject @PaginationValid @Valid Pagination pagination) { | |
145 |
1
1. getDelegationHistories : replaced return value with null for org/cardanofoundation/explorer/api/controller/StakeKeyController::getDelegationHistories → KILLED |
return ResponseEntity.ok( |
146 | stakeService.getDelegationHistories(stakeKey, pagination.toPageable())); | |
147 | } | |
148 | ||
149 | @GetMapping("/{stakeKey}/stake-history") | |
150 | @LogMessage | |
151 | @Operation(summary = "Get stake history of stake key", tags = "stake-key") | |
152 | public ResponseEntity<BaseFilterResponse<StakeHistoryProjection>> getStakeHistories( | |
153 | @PathVariable | |
154 | @PrefixedValid(CommonConstant.PREFIXED_STAKE_KEY) | |
155 | @StakeKeyLengthValid | |
156 | @Parameter(description = "The Bech32 encoded version of the stake address.") | |
157 | String stakeKey, | |
158 | @ParameterObject @PaginationValid @Valid Pagination pagination) { | |
159 |
1
1. getStakeHistories : replaced return value with null for org/cardanofoundation/explorer/api/controller/StakeKeyController::getStakeHistories → KILLED |
return ResponseEntity.ok(stakeService.getStakeHistories(stakeKey, pagination.toPageable())); |
160 | } | |
161 | ||
162 | @GetMapping("/{stakeKey}/withdrawal-history") | |
163 | @LogMessage | |
164 | @Operation(summary = "Get withdrawal transaction of stake key", tags = "stake-key") | |
165 | public BaseFilterResponse<StakeWithdrawalProjection> getWithdrawalHistories( | |
166 | @PathVariable | |
167 | @PrefixedValid(CommonConstant.PREFIXED_STAKE_KEY) | |
168 | @StakeKeyLengthValid | |
169 | @Parameter(description = "The Bech32 encoded version of the stake address.") | |
170 | String stakeKey, | |
171 | @ParameterObject @PaginationValid @Valid Pagination pagination) { | |
172 |
1
1. getWithdrawalHistories : replaced return value with null for org/cardanofoundation/explorer/api/controller/StakeKeyController::getWithdrawalHistories → KILLED |
return stakeService.getWithdrawalHistories(stakeKey, pagination.toPageable()); |
173 | } | |
174 | ||
175 | @GetMapping("/{stakeKey}/instantaneous-rewards") | |
176 | @LogMessage | |
177 | @Operation(summary = "Get reward transaction of stake key", tags = "stake-key") | |
178 | public BaseFilterResponse<StakeInstantaneousRewardsProjection> getInstantaneousRewards( | |
179 | @PathVariable | |
180 | @PrefixedValid(CommonConstant.PREFIXED_STAKE_KEY) | |
181 | @StakeKeyLengthValid | |
182 | @Parameter(description = "The Bech32 encoded version of the stake address.") | |
183 | String stakeKey, | |
184 | @ParameterObject @PaginationValid @Valid Pagination pagination) { | |
185 |
1
1. getInstantaneousRewards : replaced return value with null for org/cardanofoundation/explorer/api/controller/StakeKeyController::getInstantaneousRewards → KILLED |
return stakeService.getInstantaneousRewards(stakeKey, pagination.toPageable()); |
186 | } | |
187 | ||
188 | @GetMapping("/{stakeKey}/list-address") | |
189 | @LogMessage | |
190 | @Operation(summary = "Get all address of stake", tags = "stake-key") | |
191 | public ResponseEntity<BaseFilterResponse<AddressFilterResponse>> getAddresses( | |
192 | @PathVariable | |
193 | @PrefixedValid(CommonConstant.PREFIXED_STAKE_KEY) | |
194 | @StakeKeyLengthValid | |
195 | @Parameter(description = "The Bech32 encoded version of the stake address.") | |
196 | String stakeKey, | |
197 | @ParameterObject @Valid Pagination pagination) { | |
198 |
1
1. getAddresses : replaced return value with null for org/cardanofoundation/explorer/api/controller/StakeKeyController::getAddresses → KILLED |
return ResponseEntity.ok(stakeService.getAddresses(stakeKey, pagination.toPageable())); |
199 | } | |
200 | ||
201 | @GetMapping("/analytics") | |
202 | @LogMessage | |
203 | @Operation(summary = "Get active stake, live stake and total stake", tags = "stake-key") | |
204 | public ResponseEntity<StakeAnalyticResponse> getStakeAnalytics() { | |
205 |
1
1. getStakeAnalytics : replaced return value with null for org/cardanofoundation/explorer/api/controller/StakeKeyController::getStakeAnalytics → KILLED |
return ResponseEntity.ok(stakeService.getStakeAnalytics()); |
206 | } | |
207 | ||
208 | @GetMapping("/analytics-balance/{stakeKey}/{type}") | |
209 | @LogMessage | |
210 | @Operation(summary = "Get stake balance analytics", tags = "stake-key") | |
211 | public ResponseEntity<AddressChartBalanceResponse> getStakeBalanceAnalytics( | |
212 | @PathVariable | |
213 | @PrefixedValid(CommonConstant.PREFIXED_STAKE_KEY) | |
214 | @StakeKeyLengthValid | |
215 | @Parameter(description = "The Bech32 encoded version of the stake address.") | |
216 | String stakeKey, | |
217 | @PathVariable @Parameter(description = "Type analytics: 1d, 1w, 1m, 3m") AnalyticType type) { | |
218 |
1
1. getStakeBalanceAnalytics : replaced return value with null for org/cardanofoundation/explorer/api/controller/StakeKeyController::getStakeBalanceAnalytics → KILLED |
return ResponseEntity.ok(stakeService.getStakeBalanceAnalytics(stakeKey, type)); |
219 | } | |
220 | ||
221 | @GetMapping("/analytics-reward/{stakeKey}") | |
222 | @LogMessage | |
223 | @Operation(summary = "Get stake balance analytics", tags = "stake-key") | |
224 | public ResponseEntity<List<StakeAnalyticRewardResponse>> getStakeRewardAnalytics( | |
225 | @PathVariable | |
226 | @PrefixedValid(CommonConstant.PREFIXED_STAKE_KEY) | |
227 | @StakeKeyLengthValid | |
228 | @Parameter(description = "The Bech32 encoded version of the stake address.") | |
229 | String stakeKey) { | |
230 |
1
1. getStakeRewardAnalytics : replaced return value with null for org/cardanofoundation/explorer/api/controller/StakeKeyController::getStakeRewardAnalytics → KILLED |
return ResponseEntity.ok(stakeService.getStakeRewardAnalytics(stakeKey)); |
231 | } | |
232 | ||
233 | @GetMapping("/reward-distribution/{stakeKey}") | |
234 | @LogMessage | |
235 | @Operation(summary = "Get reward distribution information", tags = "stake-key") | |
236 | public ResponseEntity<StakeAddressRewardDistribution> getStakeAddressRewardDistributionInfo( | |
237 | @PathVariable | |
238 | @PrefixedValid(CommonConstant.PREFIXED_STAKE_KEY) | |
239 | @StakeKeyLengthValid | |
240 | @Parameter(description = "The Bech32 encoded version of the stake address.") | |
241 | String stakeKey) { | |
242 |
1
1. getStakeAddressRewardDistributionInfo : replaced return value with null for org/cardanofoundation/explorer/api/controller/StakeKeyController::getStakeAddressRewardDistributionInfo → KILLED |
return ResponseEntity.ok(stakeService.getStakeAddressRewardDistributionInfo(stakeKey)); |
243 | } | |
244 | } | |
Mutations | ||
72 |
1.1 |
|
87 |
1.1 |
|
101 |
1.1 |
|
112 |
1.1 |
|
132 |
1.1 |
|
145 |
1.1 |
|
159 |
1.1 |
|
172 |
1.1 |
|
185 |
1.1 |
|
198 |
1.1 |
|
205 |
1.1 |
|
218 |
1.1 |
|
230 |
1.1 |
|
242 |
1.1 |