-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MEED-3806 Add ERC20 verification token API
- Loading branch information
1 parent
5c2a4b7
commit 12090b0
Showing
4 changed files
with
145 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
gamification-evm-services/src/main/java/io/meeds/gamification/evm/model/ERC20Token.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.meeds.gamification.evm.model; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.math.BigInteger; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class ERC20Token { | ||
|
||
private String name; | ||
|
||
private String symbol; | ||
|
||
private BigInteger totalSupply; | ||
|
||
private BigInteger decimals; | ||
} |
45 changes: 45 additions & 0 deletions
45
gamification-evm-services/src/main/java/io/meeds/gamification/evm/rest/TokensController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package io.meeds.gamification.evm.rest; | ||
|
||
import io.meeds.gamification.evm.model.ERC20Token; | ||
import io.meeds.gamification.evm.service.BlockchainService; | ||
import org.exoplatform.commons.exception.ObjectNotFoundException; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.server.ResponseStatusException; | ||
|
||
import java.io.IOException; | ||
|
||
@RestController | ||
@RequestMapping("tokens") | ||
public class TokensController { | ||
|
||
@Autowired | ||
BlockchainService blockchainService; | ||
|
||
@GetMapping | ||
@Operation(summary = "Retrieves ERC20 Token details", method = "GET") | ||
@ApiResponse(responseCode = "200", description = "Request fulfilled") | ||
@ApiResponse(responseCode = "404", description = "Not found") | ||
@ApiResponse(responseCode = "503", description = "Service unavailable") | ||
public ERC20Token getERC20Token(@Parameter(description = "erc20 contract address", required = true) | ||
@RequestParam("contractAddress") | ||
String contractAddress) { | ||
if (contractAddress == null) { | ||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Contract address is missing"); | ||
} | ||
try { | ||
return blockchainService.getERC20TokenDetails(contractAddress); | ||
} catch (IOException e) { | ||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "ERC20 doesn't exist"); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters