1 | package org.cardanofoundation.explorer.api.controller; | |
2 | ||
3 | import java.util.Set; | |
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.*; | |
13 | ||
14 | import io.swagger.v3.oas.annotations.Operation; | |
15 | import io.swagger.v3.oas.annotations.Parameter; | |
16 | import io.swagger.v3.oas.annotations.tags.Tag; | |
17 | import org.springdoc.core.annotations.ParameterObject; | |
18 | ||
19 | import org.cardanofoundation.explorer.api.config.LogMessage; | |
20 | import org.cardanofoundation.explorer.api.model.request.script.nativescript.NativeScriptFilterRequest; | |
21 | import org.cardanofoundation.explorer.api.model.request.script.smartcontract.SmartContractFilterRequest; | |
22 | import org.cardanofoundation.explorer.api.model.response.BaseFilterResponse; | |
23 | import org.cardanofoundation.explorer.api.model.response.script.nativescript.NativeScriptFilterResponse; | |
24 | import org.cardanofoundation.explorer.api.model.response.script.nativescript.NativeScriptResponse; | |
25 | import org.cardanofoundation.explorer.api.model.response.script.smartcontract.SmartContractDetailResponse; | |
26 | import org.cardanofoundation.explorer.api.model.response.script.smartcontract.SmartContractFilterResponse; | |
27 | import org.cardanofoundation.explorer.api.model.response.script.smartcontract.SmartContractTxResponse; | |
28 | import org.cardanofoundation.explorer.api.model.response.search.ScriptSearchResponse; | |
29 | import org.cardanofoundation.explorer.api.model.response.token.TokenAddressResponse; | |
30 | import org.cardanofoundation.explorer.api.model.response.token.TokenFilterResponse; | |
31 | import org.cardanofoundation.explorer.api.service.ScriptService; | |
32 | import org.cardanofoundation.explorer.common.entity.explorer.NativeScriptInfo_; | |
33 | import org.cardanofoundation.explorer.common.entity.ledgersync.TokenTxCount_; | |
34 | import org.cardanofoundation.explorer.common.entity.ledgersyncsagg.LatestTokenBalance_; | |
35 | import org.cardanofoundation.explorer.common.validation.pagination.Pagination; | |
36 | import org.cardanofoundation.explorer.common.validation.pagination.PaginationDefault; | |
37 | import org.cardanofoundation.explorer.common.validation.pagination.PaginationValid; | |
38 | ||
39 | @RestController | |
40 | @RequestMapping("/api/v1/scripts") | |
41 | @RequiredArgsConstructor | |
42 | @Validated | |
43 | @Tag(name = "script", description = "The script APIs") | |
44 | public class ScriptController { | |
45 | ||
46 | private final ScriptService scriptService; | |
47 | ||
48 | @GetMapping("/native-scripts") | |
49 | @LogMessage | |
50 | public ResponseEntity<BaseFilterResponse<NativeScriptFilterResponse>> getNativeScripts( | |
51 | @ParameterObject | |
52 | @PaginationValid | |
53 | @PaginationDefault( | |
54 | size = 20, | |
55 | sort = {NativeScriptInfo_.NUMBER_OF_ASSET_HOLDERS}, | |
56 | direction = Sort.Direction.DESC) | |
57 | @Valid | |
58 | Pagination pagination, | |
59 | @ParameterObject @Parameter(description = "filter condition") | |
60 | NativeScriptFilterRequest filterRequest) { | |
61 |
1
1. getNativeScripts : replaced return value with null for org/cardanofoundation/explorer/api/controller/ScriptController::getNativeScripts → KILLED |
return ResponseEntity.ok( |
62 | scriptService.getNativeScripts(filterRequest, pagination.toPageable())); | |
63 | } | |
64 | ||
65 | @GetMapping("/native-scripts/{scriptHash}") | |
66 | @LogMessage | |
67 | public ResponseEntity<NativeScriptResponse> getNativeScriptDetail( | |
68 | @PathVariable String scriptHash) { | |
69 |
1
1. getNativeScriptDetail : replaced return value with null for org/cardanofoundation/explorer/api/controller/ScriptController::getNativeScriptDetail → KILLED |
return ResponseEntity.ok(scriptService.getNativeScriptDetail(scriptHash)); |
70 | } | |
71 | ||
72 | @PostMapping("/native-scripts/{scriptHash}/verify") | |
73 | @LogMessage | |
74 | @Operation(summary = "Verify native scrip contract") | |
75 | public ResponseEntity<String> verifyContract( | |
76 | @PathVariable String scriptHash, @RequestBody String jsonScript) { | |
77 |
1
1. verifyContract : replaced return value with null for org/cardanofoundation/explorer/api/controller/ScriptController::verifyContract → KILLED |
return ResponseEntity.ok(scriptService.verifyNativeScript(scriptHash, jsonScript)); |
78 | } | |
79 | ||
80 | @GetMapping("/native-scripts/{scriptHash}/tokens") | |
81 | @LogMessage | |
82 | @Operation(summary = "Get tokens of a policy", description = "Get all tokens of a policy") | |
83 | public ResponseEntity<BaseFilterResponse<TokenFilterResponse>> getTokens( | |
84 | @PathVariable @Parameter(description = "The native script hash") String scriptHash, | |
85 | @ParameterObject | |
86 | @PaginationValid | |
87 | @PaginationDefault( | |
88 | size = 20, | |
89 | sort = {TokenTxCount_.TX_COUNT}, | |
90 | direction = Sort.Direction.DESC) | |
91 | @Valid | |
92 | Pagination pagination) { | |
93 |
1
1. getTokens : replaced return value with null for org/cardanofoundation/explorer/api/controller/ScriptController::getTokens → KILLED |
return ResponseEntity.ok( |
94 | scriptService.getNativeScriptTokens(scriptHash, pagination.toPageable())); | |
95 | } | |
96 | ||
97 | @GetMapping("/native-scripts/{scriptHash}/holders") | |
98 | @LogMessage | |
99 | @Operation( | |
100 | summary = "Get holders by policy", | |
101 | description = "Get all holders of all tokens of policy") | |
102 | public ResponseEntity<BaseFilterResponse<TokenAddressResponse>> getHolders( | |
103 | @PathVariable @Parameter(description = "The native script hash") String scriptHash, | |
104 | @ParameterObject | |
105 | @PaginationValid | |
106 | @PaginationDefault( | |
107 | size = 20, | |
108 | sort = {LatestTokenBalance_.QUANTITY}, | |
109 | direction = Sort.Direction.DESC) | |
110 | @Valid | |
111 | Pagination pagination) { | |
112 |
1
1. getHolders : replaced return value with null for org/cardanofoundation/explorer/api/controller/ScriptController::getHolders → KILLED |
return ResponseEntity.ok( |
113 | scriptService.getNativeScriptHolders(scriptHash, pagination.toPageable())); | |
114 | } | |
115 | ||
116 | @GetMapping("/contracts") | |
117 | public ResponseEntity<BaseFilterResponse<SmartContractFilterResponse>> getSmartContracts( | |
118 | @ParameterObject @Parameter(description = "filter condition") | |
119 | SmartContractFilterRequest filterRequest, | |
120 | @ParameterObject | |
121 | @PaginationValid | |
122 | @PaginationDefault( | |
123 | size = 20, | |
124 | sort = {"txCount"}, | |
125 | direction = Sort.Direction.DESC) | |
126 | @Valid | |
127 | Pagination pagination) { | |
128 |
1
1. getSmartContracts : replaced return value with null for org/cardanofoundation/explorer/api/controller/ScriptController::getSmartContracts → KILLED |
return ResponseEntity.ok( |
129 | scriptService.getSmartContracts(filterRequest, pagination.toPageable())); | |
130 | } | |
131 | ||
132 | @GetMapping("/contracts/{scriptHash}") | |
133 | @LogMessage | |
134 | @Operation( | |
135 | summary = "Get smart contract detail", | |
136 | tags = {"script"}) | |
137 | public ResponseEntity<SmartContractDetailResponse> getSmartContracts( | |
138 | @PathVariable @Parameter(description = "The script hash") String scriptHash) { | |
139 |
1
1. getSmartContracts : replaced return value with null for org/cardanofoundation/explorer/api/controller/ScriptController::getSmartContracts → KILLED |
return ResponseEntity.ok(scriptService.getSmartContractDetail(scriptHash)); |
140 | } | |
141 | ||
142 | @GetMapping("/contracts/{scriptHash}/txs") | |
143 | @LogMessage | |
144 | @Operation( | |
145 | summary = "Get transactions interact with smart contract", | |
146 | tags = {"script"}) | |
147 | public ResponseEntity<BaseFilterResponse<SmartContractTxResponse>> getSmartContractsTxs( | |
148 | @PathVariable @Parameter(description = "The script hash") String scriptHash, | |
149 | @ParameterObject | |
150 | @PaginationValid | |
151 | @PaginationDefault( | |
152 | size = 20, | |
153 | sort = {"tx.id"}, | |
154 | direction = Sort.Direction.DESC) | |
155 | @Valid | |
156 | Pagination pagination) { | |
157 |
1
1. getSmartContractsTxs : replaced return value with null for org/cardanofoundation/explorer/api/controller/ScriptController::getSmartContractsTxs → KILLED |
return ResponseEntity.ok( |
158 | scriptService.getSmartContractTxs(scriptHash, pagination.toPageable())); | |
159 | } | |
160 | ||
161 | @GetMapping("/contract-executions/{txHash}/{scriptHash}") | |
162 | @LogMessage | |
163 | @Operation( | |
164 | summary = "Get smart contract execution detail", | |
165 | tags = {"script"}) | |
166 | public ResponseEntity<Set<String>> getSmartContractExecutionDetail( | |
167 | @PathVariable @Parameter(description = "The transaction hash") String txHash, | |
168 | @PathVariable @Parameter(description = "The script hash") String scriptHash) { | |
169 |
1
1. getSmartContractExecutionDetail : replaced return value with null for org/cardanofoundation/explorer/api/controller/ScriptController::getSmartContractExecutionDetail → KILLED |
return ResponseEntity.ok(scriptService.getContractExecutions(txHash, scriptHash)); |
170 | } | |
171 | ||
172 | @GetMapping("/search/{scriptHash}") | |
173 | @LogMessage | |
174 | @Operation( | |
175 | summary = "Search script by script hash", | |
176 | tags = {"script"}) | |
177 | public ResponseEntity<ScriptSearchResponse> getScriptByHash( | |
178 | @PathVariable @Parameter(description = "The script hash") String scriptHash) { | |
179 |
1
1. getScriptByHash : replaced return value with null for org/cardanofoundation/explorer/api/controller/ScriptController::getScriptByHash → KILLED |
return ResponseEntity.ok(scriptService.searchScript(scriptHash)); |
180 | } | |
181 | } | |
Mutations | ||
61 |
1.1 |
|
69 |
1.1 |
|
77 |
1.1 |
|
93 |
1.1 |
|
112 |
1.1 |
|
128 |
1.1 |
|
139 |
1.1 |
|
157 |
1.1 |
|
169 |
1.1 |
|
179 |
1.1 |