Commit dee5d47e authored by jianhua.zhang's avatar jianhua.zhang

波场浏览器JAVA版

parent 48b2532a
...@@ -70,7 +70,7 @@ public class Bootstrapper { ...@@ -70,7 +70,7 @@ public class Bootstrapper {
private long getInitialDelay() { private long getInitialDelay() {
Date nextDate = DateUtil.addDays(new Date(), 1); Date nextDate = DateUtil.addDays(new Date(), 1);
String date = DateUtil.getFormatDate(nextDate, DateUtil.PATTERN_YMD) + " 00:00:03"; String date = DateUtil.getFormatDate(nextDate, DateUtil.PATTERN_YMD) + " 00:00:03";
long millis = (DateUtil.getDateFromDateStr(date) - System.currentTimeMillis())/1000; long millis = (DateUtil.getDateFromDateStr(date, DateUtil.PATTERN_YMD_HMS) - System.currentTimeMillis())/1000;
return millis; return millis;
} }
......
package com.wuban.tron.explore.constant; package com.wuban.tron.explore.constant;
import okhttp3.MediaType; import okhttp3.MediaType;
import org.springframework.beans.factory.annotation.Value;
/** /**
* <core>常量定义类</core> * <core>常量定义类</core>
...@@ -45,7 +46,7 @@ public class Constant { ...@@ -45,7 +46,7 @@ public class Constant {
/** /**
* 用户地址长度 * 用户地址长度
*/ */
public static final int USER_ADDRESS_LEN = 42; public static final int USER_ADDRESS_LEN = 34;
/** /**
* txID长度 * txID长度
......
...@@ -11,6 +11,9 @@ import org.springframework.web.bind.annotation.RequestMethod; ...@@ -11,6 +11,9 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid; import javax.validation.Valid;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/** /**
* <core>区块统计API</core> * <core>区块统计API</core>
...@@ -26,9 +29,11 @@ public class CensusController { ...@@ -26,9 +29,11 @@ public class CensusController {
private final TransactionService transactionService; private final TransactionService transactionService;
private final ThreadPoolExecutor pool = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.SECONDS, new LinkedBlockingQueue<>());
@RequestMapping(method = RequestMethod.POST) @RequestMapping(method = RequestMethod.POST)
public void census(@RequestBody @Valid CensusRequest reqParam) { public void census(@RequestBody @Valid CensusRequest reqParam) {
new Thread(()->this.transactionService.censusBlockByDate(reqParam.getStartDate(), reqParam.getEndDate())).start(); this.pool.execute(() -> this.transactionService.censusBlockByDate(reqParam.getStartDate(), reqParam.getEndDate()));
} }
} }
package com.wuban.tron.explore.controller.v1;
import com.github.pagehelper.PageInfo;
import com.wuban.tron.explore.constant.Constant;
import com.wuban.tron.explore.constant.HomeSearchTypeEnum;
import com.wuban.tron.explore.entity.Address;
import com.wuban.tron.explore.entity.BlockDayCensus;
import com.wuban.tron.explore.entity.BlockHeader;
import com.wuban.tron.explore.entity.Transaction;
import com.wuban.tron.explore.entity.example.AddressExample;
import com.wuban.tron.explore.entity.example.BlockDayCensusExample;
import com.wuban.tron.explore.entity.example.BlockHeaderExample;
import com.wuban.tron.explore.entity.example.TransactionExample;
import com.wuban.tron.explore.param.response.*;
import com.wuban.tron.explore.service.AddressService;
import com.wuban.tron.explore.service.BlockDayCensusService;
import com.wuban.tron.explore.service.BlockHeaderService;
import com.wuban.tron.explore.service.TransactionService;
import com.wuban.tron.explore.util.ApiResponse;
import com.wuban.tron.explore.util.DateUtil;
import com.wuban.tron.explore.util.ResponseKit;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
/**
* <core>API接口</core>
*
* @author sky
* @date 2020/11/02
*/
@Slf4j
@RestController
@RequestMapping("/api/explorer/v1/")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class TransactionControllerV1 {
private final TransactionService transactionService;
private final BlockDayCensusService blockDayCensusService;
private final BlockHeaderService blockHeaderService;
private final AddressService addressService;
/**
* 首页 - 搜索
*
* @param condition
* @return
*/
@RequestMapping(value="indexGetInfoByCondition/{condition}", method = RequestMethod.GET)
public ApiResponse search(@PathVariable("condition") String condition) {
if (StringUtils.isEmpty(condition)) {
return ResponseKit.success();
}
condition = StringUtils.trimAllWhitespace(condition);
/*
块查询
*/
if (isNumeric(condition)) {
ResDataModel<BlockInfoModel> resDataModel = new ResDataModel<>();
BlockHeaderExample headerExample = new BlockHeaderExample();
headerExample.createCriteria().andNumberEqualTo(Long.valueOf(condition));
BlockHeader blockHeader = this.blockHeaderService.getOneByExample(headerExample);
BlockInfoModel model = BlockInfoModel.getInstance();
if (blockHeader != null) {
model.setNumber(blockHeader.getNumber());
model.setTimestamp(blockHeader.getTimestamp().toString());
model.setParentHash(blockHeader.getParentHash());
model.setTrans_number(blockHeader.getTransactionVolume());
model.setSize(blockHeader.getBlockBytes());
}
resDataModel.setData(model);
resDataModel.setT(HomeSearchTypeEnum.BLOCK_INFO.getCode());
return ResponseKit.success(resDataModel);
}
/*
账户地址
*/
if (condition.length() == Constant.USER_ADDRESS_LEN) {
ResDataModel<AddessInfoModel> resDataModel = new ResDataModel<>();
AddessInfoModel model = AddessInfoModel.getInstance();
AddressExample addressExample = new AddressExample();
addressExample.createCriteria().andAddressEqualTo(condition);
Address address = this.addressService.selectOneByExample(addressExample);
if (address != null) {
model.setAddress(address.getAddress());
model.setBalance(address.getBalance()+"");
}
resDataModel.setData(model);
resDataModel.setT(HomeSearchTypeEnum.ADDRESS_INFO.getCode());
return ResponseKit.success(resDataModel);
}
/*
交易hash
*/
if (condition.length()== Constant.TX_ID_LEN) {
TransInfoModel model = TransInfoModel.getInstance();
TransactionExample example = new TransactionExample();
example.createCriteria().andTxIdEqualTo(condition);
List<Transaction> txList = this.transactionService.getByExample(example);
if (!CollectionUtils.isEmpty(txList)) {
Transaction trans = txList.get(0);
model.setHash(condition);
model.setBlockHash(trans.getBlockId());
model.setBlockNumber(trans.getNumber().intValue());
model.setFrom(trans.getOwnerAddress());
if (!StringUtils.isEmpty(trans.getContractAddress())) {
model.setTo(trans.getContractAddress());
} else {
model.setTo(trans.getToAddress());
}
model.setTimestamp(trans.getTimestamp().toString());
}
return ResponseKit.success(model);
}
return ResponseKit.success();
}
/**
* 首页 - Latest Blocks
*
* @return
*/
@RequestMapping(value="indexGetBlockInfo", method = RequestMethod.GET)
public ApiResponse lastBlockList() {
BlockHeaderExample headerExample = new BlockHeaderExample();
PageInfo<BlockHeader> pageInfo = this.blockHeaderService.getByPagerEx(null, null, headerExample);
List<BlockInfoModel> list = transferBlockInfoModel(pageInfo);
return ResponseKit.success(list);
}
/**
* 首页 - All Blocks
*
* @return
*/
@RequestMapping(value="getBlockInfo/{pageNo}/{pageSize}", method = RequestMethod.GET)
public ApiResponse allBlockList(@PathVariable("pageNo") Integer pageNo, @PathVariable("pageSize") Integer pageSize) {
BlockHeaderExample headerExample = new BlockHeaderExample();
PageInfo<BlockHeader> pageInfo = this.blockHeaderService.getByPagerEx(pageNo, pageSize, headerExample);
List<BlockInfoModel> list = transferBlockInfoModel(pageInfo);
ResDataModel<BlockInfoModel> model = new ResDataModel<>();
model.setData(list);
model.setTotal(Integer.valueOf(pageInfo.getTotal()+""));
return ResponseKit.success(model);
}
private List<BlockInfoModel> transferBlockInfoModel(PageInfo<BlockHeader> pageInfo) {
List<BlockInfoModel> list = new ArrayList<>();
if (!CollectionUtils.isEmpty(pageInfo.getList())) {
pageInfo.getList().forEach(o -> {
BlockInfoModel model = BlockInfoModel.getInstance();
model.setNumber(o.getNumber());
model.setTimestamp(o.getTimestamp().toString());
model.setParentHash(o.getParentHash());
model.setHash(o.getBlockId());
model.setTrans_number(o.getTransactionVolume());
model.setSize(o.getBlockBytes());
list.add(model);
});
}
return list;
}
/**
* 首页 - Latest Transactions
*
* @return
*/
@RequestMapping(value="indexGetTxInfo", method = RequestMethod.GET)
public ApiResponse lastTransList() {
PageInfo<Transaction> pageInfo = this.transactionService.getByPageWithCategory(null, null, new TransactionExample());
List<TransInfoModel> modelList = transferTransInfoModel(pageInfo);
return ResponseKit.success(modelList);
}
/**
* 首页 - All Transactions
*
* @return
*/
@RequestMapping(value="getTxInfo/{pageNo}/{pageSize}", method = RequestMethod.GET)
public ApiResponse allTransList(@PathVariable("pageNo") Integer pageNo, @PathVariable("pageSize") Integer pageSize) {
PageInfo<Transaction> pageInfo = this.transactionService.getByPageWithCategory(pageNo, pageSize, new TransactionExample());
List<TransInfoModel> modelList = transferTransInfoModel(pageInfo);
ResDataModel<TransInfoModel> resDataModel = new ResDataModel<>();
resDataModel.setTotal(Integer.valueOf(pageInfo.getTotal()+""));
resDataModel.setData(modelList);
return ResponseKit.success(resDataModel);
}
private List<TransInfoModel> transferTransInfoModel(PageInfo<Transaction> pageInfo) {
List<TransInfoModel> modelList = new ArrayList<>();
List<Long> numberList = new ArrayList<>();
if (!CollectionUtils.isEmpty(pageInfo.getList())) {
pageInfo.getList().forEach(o -> {
TransInfoModel model = TransInfoModel.getInstance();
model.setHash(o.getBlockId());
model.setBlockHash(o.getTxId());
model.setBlockNumber(o.getNumber().intValue());
model.setFrom(o.getOwnerAddress());
BlockInfoModel blockInfoModel = BlockInfoModel.getInstance();
blockInfoModel.setNumber(o.getNumber().intValue());
model.setBlockNumber(blockInfoModel);
if (!StringUtils.isEmpty(o.getContractAddress())) {
model.setTo(o.getContractAddress());
} else {
model.setTo(o.getToAddress());
}
model.setTimestamp(o.getTimestamp().toString());
modelList.add(model);
numberList.add(o.getNumber());
});
}
return modelList;
}
/**
* 区块列表-通过区块高度查询区块详情
*
* @return
*/
@RequestMapping(value="getBlockDetailInfoByBlock/{block}", method = RequestMethod.GET)
public ApiResponse getBlockDetailInfoByBlock(@PathVariable("block") String block) {
BlockHeaderExample headerExample = new BlockHeaderExample();
headerExample.createCriteria().andNumberEqualTo(Long.valueOf(block));
BlockHeader blockHeader = this.blockHeaderService.getOneByExample(headerExample);
BlockInfoModel model = BlockInfoModel.getInstance();
if (blockHeader != null) {
model.setNumber(blockHeader.getNumber());
model.setTimestamp(blockHeader.getTimestamp().toString());
model.setParentHash(blockHeader.getParentHash());
model.setTrans_number(blockHeader.getTransactionVolume());
model.setSize(blockHeader.getBlockBytes());
}
return ResponseKit.success(model);
}
/**
* 区块列表-通过区块高度查询交易列表
*
* @return
*/
@RequestMapping(value="getTxInfoByBlock/{block}/{pageNo}/{pageSize}", method = RequestMethod.GET)
public ApiResponse getTxInfoByBlock(@PathVariable("block") String block, @PathVariable("pageNo") Integer pageNo, @PathVariable("pageSize") Integer pageSize) {
TransactionExample example = new TransactionExample();
example.createCriteria().andNumberEqualTo(Long.valueOf(block));
PageInfo<Transaction> pageInfo = this.transactionService.getByPageWithCategory(pageNo, pageSize, example);
List<TransInfoModel> modelList = transferTransInfoModel(pageInfo);
ResDataModel<TransInfoModel> resDataModel = new ResDataModel<>();
resDataModel.setTotal(Integer.valueOf(pageInfo.getTotal()+""));
resDataModel.setData(modelList);
return ResponseKit.success(resDataModel);
}
/**
* 区块列表-通过地址查询账户信息
*
* @return
*/
@RequestMapping(value="getAddressInfoByAddress/{address}", method = RequestMethod.GET)
public ApiResponse getAddressInfoByAddress(@PathVariable("address") String address) {
AddessInfoModel model = AddessInfoModel.getInstance();
AddressExample addressExample = new AddressExample();
addressExample.createCriteria().andAddressEqualTo(address);
Address obj = this.addressService.selectOneByExample(addressExample);
if (obj != null) {
model.setAddress(obj.getAddress());
model.setBalance(obj.getBalance()+"");
}
return ResponseKit.success(model);
}
/**
* 交易列表-通过交易哈希查询交易详情
*
* @return
*/
@RequestMapping(value="getTxDetailInfoByHash/{hash}", method = RequestMethod.GET)
public ApiResponse getTxDetailInfoByHash(@PathVariable("hash") String hash) {
TransInfoModel model = TransInfoModel.getInstance();
TransactionExample example = new TransactionExample();
example.createCriteria().andTxIdEqualTo(hash);
List<Transaction> txList = this.transactionService.getByExample(example);
if (!CollectionUtils.isEmpty(txList)) {
Transaction trans = txList.get(0);
model.setHash(hash);
model.setBlockHash(trans.getBlockId());
model.setBlockNumber(trans.getNumber().intValue());
model.setFrom(trans.getOwnerAddress());
if (!StringUtils.isEmpty(trans.getContractAddress())) {
model.setTo(trans.getContractAddress());
} else {
model.setTo(trans.getToAddress());
}
model.setTimestamp(trans.getTimestamp().toString());
}
return ResponseKit.success(model);
}
/**
* 地址详情页-交易列表
*
* @return
*/
@RequestMapping(value="getTxInfoByAddress/{address}", method = RequestMethod.GET)
public ApiResponse getTxInfoByAddress(@PathVariable("address") String address) {
ResDataModel<TransInfoModel> resDataModel = new ResDataModel<>();
PageInfo<Transaction> pageInfo = this.transactionService.selectPageByAddress(address, 1, 25);
if (!CollectionUtils.isEmpty(pageInfo.getList())) {
List<TransInfoModel> modelList = transferTransInfoModel(pageInfo);
resDataModel.setTotal(Integer.valueOf(pageInfo.getTotal()+""));
resDataModel.setData(modelList);
}
return ResponseKit.success(resDataModel);
}
/**
* 账户余额排行榜
*
* @return
*/
@RequestMapping(value="getTopAccountsInfo/{pageNo}/{pageSize}", method = RequestMethod.GET)
public ApiResponse getTopAccountsInfo(@PathVariable("pageNo") Integer pageNo, @PathVariable("pageSize") Integer pageSize) {
ResDataModel<TransInfoModel> resDataModel = new ResDataModel<>();
AddressExample example = new AddressExample();
example.setOrderByClause("balance desc");
PageInfo<Address> pageInfo = this.addressService.selectByPager(pageNo, pageSize, example);
resDataModel.setTotal(Integer.parseInt(pageInfo.getTotal()+""));
List<AccountInfoModel> modelList = new ArrayList<>();
if (!CollectionUtils.isEmpty(pageInfo.getList())) {
pageInfo.getList().forEach(o -> {
AccountInfoModel infoModel = AccountInfoModel.getInstance();
infoModel.setAddress(o.getAddress());
infoModel.setBalance(o.getBalance().toString());
modelList.add(infoModel);
});
}
resDataModel.setData(modelList);
return ResponseKit.success(resDataModel);
}
/**
* 首页图表
*
* @return
*/
@RequestMapping(value="indexGetChartInfo", method = RequestMethod.GET)
public ApiResponse indexGetChartInfo() {
PageInfo<BlockDayCensus> pageInfo = this.blockDayCensusService.getByPageWithCategory(1, 14, new BlockDayCensusExample());
List<HomeChartModel> modelList = new ArrayList<>();
if (!CollectionUtils.isEmpty(pageInfo.getList())) {
List<BlockDayCensus> list = pageInfo.getList();
HomeChartModel model;
int id = 1;
for (int i = 0; i < list.size(); i++) {
model = new HomeChartModel();
model.setId(id);
long time = DateUtil.getDateFromDateStr(list.get(i).getCensusDate(), DateUtil.PATTERN_YMD);
model.setTime(time);
model.setCount(list.get(i).getTotalVolume());
modelList.add(model);
id++;
}
}
return ResponseKit.success(modelList);
}
public final static boolean isNumeric(String s) {
if (s != null && !"".equals(s.trim())) {
return s.matches("^[0-9]*$");
} else {
return false;
}
}
}
package com.wuban.tron.explore.dao; package com.wuban.tron.explore.dao;
import com.wuban.tron.explore.entity.BlockHeader; import com.wuban.tron.explore.entity.BlockHeader;
import com.wuban.tron.explore.entity.Transaction;
import com.wuban.tron.explore.entity.example.BlockHeaderExample; import com.wuban.tron.explore.entity.example.BlockHeaderExample;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
...@@ -46,4 +47,12 @@ public interface BlockHeaderRepository { ...@@ -46,4 +47,12 @@ public interface BlockHeaderRepository {
*/ */
BlockHeader selectOneByExample(@Param("example")BlockHeaderExample example); BlockHeader selectOneByExample(@Param("example")BlockHeaderExample example);
/**
* 分页查询
*
* @param example 查询条件参数
* @return 分页记录列表
*/
List<BlockHeader> selectByPagerEx(@Param("example") BlockHeaderExample example);
} }
...@@ -59,4 +59,15 @@ public interface TransactionRepository { ...@@ -59,4 +59,15 @@ public interface TransactionRepository {
*/ */
List<Transaction> selectListByAddress(@Param("address") String address, @Param("t") long timestamp); List<Transaction> selectListByAddress(@Param("address") String address, @Param("t") long timestamp);
/**
* 根据账户地址查询交易信息
*
* @param address 账户地址
*
*
* @return
*/
List<Transaction> selectPageByAddress(@Param("address") String address);
} }
...@@ -20,7 +20,7 @@ import java.util.concurrent.atomic.AtomicInteger; ...@@ -20,7 +20,7 @@ import java.util.concurrent.atomic.AtomicInteger;
@Slf4j @Slf4j
public class Executor { public class Executor {
private static final int SIZE = 10; private static final int SIZE = 15;
private final List<AbstractJob> jobList = new ArrayList<>(); private final List<AbstractJob> jobList = new ArrayList<>();
private final String name; private final String name;
private ThreadPoolExecutor pool; private ThreadPoolExecutor pool;
......
...@@ -8,6 +8,8 @@ import com.wuban.tron.explore.service.AddressService; ...@@ -8,6 +8,8 @@ import com.wuban.tron.explore.service.AddressService;
import com.wuban.tron.explore.util.SpringContextUtil; import com.wuban.tron.explore.util.SpringContextUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.tron.common.utils.ByteArray;
import org.tron.walletserver.WalletApi;
import java.util.List; import java.util.List;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
...@@ -53,7 +55,9 @@ public class AddressBalanceHandler extends AbstractJob implements IAddressBalanc ...@@ -53,7 +55,9 @@ public class AddressBalanceHandler extends AbstractJob implements IAddressBalanc
public void flush(List<TronAccount> e) { public void flush(List<TronAccount> e) {
if (!CollectionUtils.isEmpty(e)) { if (!CollectionUtils.isEmpty(e)) {
Address obj = new Address(); Address obj = new Address();
obj.setAddress(e.get(0).getAddress());
String address = WalletApi.encode58Check(ByteArray.fromHexString(e.get(0).getAddress()));
obj.setAddress(address);
obj.setBalance(e.get(0).getBalance()); obj.setBalance(e.get(0).getBalance());
this.addressService.updateById(obj); this.addressService.updateById(obj);
log.info("更新账户余额 account:{}", obj.toString()); log.info("更新账户余额 account:{}", obj.toString());
......
package com.wuban.tron.explore.param.response;
import lombok.Builder;
import lombok.Data;
@Data
@Builder
public class AccountInfoModel {
private String address;
private String balance;
private String more_info;
private String name;
private String tag;
private String creator;
private String hash;
private String type;
private int txn_count;
public static AccountInfoModel getInstance() {
return AccountInfoModel.builder()
.address("")
.balance("")
.more_info("")
.name("")
.tag("")
.creator("")
.hash("")
.type("")
.txn_count(0)
.build();
}
}
package com.wuban.tron.explore.param.response;
import lombok.Builder;
import lombok.Data;
@Data
@Builder
public class AddessInfoModel {
private String address;
private String balance;
private String more_info;
private String name;
private String tag;
private String creator;
private String hash;
private String type;
private int txn_count;
public static AddessInfoModel getInstance() {
return AddessInfoModel.builder()
.address("")
.balance("")
.more_info("")
.name("")
.tag("")
.creator("")
.hash("")
.type("")
.txn_count(0)
.build();
}
}
package com.wuban.tron.explore.param.response;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.wuban.tron.explore.entity.Transaction;
import lombok.Builder;
import lombok.Data;
import java.util.Date;
/**
* 区块详情MODEL
*
* @author wuban-team
* @date 2020-11-16
*/
@Data
@Builder
public class BlockInfoModel {
private long number;
private String timestamp;
private String miner;
private String mined_time;
private String block_reward;
private String uncles_reward;
private String difficulty;
private String totalDifficulty;
private String size;
private String extraData;
private String hash;
private String mixHash;
private String parentHash;
private String sha3Uncles;
private String stateRoot;
private String receiptsRoot;
private String transactionsRoot;
private String nonce;
private String gasUsed;
private String gasLimit;
@JsonProperty(value="Transaction")
private Object transaction;
private int trans_number;
public static BlockInfoModel getInstance() {
return BlockInfoModel.builder()
.number(0L)
.timestamp("")
.miner("")
.mined_time("")
.block_reward("")
.uncles_reward("")
.difficulty("")
.totalDifficulty("")
.size("")
.extraData("")
.hash("")
.mixHash("")
.parentHash("")
.sha3Uncles("")
.stateRoot("")
.receiptsRoot("")
.transactionsRoot("")
.nonce("")
.gasUsed("")
.gasLimit("")
.build();
}
}
package com.wuban.tron.explore.param.response;
import lombok.Data;
@Data
public class HomeChartModel {
private int id;
private long time;
private int count;
}
package com.wuban.tron.explore.param.response;
import lombok.Data;
/**
* 统一响应数据MODEL
*
* @author wuban-team
* @date 2020-11-16
*/
@Data
public class ResDataModel<T> {
private int total;
private int sum;
private int t;
private long total_balance;
private Object data;
}
package com.wuban.tron.explore.param.response;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Builder;
import lombok.Data;
/**
* 交易详情MODEL
*
* @author wuban-team
* @date 2020-11-16
*/
@Data
@Builder
public class TransInfoModel {
private String hash;
private String blockHash;
@JsonProperty(value="BlockNumber")
private Object blockNumber;
private String timestamp;
private String from;
private String to;
private String value;
private String v;
private String gas;
private String gasPrice;
private String transactionIndex;
private String nonce;
private String input;
public static TransInfoModel getInstance() {
return TransInfoModel.builder()
.hash("")
.blockHash("")
.blockNumber(0)
.timestamp("")
.from("")
.to("")
.value("")
.v("")
.gas("")
.gasPrice("")
.transactionIndex("")
.nonce("")
.input("")
.blockNumber(null)
.build();
}
}
...@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON; ...@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
import com.wuban.tron.explore.constant.Constant; import com.wuban.tron.explore.constant.Constant;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import okhttp3.*; import okhttp3.*;
import org.springframework.beans.factory.annotation.Value;
import java.io.IOException; import java.io.IOException;
import java.util.Map; import java.util.Map;
...@@ -36,6 +37,9 @@ public abstract class BaseCommonService { ...@@ -36,6 +37,9 @@ public abstract class BaseCommonService {
*/ */
protected static final String GET_ACCOUNT = PREFIX + "/getaccount"; protected static final String GET_ACCOUNT = PREFIX + "/getaccount";
@Value("${tron.site}")
private String tronSite;
/** /**
* http请求 * http请求
* *
...@@ -79,7 +83,7 @@ public abstract class BaseCommonService { ...@@ -79,7 +83,7 @@ public abstract class BaseCommonService {
protected Request builder(String uri, Map<String, Object> paramMap) { protected Request builder(String uri, Map<String, Object> paramMap) {
String param = JSON.toJSONString(paramMap); String param = JSON.toJSONString(paramMap);
RequestBody postBody = RequestBody.create(param, Constant.JSON_TYPE); RequestBody postBody = RequestBody.create(param, Constant.JSON_TYPE);
return new Request.Builder().url(Constant.HOST + uri).post(postBody) return new Request.Builder().url(this.tronSite + uri).post(postBody)
.addHeader(Constant.CONTENT_TYPE_KEY, Constant.CONTENT_TYPE_VAL).build(); .addHeader(Constant.CONTENT_TYPE_KEY, Constant.CONTENT_TYPE_VAL).build();
} }
......
package com.wuban.tron.explore.service; package com.wuban.tron.explore.service;
import com.github.pagehelper.PageInfo;
import com.wuban.tron.explore.entity.BlockHeader; import com.wuban.tron.explore.entity.BlockHeader;
import com.wuban.tron.explore.entity.example.BlockHeaderExample; import com.wuban.tron.explore.entity.example.BlockHeaderExample;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List;
/** /**
* <core>区块头服务接口</core> * <core>区块头服务接口</core>
* *
...@@ -20,4 +23,14 @@ public interface BlockHeaderService { ...@@ -20,4 +23,14 @@ public interface BlockHeaderService {
*/ */
BlockHeader getOneByExample(@Param("example") BlockHeaderExample example); BlockHeader getOneByExample(@Param("example") BlockHeaderExample example);
/**
* 分页查询
*
* @param startIndex
* @param pageSize
* @param example 查询条件参数
* @return 分页记录列表
*/
PageInfo<BlockHeader> getByPagerEx(Integer startIndex, Integer pageSize, @Param("example") BlockHeaderExample example);
} }
...@@ -77,7 +77,18 @@ public interface TransactionService { ...@@ -77,7 +77,18 @@ public interface TransactionService {
* @param pageSize * @param pageSize
* @return * @return
*/ */
PageInfo<Transaction> selectListByAddress(String address, int type, Integer startIndex, Integer pageSize); PageInfo<Transaction> selectListByAddress(String address, Integer type, Integer startIndex, Integer pageSize);
/**
* 根据账户地址查询交易信息
*
* @param address 账户地址
* @param startIndex
* @param pageSize
* @return
*/
PageInfo<Transaction> selectPageByAddress(@Param("address") String address, Integer startIndex, Integer pageSize);
} }
package com.wuban.tron.explore.service.impl; package com.wuban.tron.explore.service.impl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wuban.tron.explore.constant.PageConstant;
import com.wuban.tron.explore.dao.BlockHeaderRepository; import com.wuban.tron.explore.dao.BlockHeaderRepository;
import com.wuban.tron.explore.entity.BlockHeader; import com.wuban.tron.explore.entity.BlockHeader;
import com.wuban.tron.explore.entity.example.BlockHeaderExample; import com.wuban.tron.explore.entity.example.BlockHeaderExample;
...@@ -8,6 +11,8 @@ import lombok.RequiredArgsConstructor; ...@@ -8,6 +11,8 @@ import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
/** /**
* <core>区块头服务接口实现类</core> * <core>区块头服务接口实现类</core>
* *
...@@ -31,5 +36,33 @@ public class BlockHeaderServiceImpl implements BlockHeaderService { ...@@ -31,5 +36,33 @@ public class BlockHeaderServiceImpl implements BlockHeaderService {
return blockHeaderRepository.selectOneByExample(example); return blockHeaderRepository.selectOneByExample(example);
} }
/**
* 分页查询
*
* @param example 查询条件参数
* @return 分页记录列表
*/
@Override
public PageInfo<BlockHeader> getByPagerEx(Integer startIndex, Integer pageSize, BlockHeaderExample example) {
if (startIndex == null) {
startIndex = PageConstant.DEFAULT_START_INDEX;
}
if (pageSize == null) {
pageSize = PageConstant.DEFAULT_PAGE_SIZE;
}
if (pageSize > PageConstant.MAX_PAGE_SIZE) {
pageSize = PageConstant.MAX_PAGE_SIZE;
}
example.setOrderByClause("`timestamp` DESC");
PageHelper.startPage(startIndex, pageSize);
List<BlockHeader> list = this.blockHeaderRepository.selectByPagerEx(example);
PageInfo<BlockHeader> pageInfo = new PageInfo<>(list);
return pageInfo;
}
} }
...@@ -8,7 +8,6 @@ import com.wuban.tron.explore.dao.*; ...@@ -8,7 +8,6 @@ import com.wuban.tron.explore.dao.*;
import com.wuban.tron.explore.domain.*; import com.wuban.tron.explore.domain.*;
import com.wuban.tron.explore.entity.*; import com.wuban.tron.explore.entity.*;
import com.wuban.tron.explore.entity.example.TransactionExample; import com.wuban.tron.explore.entity.example.TransactionExample;
import com.wuban.tron.explore.fetch.Executor;
import com.wuban.tron.explore.service.TransactionService; import com.wuban.tron.explore.service.TransactionService;
import com.wuban.tron.explore.util.BigDecimalUtil; import com.wuban.tron.explore.util.BigDecimalUtil;
import com.wuban.tron.explore.util.DateUtil; import com.wuban.tron.explore.util.DateUtil;
...@@ -24,6 +23,8 @@ import org.springframework.stereotype.Service; ...@@ -24,6 +23,8 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.tron.common.utils.ByteArray;
import org.tron.walletserver.WalletApi;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.BigInteger; import java.math.BigInteger;
...@@ -54,8 +55,6 @@ public class TransactionServiceImpl implements TransactionService { ...@@ -54,8 +55,6 @@ public class TransactionServiceImpl implements TransactionService {
private final StringRedisTemplate stringRedisTemplate; private final StringRedisTemplate stringRedisTemplate;
private Executor excutor;
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void save(List<TronResponseData> dataList) { public void save(List<TronResponseData> dataList) {
...@@ -103,17 +102,31 @@ public class TransactionServiceImpl implements TransactionService { ...@@ -103,17 +102,31 @@ public class TransactionServiceImpl implements TransactionService {
区块头、区块交易、hex持久化 区块头、区块交易、hex持久化
*/ */
this.blockHeaderRepository.batchInsert(headerList); this.blockHeaderRepository.batchInsert(headerList);
Set<String> set = new HashSet<>(); Set<String> hexSet = new HashSet<>();
Set<String> base58Set = new HashSet<>();
if (transactionList.size() != 0) { if (transactionList.size() != 0) {
transactionList.forEach(o -> { transactionList.forEach(o -> {
// hex 数据转换成base58
String ownerAddress;
String toAddress;
String contractAddress;
if (!StringUtils.isEmpty(o.getOwnerAddress())) { if (!StringUtils.isEmpty(o.getOwnerAddress())) {
set.add(o.getOwnerAddress()); hexSet.add(o.getOwnerAddress());
ownerAddress = WalletApi.encode58Check(ByteArray.fromHexString(o.getOwnerAddress()));
o.setOwnerAddress(ownerAddress);
base58Set.add(ownerAddress);
} }
if (!StringUtils.isEmpty(o.getToAddress())) { if (!StringUtils.isEmpty(o.getToAddress())) {
set.add(o.getToAddress()); hexSet.add(o.getToAddress());
toAddress = WalletApi.encode58Check(ByteArray.fromHexString(o.getToAddress()));
o.setToAddress(toAddress);
base58Set.add(toAddress);
} }
if (!StringUtils.isEmpty(o.getContractAddress())) { if (!StringUtils.isEmpty(o.getContractAddress())) {
set.add(o.getContractAddress()); hexSet.add(o.getContractAddress());
contractAddress = WalletApi.encode58Check(ByteArray.fromHexString(o.getContractAddress()));
o.setContractAddress(contractAddress);
base58Set.add(contractAddress);
} }
}); });
this.transactionRepository.batchInsert(transactionList); this.transactionRepository.batchInsert(transactionList);
...@@ -127,12 +140,10 @@ public class TransactionServiceImpl implements TransactionService { ...@@ -127,12 +140,10 @@ public class TransactionServiceImpl implements TransactionService {
this.lastBlockRepository.updateCurBlockNumById(lastBlock); this.lastBlockRepository.updateCurBlockNumById(lastBlock);
log.info("已同步数据区块高度num:{}",headerList.get(0).getNumber()); log.info("已同步数据区块高度num:{}",headerList.get(0).getNumber());
List<Address> records = transferAddress(set); List<Address> records = transferAddress(base58Set);
if (!CollectionUtils.isEmpty(records)) { if (!CollectionUtils.isEmpty(records)) {
this.addressRepository.batchInsertOnDuplicateKey(records); this.addressRepository.batchInsertOnDuplicateKey(records);
/* AccountBalanceTask task = new AccountBalanceTask(set); addressPushRedis(hexSet);
excutor.execute(task);*/
addressPushRedis(set);
} }
} }
...@@ -204,6 +215,7 @@ public class TransactionServiceImpl implements TransactionService { ...@@ -204,6 +215,7 @@ public class TransactionServiceImpl implements TransactionService {
Contract contract = rawData.getContract().get(0); Contract contract = rawData.getContract().get(0);
ContractParameter contractParameter = contract.getParameter(); ContractParameter contractParameter = contract.getParameter();
ContractParameterValue val = contractParameter.getValue(); ContractParameterValue val = contractParameter.getValue();
Transaction tr = Transaction.builder() Transaction tr = Transaction.builder()
.blockId(blockId) .blockId(blockId)
.txId(o.getTxID()) .txId(o.getTxID())
...@@ -229,13 +241,6 @@ public class TransactionServiceImpl implements TransactionService { ...@@ -229,13 +241,6 @@ public class TransactionServiceImpl implements TransactionService {
return retList; return retList;
} }
/*public synchronized void initExcutor() {
if (excutor == null) {
excutor = new Executor(Constant.EXCUTOR_NAME_ACCOUNT, 3);
new AccountBalanceTask();
}
}*/
@Override @Override
public Long getBlockMinTime() { public Long getBlockMinTime() {
return this.blockHeaderRepository.selectBlockMinTime(); return this.blockHeaderRepository.selectBlockMinTime();
...@@ -252,6 +257,7 @@ public class TransactionServiceImpl implements TransactionService { ...@@ -252,6 +257,7 @@ public class TransactionServiceImpl implements TransactionService {
@Override @Override
public void censusBlockByDate(String startDate, String endDate) { public void censusBlockByDate(String startDate, String endDate) {
log.info("按天统计交易数据开始startDate:{} 结束endDate:{}", startDate, endDate);
if (StringUtils.isEmpty(endDate) || (startDate.equals(endDate))) { if (StringUtils.isEmpty(endDate) || (startDate.equals(endDate))) {
String _startDate = startDate + " 00:00:00"; String _startDate = startDate + " 00:00:00";
String _endDate = startDate + " 23:59:59"; String _endDate = startDate + " 23:59:59";
...@@ -263,14 +269,14 @@ public class TransactionServiceImpl implements TransactionService { ...@@ -263,14 +269,14 @@ public class TransactionServiceImpl implements TransactionService {
while (true) { while (true) {
String _startDate = date + " 00:00:00"; String _startDate = date + " 00:00:00";
String _endDate = date + " 23:59:59"; String _endDate = date + " 23:59:59";
this.census(startDate, _startDate, _endDate); this.census(date, _startDate, _endDate);
if (date == endDate) { if (date.equals(endDate)) {
break; break;
} }
Date nextDate = DateUtil.addDays(new Date(), 1); Date nextDate = DateUtil.addDays(date, 1);
date = DateUtil.getFormatDate(nextDate,DateUtil.PATTERN_YMD); date = DateUtil.getFormatDate(nextDate, DateUtil.PATTERN_YMD);
} }
} }
...@@ -316,7 +322,7 @@ public class TransactionServiceImpl implements TransactionService { ...@@ -316,7 +322,7 @@ public class TransactionServiceImpl implements TransactionService {
} }
@Override @Override
public PageInfo<Transaction> selectListByAddress(String address, int type, Integer startIndex, Integer pageSize) { public PageInfo<Transaction> selectListByAddress(String address, Integer type, Integer startIndex, Integer pageSize) {
Date date; Date date;
switch (type) { switch (type) {
case 1: case 1:
...@@ -329,10 +335,10 @@ public class TransactionServiceImpl implements TransactionService { ...@@ -329,10 +335,10 @@ public class TransactionServiceImpl implements TransactionService {
date = DateUtil.addDays(new Date(), -30); date = DateUtil.addDays(new Date(), -30);
break; break;
default: default:
date = DateUtil.addDays(new Date(), -7); date = null;
} }
String str = DateUtil.getFormatDate(date, DateUtil.PATTERN_YMD_HMS); String str = DateUtil.getFormatDate(date, DateUtil.PATTERN_YMD_HMS);
long t = DateUtil.getDateFromDateStr(str); long t = DateUtil.getDateFromDateStr(str, DateUtil.PATTERN_YMD_HMS);
if (startIndex == null) { if (startIndex == null) {
startIndex = PageConstant.DEFAULT_START_INDEX; startIndex = PageConstant.DEFAULT_START_INDEX;
...@@ -353,9 +359,38 @@ public class TransactionServiceImpl implements TransactionService { ...@@ -353,9 +359,38 @@ public class TransactionServiceImpl implements TransactionService {
return pageInfo; return pageInfo;
} }
/**
* 根据账户地址查询交易信息
*
* @param address 账户地址
* @param startIndex
* @param pageSize
* @return
*/
@Override
public PageInfo<Transaction> selectPageByAddress(String address, Integer startIndex, Integer pageSize) {
if (startIndex == null) {
startIndex = PageConstant.DEFAULT_START_INDEX;
}
if (pageSize == null) {
pageSize = PageConstant.DEFAULT_PAGE_SIZE;
}
if (pageSize > PageConstant.MAX_PAGE_SIZE) {
pageSize = PageConstant.MAX_PAGE_SIZE;
}
PageHelper.startPage(startIndex, pageSize);
List<Transaction> list = this.transactionRepository.selectPageByAddress(address);
PageInfo<Transaction> pageInfo = new PageInfo<>(list);
return pageInfo;
}
private void census(String date, String startDate, String endDate) { private void census(String date, String startDate, String endDate) {
Long startDateSeconds = DateUtil.getDateFromDateStr(startDate); Long startDateSeconds = DateUtil.getDateFromDateStr(startDate, DateUtil.PATTERN_YMD_HMS);
Long endDateSeconds = DateUtil.getDateFromDateStr(endDate); Long endDateSeconds = DateUtil.getDateFromDateStr(endDate, DateUtil.PATTERN_YMD_HMS);
BlockDayCensus data = this.blockDayCensusRepository.censusBlockByTime(startDateSeconds, endDateSeconds); BlockDayCensus data = this.blockDayCensusRepository.censusBlockByTime(startDateSeconds, endDateSeconds);
if (data != null) { if (data != null) {
Long totalSeconds = 24 * 60 * 60L; Long totalSeconds = 24 * 60 * 60L;
...@@ -367,6 +402,9 @@ public class TransactionServiceImpl implements TransactionService { ...@@ -367,6 +402,9 @@ public class TransactionServiceImpl implements TransactionService {
BigDecimal averBlockBytes = BigDecimalUtil.getDevide(new BigDecimal(data.getTotalBlockBytes()), new BigDecimal(data.getGenBlockTotalNum())); BigDecimal averBlockBytes = BigDecimalUtil.getDevide(new BigDecimal(data.getTotalBlockBytes()), new BigDecimal(data.getGenBlockTotalNum()));
data.setAverBlockBytes(averBlockBytes.intValue()); data.setAverBlockBytes(averBlockBytes.intValue());
this.blockDayCensusRepository.insert(data); this.blockDayCensusRepository.insert(data);
log.info("date:{} 交易数据已统计完成",date);
} else {
log.info("date:{} 暂无交易数据统计",date);
} }
} }
......
...@@ -21,46 +21,36 @@ public class ApiResponse<T> { ...@@ -21,46 +21,36 @@ public class ApiResponse<T> {
public static final String DEFAULT_SUCCESS_MESSAGE = "操作成功"; public static final String DEFAULT_SUCCESS_MESSAGE = "操作成功";
private Boolean success; private Integer error;
private Integer code; private String err_msg;
private String msg;
private T data; private T data;
public ApiResponse() { public ApiResponse() {
} }
public ApiResponse(Boolean success, Integer code, String message, T data) { public ApiResponse(Integer error, String message, T data) {
this.success = success; this.error = error;
this.code = code; this.err_msg = message;
this.msg = message;
this.data = data; this.data = data;
} }
public Boolean getSuccess() { public Integer getError() {
return success; return error;
} }
public void setSuccess(Boolean success) { public void setError(Integer error) {
this.success = success; this.error = error;
} }
public Integer getCode() { public String getErr_msg() {
return code; return err_msg;
} }
public void setCode(Integer code) { public void setErr_msg(String err_msg) {
this.code = code; this.err_msg = err_msg;
} }
public String getMsg() { public T getData() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public Object getData() {
return data; return data;
} }
......
...@@ -165,6 +165,31 @@ public class DateUtil { ...@@ -165,6 +165,31 @@ public class DateUtil {
* @return * @return
*/ */
public static Date addDays(final Date date, final int days) { public static Date addDays(final Date date, final int days) {
final Calendar cal = Calendar.getInstance();
if (date != null) {
cal.setTime(date);
}
cal.add(0, days);
return cal.getTime();
}
/**
* date 日期加上或减去几天
*
* @param dateStr
* @param days
* @return
*/
public static Date addDays(final String dateStr, final int days) {
Date date;
try {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
date = format.parse(dateStr);
} catch (ParseException e) {
return null;
}
final Calendar cal = Calendar.getInstance(); final Calendar cal = Calendar.getInstance();
if (date != null) { if (date != null) {
cal.setTime(date); cal.setTime(date);
...@@ -231,8 +256,8 @@ public class DateUtil { ...@@ -231,8 +256,8 @@ public class DateUtil {
* @param date * @param date
* @return * @return
*/ */
public static Long getDateFromDateStr(String date) { public static Long getDateFromDateStr(String date, String pattern) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat format = new SimpleDateFormat(pattern);
try { try {
Date dateTime = format.parse(date); Date dateTime = format.parse(date);
return dateTime.getTime(); return dateTime.getTime();
......
...@@ -12,11 +12,11 @@ package com.wuban.tron.explore.util; ...@@ -12,11 +12,11 @@ package com.wuban.tron.explore.util;
public class ErrorResponseData extends ApiResponse { public class ErrorResponseData extends ApiResponse {
public ErrorResponseData(Integer code, String message) { public ErrorResponseData(Integer code, String message) {
super(false, code, message, null); super(code, message, null);
} }
public ErrorResponseData(Integer code, String message, Object object) { public ErrorResponseData(Integer code, String message, Object object) {
super(false, code, message, object); super(code, message, object);
} }
} }
...@@ -12,14 +12,14 @@ package com.wuban.tron.explore.util; ...@@ -12,14 +12,14 @@ package com.wuban.tron.explore.util;
public class SuccessResponseData<T> extends ApiResponse { public class SuccessResponseData<T> extends ApiResponse {
public SuccessResponseData() { public SuccessResponseData() {
super(true, OK, DEFAULT_SUCCESS_MESSAGE, null); super(OK, DEFAULT_SUCCESS_MESSAGE, null);
} }
public SuccessResponseData(T object) { public SuccessResponseData(T object) {
super(true, OK, DEFAULT_SUCCESS_MESSAGE, object); super(OK, DEFAULT_SUCCESS_MESSAGE, object);
} }
public SuccessResponseData(String message, Object object) { public SuccessResponseData(String message, Object object) {
super(true, OK, message, object); super(OK, message, object);
} }
} }
# config
tron:
site: https://api.shasta.trongrid.io
spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://123.56.5.114:13306/test_tron?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
username: root
password: root123456
# 初始化大小,最小,最大
initialSize: 20
minIdle: 5
maxActive: 100
# 配置获取连接等待超时的时间
maxWait: 60000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
timeBetweenEvictionRunsMillis: 60000
# 配置一个连接在池中最小生存的时间,单位是毫秒St
minEvictableIdleTimeMillis: 300000
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
# 打开PSCache,并且指定每个连接上PSCache的大小
poolPreparedStatements: true
maxPoolPreparedStatementPerConnectionSize: 20
redis:
host: 123.56.5.114
port: 6379
jedis:
pool:
max-active: 1024
max-idle: 200
max-wait: 10000
min-idle: 100
timeout: 10000
password: 123456
database: 2
\ No newline at end of file
# config
tron:
site: https://api.shasta.trongrid.io
spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://123.56.5.114:13306/test_tron?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
username: root
password: root123456
# 初始化大小,最小,最大
initialSize: 20
minIdle: 5
maxActive: 100
# 配置获取连接等待超时的时间
maxWait: 60000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
timeBetweenEvictionRunsMillis: 60000
# 配置一个连接在池中最小生存的时间,单位是毫秒St
minEvictableIdleTimeMillis: 300000
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
# 打开PSCache,并且指定每个连接上PSCache的大小
poolPreparedStatements: true
maxPoolPreparedStatementPerConnectionSize: 20
redis:
host: 123.56.5.114
port: 6379
jedis:
pool:
max-active: 1024
max-idle: 200
max-wait: 10000
min-idle: 100
timeout: 10000
password: 123456
database: 2
\ No newline at end of file
server: server:
port: 8080 port: 8080
# config
spring: spring:
datasource: profiles:
type: com.alibaba.druid.pool.DruidDataSource active:
driverClassName: com.mysql.cj.jdbc.Driver - dev
url: jdbc:mysql://coupon-d.mysql.db.wuban.net.cn:30101/tron-explore?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai application:
username: root name: tron-explore
password: ^osyBXr7}duMefFb
# 初始化大小,最小,最大
initialSize: 5
minIdle: 5
maxActive: 20
# 配置获取连接等待超时的时间
maxWait: 60000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
timeBetweenEvictionRunsMillis: 60000
# 配置一个连接在池中最小生存的时间,单位是毫秒St
minEvictableIdleTimeMillis: 300000
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
# 打开PSCache,并且指定每个连接上PSCache的大小
poolPreparedStatements: true
maxPoolPreparedStatementPerConnectionSize: 20
redis:
host: coupon.redis.db.wuban.net.cn
port: 30104
jedis:
pool:
max-active: 1024
max-idle: 200
max-wait: 10000
min-idle: 100
timeout: 10000
password: lk_2AF|;29l3qvZJ
database: 8
mybatis: mybatis:
mapper-locations: classpath:*.xml mapper-locations: classpath:*.xml
type-aliases-package: com.wuban.tron.explore.entity type-aliases-package: com.wuban.tron.explore.entity
logging: logging:
level: level:
com.wuban.tron.explore.dao: error com.wuban.tron.explore.dao: debug
\ No newline at end of file \ No newline at end of file
...@@ -266,4 +266,16 @@ ...@@ -266,4 +266,16 @@
from <include refid="Table_Name"/> from <include refid="Table_Name"/>
</select> </select>
<select id="selectByPagerEx" resultMap="BlockHeaderMap" parameterType="java.util.Map">
select
<include refid="Base_Column_List"/>
from <include refid="Table_Name"/>
<if test="example != null">
<include refid="Example_Where_Clause"/>
</if>
<if test="example.orderByClause != null">
order by ${example.orderByClause}
</if>
</select>
</mapper> </mapper>
...@@ -305,4 +305,12 @@ ...@@ -305,4 +305,12 @@
where (`timestamp` &gt; #{t}) and (owner_address = #{address} or to_address = #{address}) where (`timestamp` &gt; #{t}) and (owner_address = #{address} or to_address = #{address})
order by `timestamp` desc order by `timestamp` desc
</select> </select>
<select id="selectPageByAddress" resultMap="TransactionMap" parameterType="java.util.Map">
select
tx_id,owner_address,contract_address,to_address,`number`,`timestamp`,amount
from <include refid="Table_Name"/>
where (owner_address = #{address} or to_address = #{address} or contract_address= #{address})
order by `timestamp` desc
</select>
</mapper> </mapper>
...@@ -53,7 +53,7 @@ class BlockHeaderRepositoryTest { ...@@ -53,7 +53,7 @@ class BlockHeaderRepositoryTest {
void testDateDely() { void testDateDely() {
Date nextDate = DateUtil.addDays(new Date(), 1); Date nextDate = DateUtil.addDays(new Date(), 1);
String date = DateUtil.getFormatDate(nextDate,"yyyy-MM-dd") + " 00:00:01"; String date = DateUtil.getFormatDate(nextDate,"yyyy-MM-dd") + " 00:00:01";
Long millis = (DateUtil.getDateFromDateStr(date) - System.currentTimeMillis())/1000; Long millis = (DateUtil.getDateFromDateStr(date, DateUtil.PATTERN_YMD_HMS) - System.currentTimeMillis())/1000;
System.out.println(millis+"--------------------"); System.out.println(millis+"--------------------");
} }
......
...@@ -5,8 +5,6 @@ import com.wuban.tron.explore.entity.Transaction; ...@@ -5,8 +5,6 @@ import com.wuban.tron.explore.entity.Transaction;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.tron.common.utils.ByteArray;
import org.tron.walletserver.WalletApi;
import java.util.List; import java.util.List;
...@@ -32,9 +30,9 @@ class TransactionRepositoryTest extends BaseTest { ...@@ -32,9 +30,9 @@ class TransactionRepositoryTest extends BaseTest {
@Test @Test
void test() { void test() {
String hexString = "416c4858d8d3435d278a34146d49dd7e126879ba0d"; /* String hexString = "416c4858d8d3435d278a34146d49dd7e126879ba0d";
String base58check = WalletApi.encode58Check(ByteArray.fromHexString(hexString)); String base58check = WalletApi.encode58Check(ByteArray.fromHexString(hexString));
System.out.println(base58check); System.out.println(base58check);*/
} }
} }
\ No newline at end of file
...@@ -129,7 +129,7 @@ CREATE TABLE `tron_transaction` ( ...@@ -129,7 +129,7 @@ CREATE TABLE `tron_transaction` (
DROP TABLE IF EXISTS `tron_transaction_hex`; DROP TABLE IF EXISTS `tron_transaction_hex`;
CREATE TABLE `tron_transaction_hex` ( CREATE TABLE `tron_transaction_hex` (
`id` bigint(20) NOT NULL AUTO_INCREMENT, `id` bigint(20) NOT NULL AUTO_INCREMENT,
`hex` text COLLATE utf8mb4_unicode_ci, `hex` longtext COLLATE utf8mb4_unicode_ci,
`block_id` varchar(80) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '区块ID', `block_id` varchar(80) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '区块ID',
`tx_id` varchar(80) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '交易ID', `tx_id` varchar(80) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '交易ID',
`signature` varchar(150) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `signature` varchar(150) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment