diff --git a/src/main/java/com/nynja/walletservice/controller/TransactionController.java b/src/main/java/com/nynja/walletservice/controller/TransactionController.java index 4d8c30d4e43048051a594d144f83bc58e27a00d3..a7fe092f08a7376167aca5fb5f4714fd93e06637 100644 --- a/src/main/java/com/nynja/walletservice/controller/TransactionController.java +++ b/src/main/java/com/nynja/walletservice/controller/TransactionController.java @@ -17,7 +17,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import org.web3j.protocol.core.methods.response.EthEstimateGas; import org.web3j.protocol.core.methods.response.TransactionReceipt; import javax.validation.Valid; @@ -105,7 +104,7 @@ public class TransactionController { @ApiOperation(value = "Endpoint for transaction gas price estimation", httpMethod = "POST") @ApiResponse(code = 200, message = RETRIEVED) @PostMapping(API_VERSION + "/estimate-gas-price") - public CompletableFuture> estimateGasPrice(@RequestBody EstimateGasDto dto) { - return web3JService.estimateGas(dto).thenApplyAsync(ResponseEntity::ok); + public CompletableFuture> estimateGasPrice(@RequestBody EstimateGasDto dto) { + return web3JService.estimateGasPrice(dto).thenApplyAsync(ResponseEntity::ok); } } diff --git a/src/main/java/com/nynja/walletservice/service/Web3JService.java b/src/main/java/com/nynja/walletservice/service/Web3JService.java index 440b3fe74275cd5d66719f58e505131c0d3d40ce..9ad63f3821bba4fb036b2685bf7ed0916da59c07 100644 --- a/src/main/java/com/nynja/walletservice/service/Web3JService.java +++ b/src/main/java/com/nynja/walletservice/service/Web3JService.java @@ -104,7 +104,7 @@ public class Web3JService { .thenApplyAsync(EthGetTransactionCount::getTransactionCount); } - public CompletableFuture estimateGas(EstimateGasDto dto) { + public CompletableFuture estimateGasPrice(EstimateGasDto dto) { return web3j().ethEstimateGas(new org.web3j.protocol.core.methods.request.Transaction( dto.getFrom(), null, @@ -113,7 +113,10 @@ public class Web3JService { dto.getTo(), dto.getValue(), dto.getData() - )).sendAsync(); + )).sendAsync().thenComposeAsync(ethEstimateGas -> web3j().ethGasPrice().sendAsync() + .thenApplyAsync(ethGasPrice -> + ethGasPrice.getGasPrice().multiply(ethEstimateGas.getAmountUsed())) + ); } private Web3j web3j() {