| | |
| | | import com.xcong.excoin.modules.member.entity.MemberCoinAddressEntity; |
| | | import com.xcong.excoin.rabbit.producer.UsdtUpdateProducer; |
| | | import com.xcong.excoin.utils.RedisUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.collections.CollectionUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.http.HttpEntity; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.http.*; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.client.RestTemplate; |
| | | import org.tron.common.utils.ByteArray; |
| | |
| | | /** |
| | | * TRX TRC20服务类 |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class TrxUsdtUpdateService { |
| | | |
| | |
| | | /** |
| | | * 扫块 同步充值USDT-TRC20和TRX |
| | | */ |
| | | public void monitorCoinListener() { |
| | | public void monitorCoinListener(Long blockNum) { |
| | | if (CollectionUtils.isEmpty(addressList)) { |
| | | List<MemberCoinAddressEntity> coinAddressList = memberCoinAddressDao.selectAllBlockAddressBySymbolAndTag(CoinTypeEnum.USDT.name(), "TRC20"); |
| | | if (CollectionUtils.isNotEmpty(coinAddressList)) { |
| | |
| | | addressList.add(e.getAddress()); |
| | | }); |
| | | } |
| | | } |
| | | // 扫块区块 |
| | | Object trc20BlockNum = redisUtils.get("USDT_TRC20_BLOCK_NUM"); |
| | | if(trc20BlockNum==null){ |
| | | trc20BlockNum = 28471475L; |
| | | |
| | | } |
| | | Long blockNum = Long.valueOf(trc20BlockNum.toString()); |
| | | redisUtils.set("USDT_TRC20_BLOCK_NUM",blockNum); |
| | | // 查询一下最新区块 |
| | | long getnowblock = getnowblock()-20L; |
| | | if(getnowblock<blockNum){ |
| | | // 如果当前区块比最新已确认区块还大,则不继续执行 |
| | | return; |
| | | } |
| | | if (CollectionUtils.isEmpty(addressList)) { |
| | | return; |
| | |
| | | if (StringUtils.isBlank(transactionInfoByBlockNum)) { |
| | | return; |
| | | } |
| | | // log.info("--->{}, {}", num, System.currentTimeMillis()); |
| | | // 不用等到扫完再累加 只要进来就加 还有一个条件是必须查询出区块再加 否则当区块超过实际区块 |
| | | redisUtils.set("USDT_TRC20_BLOCK_NUM", (num + 1L)); |
| | | // redisUtils.set("USDT_TRC20_BLOCK_NUM", (num + 1L)); |
| | | JSONArray parseArray = JSON.parseObject(transactionInfoByBlockNum).getJSONArray("transactions"); |
| | | if (parseArray.size() > 0) { |
| | | if (parseArray != null && parseArray.size() > 0) { |
| | | for (Object e : parseArray) { |
| | | try { |
| | | // String txId = JSON.parseObject(e.toString()).getString("id"); |
| | |
| | | |
| | | } else if ("TransferContract".equals(type)) { |
| | | //trx 转账 |
| | | transferContract(parseObject); |
| | | //transferContract(parseObject); |
| | | } |
| | | } |
| | | } catch (Exception exception) { |
| | |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.setContentType(MediaType.APPLICATION_JSON); |
| | | headers.set("TRON-PRO-API-KEY",Trc20Service.API_KEY); |
| | | HttpEntity<String> request = new HttpEntity<>(param); |
| | | HttpEntity<String> request = new HttpEntity<>(param,headers); |
| | | ResponseEntity<String> result = restTemplate.postForEntity(url, request, String.class); |
| | | // System.out.println("url:" + url + ",param:" + param + ",result:" + result.getBody()); |
| | | return result; |
| | |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.setContentType(MediaType.APPLICATION_JSON); |
| | | headers.set("TRON-PRO-API-KEY",Trc20Service.API_KEY); |
| | | //HttpEntity<String> request = new HttpEntity<>(); |
| | | String forObject = restTemplate.getForObject(url, String.class); |
| | | HttpEntity<String> request = new HttpEntity<>(headers); |
| | | ResponseEntity<String> exchange = restTemplate.exchange(url, HttpMethod.GET, request, String.class); |
| | | String forObject = exchange.getBody(); |
| | | //System.out.println(forObject); |
| | | // String forObject = restTemplate.getForObject(url, String.class); |
| | | String number = JSON.parseObject(forObject).getJSONObject("block_header").getJSONObject("raw_data").getString("number"); |
| | | return Long.valueOf(number); |
| | | } |
| | | |
| | | |
| | | |
| | | } |