From f85469b5d5e0ea77c91cd7eea31fb7a435eaff9f Mon Sep 17 00:00:00 2001 From: Jayendra Date: Thu, 19 Sep 2019 17:46:52 +0530 Subject: [PATCH] Added coin conversion price API --- .../walletservice/constant/Constants.java | 10 +- .../controller/TokenControllerV2.java | 107 +++++++++++++++- .../controller/WalletControllerV2.java | 56 +++++++++ .../exception/GlobalExceptionHandler.java | 5 + .../walletservice/util/RestTemplateUtil.java | 30 ++++- .../nynja/walletservice/util/Web3JUtils.java | 18 +++ .../websocket/ApplicationContextUtil.java | 22 ++++ .../websocket/NYN_BTCConversion.java | 114 ++++++++++++++++++ .../websocket/NYN_ETHConversion.java | 112 +++++++++++++++++ .../walletservice/websocket/WSClient.java | 92 ++++++++++++++ .../walletservice/websocket/WSConfig.java | 34 ++++++ src/main/resources/application.yml | 6 +- 12 files changed, 597 insertions(+), 9 deletions(-) create mode 100644 src/main/java/com/nynja/walletservice/controller/WalletControllerV2.java create mode 100644 src/main/java/com/nynja/walletservice/websocket/ApplicationContextUtil.java create mode 100644 src/main/java/com/nynja/walletservice/websocket/NYN_BTCConversion.java create mode 100644 src/main/java/com/nynja/walletservice/websocket/NYN_ETHConversion.java create mode 100644 src/main/java/com/nynja/walletservice/websocket/WSClient.java create mode 100644 src/main/java/com/nynja/walletservice/websocket/WSConfig.java diff --git a/src/main/java/com/nynja/walletservice/constant/Constants.java b/src/main/java/com/nynja/walletservice/constant/Constants.java index 6297186..d820e4d 100644 --- a/src/main/java/com/nynja/walletservice/constant/Constants.java +++ b/src/main/java/com/nynja/walletservice/constant/Constants.java @@ -10,7 +10,10 @@ public interface Constants { interface HttpStatus { short SUCCESS_STATUS_CODE = 200; - + short FORBIDDEN_STATUS_CODE = 403; + short UNAUTHORIZED_STATUS_CODE = 401; + short BAD_REQUEST_STATUS_CODE = 400; + short SERVICE_UNAVAILABLE_STATUS_CODE = 502; } interface RestApi { @@ -69,4 +72,9 @@ public interface Constants { return () -> new RuntimeException(message); } + interface EtherUnits { + String WEI = "1000000000000000000"; + } + + } diff --git a/src/main/java/com/nynja/walletservice/controller/TokenControllerV2.java b/src/main/java/com/nynja/walletservice/controller/TokenControllerV2.java index 2ed89a7..c1c0e2c 100644 --- a/src/main/java/com/nynja/walletservice/controller/TokenControllerV2.java +++ b/src/main/java/com/nynja/walletservice/controller/TokenControllerV2.java @@ -1,10 +1,14 @@ package com.nynja.walletservice.controller; +import com.fasterxml.jackson.databind.ObjectMapper; import com.nynja.walletservice.config.ConfigValues; import com.nynja.walletservice.constant.Constants; import com.nynja.walletservice.model.network.NetworkProperties; import com.nynja.walletservice.service.Web3JService; import com.nynja.walletservice.util.RestTemplateUtil; +import com.nynja.walletservice.util.Web3JUtils; +import com.nynja.walletservice.websocket.NYN_BTCConversion; +import com.nynja.walletservice.websocket.NYN_ETHConversion; import com.nynja.walletservice.wrapper.NynjaCoin; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -14,6 +18,8 @@ import org.web3j.protocol.core.methods.response.TransactionReceipt; import org.web3j.tx.FastRawTransactionManager; import org.web3j.tx.TransactionManager; import org.web3j.tx.response.NoOpProcessor; + +import java.math.BigDecimal; import java.math.BigInteger; import java.util.HashMap; import java.util.List; @@ -21,6 +27,10 @@ import java.util.Map; import static com.nynja.walletservice.constant.Constants.RestApi.API_VERSION_V2; +/** + * @author Jayendra + */ + @RestController @RequestMapping("/token") public class TokenControllerV2 { @@ -34,6 +44,39 @@ public class TokenControllerV2 { @Autowired private RestTemplateUtil restTemplateUtil; + @Autowired + private ObjectMapper objectMapper; + + @Autowired + private NYN_BTCConversion nyn_btcConversion; + + @Autowired + private NYN_ETHConversion nyn_ethConversion; + + + @GetMapping(API_VERSION_V2 + "/nyn/conversion") + public Map getNynCoinConversion() { + + System.out.println(""); + System.out.println("-------------"); + System.out.println(""); + System.out.println("Get NYN coin conversions"); + System.out.println(""); + System.out.println("-------------"); + System.out.println(""); + + Map conversionMap = new HashMap<>(2); + conversionMap.put("NYN_ETH", nyn_ethConversion); + conversionMap.put("NYN_BTC", nyn_btcConversion); + + Map response = new HashMap<>(3); + response.put("status", Constants.HttpStatus.SUCCESS_STATUS_CODE); + response.put("conversion", conversionMap); + + return response; + + } + @GetMapping(API_VERSION_V2 + "/status") public Map getTransactionStatus(@RequestParam String chainId, @@ -66,6 +109,7 @@ public class TokenControllerV2 { @RequestParam String amount ) throws Exception { + System.out.println(""); System.out.println("------------->>"); System.out.println(""); @@ -79,6 +123,59 @@ public class TokenControllerV2 { System.out.println("------------->>"); System.out.println(""); + // Checking balance for proceeding for transaction. + Map adminEtherBalance = restTemplateUtil.getBalanceByAddressInEther(conf.getNetworkProps(chainId).getAdminAddress(), chainId); + String weiBalance = adminEtherBalance.get("result").toString(); + BigDecimal weiBalanceBD = new BigDecimal(weiBalance); + + BigDecimal etherBalanceBD = weiBalanceBD.divide(new BigDecimal(Constants.EtherUnits.WEI)); + + BigInteger gasPrice = conf.getNetworkProps(chainId).getGasPrice(); + BigInteger gasLimit = conf.getNetworkProps(chainId).getGasLimit(); + + System.out.println("WEI-Balance BD : " + weiBalanceBD); + System.out.println("ETHER-Balance BD : " + etherBalanceBD); + System.out.println("GAS-Price : " + gasPrice); + System.out.println("GAS-Limit : " + gasLimit); + + // Gas required is in ETHERS + BigDecimal requiredEtherGas = Web3JUtils.calculateGasFees(gasPrice, gasLimit); + + System.out.println("Required-Gas (Ethers): " + requiredEtherGas); + System.out.println(""); + + if (etherBalanceBD.compareTo(requiredEtherGas) <= 0) { + System.out.println("Ether balance is insufficient to perform transfer operation"); + System.out.println(""); + + Map response = new HashMap<>(3); + response.put("status", Constants.HttpStatus.UNAUTHORIZED_STATUS_CODE); + response.put("message", "Ether balance is insufficient for gas. So, transfer operation can't be performed."); + + return response; + } + + + // Checking Nynja Coin Balance + Map getNynCoinBalance = restTemplateUtil.getBalanceByAddress(conf.getNetworkProps(chainId).getAdminAddress(), chainId); + String nynBalance = getNynCoinBalance.get("result").toString(); + + BigInteger nynBalanceBD = new BigInteger(nynBalance); + BigInteger amountBD = new BigInteger(amount); + + if (nynBalanceBD.compareTo(amountBD) <= 0) { + System.out.println("Nynja coin balance is insufficient to perform transfer operation"); + System.out.println(""); + + Map response = new HashMap<>(3); + response.put("status", Constants.HttpStatus.UNAUTHORIZED_STATUS_CODE); + response.put("message", "Nynja coins balance is not sufficient."); + + return response; + } + + + // Performing transfer coin operation. Credentials credentials = Credentials.create(conf.getNetworkProps(chainId).getAdminPrivateKey()); Web3j web3j = web3JService.web3j(chainId); NetworkProperties networkProperties = conf.getNetworkProps(chainId); @@ -118,7 +215,7 @@ public class TokenControllerV2 { Map response = new HashMap<>(3); response.put("status", Constants.HttpStatus.SUCCESS_STATUS_CODE); response.put("transaction_id", receipt.getTransactionHash()); - response.put("message", "Transaction will be initiated in 5-10 minutes."); + response.put("message", "Transaction will be initiated in 10-15 minutes."); return response; } @@ -181,7 +278,7 @@ public class TokenControllerV2 { @RequestParam(required = false) String offset, @RequestParam(required = false) String sort - ) { + ) { System.out.println(""); System.out.println("-----------"); System.out.println(""); @@ -202,7 +299,7 @@ public class TokenControllerV2 { System.out.println(transactionHistory.get("status")); System.out.println(""); - if(transactionHistory.get("status").toString().equals("1")) { + if (transactionHistory.get("status").toString().equals("1")) { int count = ((List) transactionHistory.get("result")).size(); System.out.println("Size : " + count); @@ -243,9 +340,9 @@ public class TokenControllerV2 { System.out.println(transactionHistory); System.out.println(""); - if(transactionHistory.get("status").equals("1")){ + if (transactionHistory.get("status").equals("1")) { - int count = ((List)transactionHistory.get("result")).size(); + int count = ((List) transactionHistory.get("result")).size(); System.out.println("Size : " + count); System.out.println(""); diff --git a/src/main/java/com/nynja/walletservice/controller/WalletControllerV2.java b/src/main/java/com/nynja/walletservice/controller/WalletControllerV2.java new file mode 100644 index 0000000..6694046 --- /dev/null +++ b/src/main/java/com/nynja/walletservice/controller/WalletControllerV2.java @@ -0,0 +1,56 @@ +package com.nynja.walletservice.controller; + +import com.nynja.walletservice.config.ConfigValues; +import com.nynja.walletservice.constant.Constants; +import com.nynja.walletservice.model.network.NetworkProperties; +import com.nynja.walletservice.util.RestTemplateUtil; +import com.nynja.walletservice.util.Web3JUtils; +import org.springframework.beans.factory.annotation.Autowired; +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 java.math.BigDecimal; +import java.math.BigInteger; +import java.util.Map; + +import static com.nynja.walletservice.constant.Constants.RestApi.API_VERSION_V2; + + +/** + * @author Jayendra + */ + +@RestController +@RequestMapping("/wallet") +public class WalletControllerV2 { + + @Autowired + private RestTemplateUtil restTemplateUtil; + + @Autowired + private ConfigValues conf; + + @GetMapping(API_VERSION_V2 + "/ether/balance") + public Map getEtherBalanceByAddress(@RequestParam("address") String address, + @RequestParam("chainId") String chainId + ) { + + System.out.println(""); + System.out.println("--------------"); + System.out.println(""); + System.out.println("Get Ether Balance By Address"); + System.out.println(""); + System.out.println("chainId : " + chainId); + System.out.println("address : " + address); + System.out.println(""); + System.out.println("--------------"); + System.out.println(""); + + Map result = restTemplateUtil.getBalanceByAddressInEther(address, chainId); + + return result; + } + +} diff --git a/src/main/java/com/nynja/walletservice/exception/GlobalExceptionHandler.java b/src/main/java/com/nynja/walletservice/exception/GlobalExceptionHandler.java index 4cf5524..6da447b 100644 --- a/src/main/java/com/nynja/walletservice/exception/GlobalExceptionHandler.java +++ b/src/main/java/com/nynja/walletservice/exception/GlobalExceptionHandler.java @@ -52,6 +52,11 @@ public class GlobalExceptionHandler { @ExceptionHandler(MissingServletRequestParameterException.class) public ResponseEntity handle(MissingServletRequestParameterException e) { log.error(e.getMessage(), e); + System.out.println("---------------------------------------"); + System.out.println("MissingServletRequestParameterException"); + e.printStackTrace(); + System.out.println(""); + System.out.println("---------------------------------------"); return compose(HttpStatus.BAD_REQUEST, e.getMessage()); } diff --git a/src/main/java/com/nynja/walletservice/util/RestTemplateUtil.java b/src/main/java/com/nynja/walletservice/util/RestTemplateUtil.java index e01e095..5aea34c 100644 --- a/src/main/java/com/nynja/walletservice/util/RestTemplateUtil.java +++ b/src/main/java/com/nynja/walletservice/util/RestTemplateUtil.java @@ -14,6 +14,9 @@ import org.springframework.web.util.UriComponentsBuilder; import javax.annotation.PostConstruct; import java.util.Map; +/** + * @author Jayendra + */ @Component public class RestTemplateUtil { @@ -141,10 +144,35 @@ public class RestTemplateUtil { HttpMethod.GET, httpEntity, Map.class - ).getBody(); + ).getBody(); return balanceByAddress; } + + public Map getBalanceByAddressInEther(String address, String chainId) { + + NetworkProperties props = conf.getNetworks().get(chainId); + + // module=account&action=balance&address=0xB9BbCB84B654316D8E23383434c4EC66A97038ED&tag=latest&apikey=YourApiKeyToken + + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(props.getBlockExplorerUrl()) + .queryParam("module", "account") + .queryParam("action", "balance") + .queryParam("address", address) + .queryParam("tag", "latest") + .queryParam("apikey", props.getBlockExplorerApiKey()); + + HttpEntity> httpEntity = new HttpEntity<>(new HttpHeaders()); + + Map etherBalance = restTemplate.exchange(builder.toUriString(), + HttpMethod.GET, + httpEntity, + Map.class).getBody(); + + return etherBalance; + + } + } diff --git a/src/main/java/com/nynja/walletservice/util/Web3JUtils.java b/src/main/java/com/nynja/walletservice/util/Web3JUtils.java index b6b462e..2ab12ae 100644 --- a/src/main/java/com/nynja/walletservice/util/Web3JUtils.java +++ b/src/main/java/com/nynja/walletservice/util/Web3JUtils.java @@ -1,10 +1,13 @@ package com.nynja.walletservice.util; +import com.nynja.walletservice.constant.Constants; import com.nynja.walletservice.dto.TransactionResponseDto; import org.web3j.crypto.Credentials; import org.web3j.crypto.ECKeyPair; import org.web3j.protocol.core.methods.response.TransactionReceipt; +import org.web3j.utils.Convert; +import java.math.BigDecimal; import java.math.BigInteger; import java.util.function.Function; @@ -25,4 +28,19 @@ public class Web3JUtils { throw new RuntimeException(errorMessage); }; } + + + /** + * @author Jayendra + */ + // Considering Gas price in WEI + public static BigDecimal calculateGasFees(BigInteger gasPrice, BigInteger gasLimit){ + + BigDecimal etherGasPriceBD = new BigDecimal(gasPrice).divide(new BigDecimal(Constants.EtherUnits.WEI)); + BigDecimal totalRequiredGas = etherGasPriceBD.multiply(new BigDecimal(gasLimit)); + + return totalRequiredGas; + + } + } diff --git a/src/main/java/com/nynja/walletservice/websocket/ApplicationContextUtil.java b/src/main/java/com/nynja/walletservice/websocket/ApplicationContextUtil.java new file mode 100644 index 0000000..9c8fa2d --- /dev/null +++ b/src/main/java/com/nynja/walletservice/websocket/ApplicationContextUtil.java @@ -0,0 +1,22 @@ +package com.nynja.walletservice.websocket; + +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Service; + +@Service +public class ApplicationContextUtil implements ApplicationContextAware { + + private static ApplicationContext applicationContext; + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + this.applicationContext = applicationContext; + } + + public static T getBean(Class beanClass) { + + return applicationContext.getBean(beanClass); + } +} diff --git a/src/main/java/com/nynja/walletservice/websocket/NYN_BTCConversion.java b/src/main/java/com/nynja/walletservice/websocket/NYN_BTCConversion.java new file mode 100644 index 0000000..feecc4a --- /dev/null +++ b/src/main/java/com/nynja/walletservice/websocket/NYN_BTCConversion.java @@ -0,0 +1,114 @@ +package com.nynja.walletservice.websocket; + +import org.springframework.stereotype.Component; + +@Component +public class NYN_BTCConversion { + + String symbol; + String open_price; + String highest_price; + String lowest_price; + String volume; + String current_price; + String fluctuation; + String rate; + String timestamp; + + + public String getSymbol() { + return symbol; + } + + public void setSymbol(String symbol) { + this.symbol = symbol; + } + + public String getOpen_price() { + return open_price; + } + + public void setOpen_price(String open_price) { + this.open_price = open_price; + } + + public String getHighest_price() { + return highest_price; + } + + public void setHighest_price(String highest_price) { + this.highest_price = highest_price; + } + + public String getLowest_price() { + return lowest_price; + } + + public void setLowest_price(String lowest_price) { + this.lowest_price = lowest_price; + } + + public String getVolume() { + return volume; + } + + public void setVolume(String volume) { + this.volume = volume; + } + + public String getCurrent_price() { + return current_price; + } + + public void setCurrent_price(String current_price) { + this.current_price = current_price; + } + + public String getFluctuation() { + return fluctuation; + } + + public void setFluctuation(String fluctuation) { + this.fluctuation = fluctuation; + } + + public String getRate() { + return rate; + } + + public void setRate(String rate) { + this.rate = rate; + } + + public String getTimestamp() { + return timestamp; + } + + public void setTimestamp(String timestamp) { + this.timestamp = timestamp; + } + + @Override + public String toString() { + return "ConversionPrice{" + + ", symbol='" + symbol + '\'' + + ", open_price='" + open_price + '\'' + + ", highest_price='" + highest_price + '\'' + + ", lowest_price='" + lowest_price + '\'' + + ", volume='" + volume + '\'' + + ", current_price='" + current_price + '\'' + + ", fluctuation='" + fluctuation + '\'' + + ", rate='" + rate + '\'' + + ", timestamp='" + timestamp + '\'' + + '}'; + } +} + + +// {"subscribe":"price","symbol":"BMX_ETH", +// "data":{"open_price":"0.00015984","highest_price":"0.00017900","lowest_price":"0.00013402","volume":"4269.52081997","current_price":"0.00014196","fluctuation":"-0.1119","rate":"0.03 USD","timestamp":1568806897223}} + + + + + diff --git a/src/main/java/com/nynja/walletservice/websocket/NYN_ETHConversion.java b/src/main/java/com/nynja/walletservice/websocket/NYN_ETHConversion.java new file mode 100644 index 0000000..ddf032f --- /dev/null +++ b/src/main/java/com/nynja/walletservice/websocket/NYN_ETHConversion.java @@ -0,0 +1,112 @@ +package com.nynja.walletservice.websocket; + +import org.springframework.stereotype.Component; + +@Component +public class NYN_ETHConversion { + + String symbol; + String open_price; + String highest_price; + String lowest_price; + String volume; + String current_price; + String fluctuation; + String rate; + String timestamp; + + public String getSymbol() { + return symbol; + } + + public void setSymbol(String symbol) { + this.symbol = symbol; + } + + public String getOpen_price() { + return open_price; + } + + public void setOpen_price(String open_price) { + this.open_price = open_price; + } + + public String getHighest_price() { + return highest_price; + } + + public void setHighest_price(String highest_price) { + this.highest_price = highest_price; + } + + public String getLowest_price() { + return lowest_price; + } + + public void setLowest_price(String lowest_price) { + this.lowest_price = lowest_price; + } + + public String getVolume() { + return volume; + } + + public void setVolume(String volume) { + this.volume = volume; + } + + public String getCurrent_price() { + return current_price; + } + + public void setCurrent_price(String current_price) { + this.current_price = current_price; + } + + public String getFluctuation() { + return fluctuation; + } + + public void setFluctuation(String fluctuation) { + this.fluctuation = fluctuation; + } + + public String getRate() { + return rate; + } + + public void setRate(String rate) { + this.rate = rate; + } + + public String getTimestamp() { + return timestamp; + } + + public void setTimestamp(String timestamp) { + this.timestamp = timestamp; + } + + @Override + public String toString() { + return "ConversionPrice{" + + ", symbol='" + symbol + '\'' + + ", open_price='" + open_price + '\'' + + ", highest_price='" + highest_price + '\'' + + ", lowest_price='" + lowest_price + '\'' + + ", volume='" + volume + '\'' + + ", current_price='" + current_price + '\'' + + ", fluctuation='" + fluctuation + '\'' + + ", rate='" + rate + '\'' + + ", timestamp='" + timestamp + '\'' + + '}'; + } +} + + +// {"subscribe":"price","symbol":"BMX_ETH", +// "data":{"open_price":"0.00015984","highest_price":"0.00017900","lowest_price":"0.00013402","volume":"4269.52081997","current_price":"0.00014196","fluctuation":"-0.1119","rate":"0.03 USD","timestamp":1568806897223}} + + + + diff --git a/src/main/java/com/nynja/walletservice/websocket/WSClient.java b/src/main/java/com/nynja/walletservice/websocket/WSClient.java new file mode 100644 index 0000000..d684c2a --- /dev/null +++ b/src/main/java/com/nynja/walletservice/websocket/WSClient.java @@ -0,0 +1,92 @@ +package com.nynja.walletservice.websocket; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import javax.websocket.*; +import java.io.IOException; +import java.util.Map; + +@ClientEndpoint +public class WSClient { + + static NYN_BTCConversion nyn_btcConversion; + static NYN_ETHConversion nyn_ethConversion; + + static { + + nyn_btcConversion = ApplicationContextUtil.getBean(NYN_BTCConversion.class); + nyn_ethConversion = ApplicationContextUtil.getBean(NYN_ETHConversion.class); + + } + + ObjectMapper objectMapper = new ObjectMapper(); + + @OnMessage + public void onMessage(String message) throws InterruptedException, IOException { + + + Map messageMap = objectMapper.readValue(message, Map.class); + String symbol = (String) messageMap.get("symbol"); + Map data = (Map) messageMap.get("data"); + + + if (symbol.equals("NYN_BTC")) { + + + nyn_btcConversion.setSymbol(symbol); + nyn_btcConversion.setOpen_price(data.get("open_price").toString()); + nyn_btcConversion.setHighest_price(data.get("highest_price").toString()); + nyn_btcConversion.setHighest_price(data.get("highest_price").toString()); + nyn_btcConversion.setLowest_price(data.get("lowest_price").toString()); + nyn_btcConversion.setVolume(data.get("volume").toString()); + nyn_btcConversion.setCurrent_price(data.get("current_price").toString()); + nyn_btcConversion.setFluctuation(data.get("fluctuation").toString()); + nyn_btcConversion.setRate(data.get("rate").toString()); + nyn_btcConversion.setTimestamp(data.get("timestamp").toString()); + + + } else if (symbol.equals("NYN_ETH")) { + + nyn_ethConversion.setSymbol(symbol); + nyn_ethConversion.setOpen_price(data.get("open_price").toString()); + nyn_ethConversion.setHighest_price(data.get("highest_price").toString()); + nyn_ethConversion.setHighest_price(data.get("highest_price").toString()); + nyn_ethConversion.setLowest_price(data.get("lowest_price").toString()); + nyn_ethConversion.setVolume(data.get("volume").toString()); + nyn_ethConversion.setCurrent_price(data.get("current_price").toString()); + nyn_ethConversion.setFluctuation(data.get("fluctuation").toString()); + nyn_ethConversion.setRate(data.get("rate").toString()); + nyn_ethConversion.setTimestamp(data.get("timestamp").toString()); + + } + + + // Sleep for 5 seconds before fetching new record + Thread.sleep(5000); + } + + @OnOpen + public void onOpen(Session session) throws IOException { + + System.out.println("------------>>>"); + System.out.println("Opening Websocket connection."); + System.out.println(""); + System.out.println("Mapper : "); + System.out.println(objectMapper); + System.out.println(""); + + + // Subscribing to get NYN - ETH conversion price + session.getBasicRemote().sendText("{\"subscribe\":\"price\",\"symbol\":\"NYN_ETH\"}"); + + // Subscribing to get NYN - BTC conversion price + session.getBasicRemote().sendText("{\"subscribe\":\"price\",\"symbol\":\"NYN_BTC\"}"); + + System.out.println(""); + System.out.println("Websocket connection is opened."); + System.out.println("------------>>>"); + } + + +} + diff --git a/src/main/java/com/nynja/walletservice/websocket/WSConfig.java b/src/main/java/com/nynja/walletservice/websocket/WSConfig.java new file mode 100644 index 0000000..c4b525e --- /dev/null +++ b/src/main/java/com/nynja/walletservice/websocket/WSConfig.java @@ -0,0 +1,34 @@ +package com.nynja.walletservice.websocket; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import javax.websocket.ContainerProvider; +import javax.websocket.DeploymentException; +import javax.websocket.WebSocketContainer; +import java.io.IOException; +import java.net.URI; + +@Configuration +@ComponentScan(basePackages = "com.nynja.walletservice.*") +public class WSConfig { + + @Value("${bitmart.uri}") + private String bitmartUri; + + @Bean("test") + public ObjectMapper objectMapper() { + return new ObjectMapper(); + } + + @Bean + public WebSocketContainer webSocketClient() throws IOException, DeploymentException { + + WebSocketContainer webSocketContainer = ContainerProvider.getWebSocketContainer(); + webSocketContainer.connectToServer(WSClient.class, URI.create(bitmartUri)); + + return webSocketContainer; + } +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index d362753..1353888 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -31,7 +31,7 @@ ethereum: nynja-coin-listen-events: false #nynja-coin-address: "0xF36c7AdAd65c39A4848F3c85001F67f31d00d207" nynja-coin-address: "0x5b52b324fc10cb43b9eeadaf9bd15afb98867942" - gas-price: 41000000000 + gas-price: 41000000000 # Amount is in wei, (41 Gwei) gas-limit: 400000 four: # url: http://35.242.240.78:8545 @@ -43,7 +43,7 @@ ethereum: nynja-coin-listen-events: true # nynja-coin-address: "0xF36c7AdAd65c39A4848F3c85001F67f31d00d207" nynja-coin-address: "0x1bd759504dd3a93f13ba807204c7a98a592559cc" - gas-price: 41000000000 + gas-price: 41000000000 # Amount is in wei, (41 Gwei) gas-limit: 400000 event: margin: 20 @@ -53,3 +53,5 @@ message-broker: url: "http://dev2.ci.nynja.net/publish" topic: "/transfer-" +bitmart: + uri: "wss://openws.bitmart.com" \ No newline at end of file -- GitLab