From 7d9144fa49d7fc5abaf1873d24cfb2fc4a39bd65 Mon Sep 17 00:00:00 2001 From: Oleg Zhymolokhov Date: Fri, 14 Sep 2018 12:58:19 +0300 Subject: [PATCH] refactoring: Changed error handling of the signed transaction. --- .../controller/TransactionController.java | 2 +- .../walletservice/dto/SignedTransactionDto.java | 2 +- .../nynja/walletservice/service/Web3JService.java | 12 ++++++++---- src/main/resources/application.yml | 2 +- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/nynja/walletservice/controller/TransactionController.java b/src/main/java/com/nynja/walletservice/controller/TransactionController.java index 89f5cd7..babf256 100644 --- a/src/main/java/com/nynja/walletservice/controller/TransactionController.java +++ b/src/main/java/com/nynja/walletservice/controller/TransactionController.java @@ -57,7 +57,7 @@ public class TransactionController { @ApiResponse(code = 200, message = RETRIEVED) @PostMapping(API_VERSION + "/signed-transaction-send") public CompletableFuture>> sendSignedTransaction(@Valid @RequestBody SignedTransactionDto dto) { - return web3JService.sendSignedTransaction(dto.getBase64Transaction()).thenApplyAsync(ResponseEntity::ok); + return web3JService.sendSignedTransaction(dto.getSignedTransaction()).thenApplyAsync(ResponseEntity::ok); } @ApiOperation(value = "Endpoint for getting transaction info by hash", httpMethod = "GET") diff --git a/src/main/java/com/nynja/walletservice/dto/SignedTransactionDto.java b/src/main/java/com/nynja/walletservice/dto/SignedTransactionDto.java index 7fd85b0..01537d7 100644 --- a/src/main/java/com/nynja/walletservice/dto/SignedTransactionDto.java +++ b/src/main/java/com/nynja/walletservice/dto/SignedTransactionDto.java @@ -15,5 +15,5 @@ import org.hibernate.validator.constraints.NotBlank; public class SignedTransactionDto { @NotBlank - private String base64Transaction; + private String signedTransaction; } diff --git a/src/main/java/com/nynja/walletservice/service/Web3JService.java b/src/main/java/com/nynja/walletservice/service/Web3JService.java index 0c30498..9294b5e 100644 --- a/src/main/java/com/nynja/walletservice/service/Web3JService.java +++ b/src/main/java/com/nynja/walletservice/service/Web3JService.java @@ -78,12 +78,16 @@ public class Web3JService { return web3j().ethGetBalance(address, DefaultBlockParameterName.LATEST).sendAsync(); } - public CompletableFuture> sendSignedTransaction(String base64Transaction) { - return web3j().ethSendRawTransaction(base64Transaction) + public CompletableFuture> sendSignedTransaction(String transaction) { + return web3j().ethSendRawTransaction(transaction) .sendAsync() .thenApplyAsync(ethSendTransaction -> { - log.info(SIGNED_TRANSACTION_SENT, ethSendTransaction.getTransactionHash()); - return new TransactionResponseDto<>(ethSendTransaction.getTransactionHash(), ""); + if (ethSendTransaction.getError() != null) { + throw new RuntimeException(ethSendTransaction.getError().getMessage()); + } else { + log.info(SIGNED_TRANSACTION_SENT, ethSendTransaction.getTransactionHash()); + return new TransactionResponseDto<>(ethSendTransaction.getTransactionHash(), ""); + } }).exceptionally(ex -> { log.error(SIGNED_TRANSACTION_FAIL, ex.getMessage()); return new TransactionResponseDto<>(TRANSACTION_FAILED, ex.getMessage()); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index a6192b7..c9bd497 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -25,7 +25,7 @@ ethereum: private-key: "960d1cad3ad7c42251f79c31e15636915f953cbfff1770cc4483efa44bf4ffc9" contract: # First deploy a contract and then place/replace it's address into this property - nynja-coin-address: "0x812e97c042632982b7cbd1c2818577602e646b1e" + nynja-coin-address: "0x5c015d5b7490cc329b96aebfb9d8e5ebd78e2bf6" gas-price: 2000000000000 gas-limit: 4700000 etherscan: -- GitLab