Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
tron-explore
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张建华@五瓣科技
tron-explore
Commits
dee5d47e
Commit
dee5d47e
authored
Nov 17, 2020
by
jianhua.zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
波场浏览器JAVA版
parent
48b2532a
Changes
31
Hide whitespace changes
Inline
Side-by-side
Showing
31 changed files
with
956 additions
and
107 deletions
+956
-107
Bootstrapper.java
src/main/java/com/wuban/tron/explore/Bootstrapper.java
+1
-1
Constant.java
src/main/java/com/wuban/tron/explore/constant/Constant.java
+2
-1
CensusController.java
...a/com/wuban/tron/explore/controller/CensusController.java
+6
-1
TransactionControllerV1.java
...n/tron/explore/controller/v1/TransactionControllerV1.java
+411
-0
BlockHeaderRepository.java
...ava/com/wuban/tron/explore/dao/BlockHeaderRepository.java
+9
-0
TransactionRepository.java
...ava/com/wuban/tron/explore/dao/TransactionRepository.java
+11
-0
Executor.java
src/main/java/com/wuban/tron/explore/fetch/Executor.java
+1
-1
AddressBalanceHandler.java
...com/wuban/tron/explore/handler/AddressBalanceHandler.java
+5
-1
AccountInfoModel.java
...m/wuban/tron/explore/param/response/AccountInfoModel.java
+35
-0
AddessInfoModel.java
...om/wuban/tron/explore/param/response/AddessInfoModel.java
+34
-0
BlockInfoModel.java
...com/wuban/tron/explore/param/response/BlockInfoModel.java
+70
-0
HomeChartModel.java
...com/wuban/tron/explore/param/response/HomeChartModel.java
+12
-0
ResDataModel.java
...a/com/wuban/tron/explore/param/response/ResDataModel.java
+20
-0
TransInfoModel.java
...com/wuban/tron/explore/param/response/TransInfoModel.java
+52
-0
BaseCommonService.java
...ava/com/wuban/tron/explore/service/BaseCommonService.java
+5
-1
BlockHeaderService.java
...va/com/wuban/tron/explore/service/BlockHeaderService.java
+13
-0
TransactionService.java
...va/com/wuban/tron/explore/service/TransactionService.java
+12
-1
BlockHeaderServiceImpl.java
...ban/tron/explore/service/impl/BlockHeaderServiceImpl.java
+33
-0
TransactionServiceImpl.java
...ban/tron/explore/service/impl/TransactionServiceImpl.java
+65
-27
ApiResponse.java
src/main/java/com/wuban/tron/explore/util/ApiResponse.java
+14
-24
DateUtil.java
src/main/java/com/wuban/tron/explore/util/DateUtil.java
+27
-2
ErrorResponseData.java
...n/java/com/wuban/tron/explore/util/ErrorResponseData.java
+2
-2
SuccessResponseData.java
...java/com/wuban/tron/explore/util/SuccessResponseData.java
+3
-3
application-dev.yml
src/main/resources/application-dev.yml
+41
-0
application-test.yml
src/main/resources/application-test.yml
+41
-0
application.yml
src/main/resources/application.yml
+7
-36
BlockHeaderMapper.xml
src/main/resources/mapper/BlockHeaderMapper.xml
+12
-0
TransactionMapper.xml
src/main/resources/mapper/TransactionMapper.xml
+8
-0
BlockHeaderRepositoryTest.java
...com/wuban/tron/explore/dao/BlockHeaderRepositoryTest.java
+1
-1
TransactionRepositoryTest.java
...com/wuban/tron/explore/dao/TransactionRepositoryTest.java
+2
-4
tron-explore.sql
tron-explore.sql
+1
-1
No files found.
src/main/java/com/wuban/tron/explore/Bootstrapper.java
View file @
dee5d47e
...
...
@@ -70,7 +70,7 @@ public class Bootstrapper {
private
long
getInitialDelay
()
{
Date
nextDate
=
DateUtil
.
addDays
(
new
Date
(),
1
);
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
;
}
...
...
src/main/java/com/wuban/tron/explore/constant/Constant.java
View file @
dee5d47e
package
com
.
wuban
.
tron
.
explore
.
constant
;
import
okhttp3.MediaType
;
import
org.springframework.beans.factory.annotation.Value
;
/**
* <core>常量定义类</core>
...
...
@@ -45,7 +46,7 @@ public class Constant {
/**
* 用户地址长度
*/
public
static
final
int
USER_ADDRESS_LEN
=
42
;
public
static
final
int
USER_ADDRESS_LEN
=
34
;
/**
* txID长度
...
...
src/main/java/com/wuban/tron/explore/controller/CensusController.java
View file @
dee5d47e
...
...
@@ -11,6 +11,9 @@ import org.springframework.web.bind.annotation.RequestMethod;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.validation.Valid
;
import
java.util.concurrent.LinkedBlockingQueue
;
import
java.util.concurrent.ThreadPoolExecutor
;
import
java.util.concurrent.TimeUnit
;
/**
* <core>区块统计API</core>
...
...
@@ -26,9 +29,11 @@ public class CensusController {
private
final
TransactionService
transactionService
;
private
final
ThreadPoolExecutor
pool
=
new
ThreadPoolExecutor
(
1
,
1
,
0L
,
TimeUnit
.
SECONDS
,
new
LinkedBlockingQueue
<>());
@RequestMapping
(
method
=
RequestMethod
.
POST
)
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
())
);
}
}
src/main/java/com/wuban/tron/explore/controller/v1/TransactionControllerV1.java
0 → 100644
View file @
dee5d47e
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
;
}
}
}
src/main/java/com/wuban/tron/explore/dao/BlockHeaderRepository.java
View file @
dee5d47e
package
com
.
wuban
.
tron
.
explore
.
dao
;
import
com.wuban.tron.explore.entity.BlockHeader
;
import
com.wuban.tron.explore.entity.Transaction
;
import
com.wuban.tron.explore.entity.example.BlockHeaderExample
;
import
org.apache.ibatis.annotations.Param
;
import
org.springframework.stereotype.Repository
;
...
...
@@ -46,4 +47,12 @@ public interface BlockHeaderRepository {
*/
BlockHeader
selectOneByExample
(
@Param
(
"example"
)
BlockHeaderExample
example
);
/**
* 分页查询
*
* @param example 查询条件参数
* @return 分页记录列表
*/
List
<
BlockHeader
>
selectByPagerEx
(
@Param
(
"example"
)
BlockHeaderExample
example
);
}
src/main/java/com/wuban/tron/explore/dao/TransactionRepository.java
View file @
dee5d47e
...
...
@@ -59,4 +59,15 @@ public interface TransactionRepository {
*/
List
<
Transaction
>
selectListByAddress
(
@Param
(
"address"
)
String
address
,
@Param
(
"t"
)
long
timestamp
);
/**
* 根据账户地址查询交易信息
*
* @param address 账户地址
*
*
* @return
*/
List
<
Transaction
>
selectPageByAddress
(
@Param
(
"address"
)
String
address
);
}
src/main/java/com/wuban/tron/explore/fetch/Executor.java
View file @
dee5d47e
...
...
@@ -20,7 +20,7 @@ import java.util.concurrent.atomic.AtomicInteger;
@Slf4j
public
class
Executor
{
private
static
final
int
SIZE
=
1
0
;
private
static
final
int
SIZE
=
1
5
;
private
final
List
<
AbstractJob
>
jobList
=
new
ArrayList
<>();
private
final
String
name
;
private
ThreadPoolExecutor
pool
;
...
...
src/main/java/com/wuban/tron/explore/handler/AddressBalanceHandler.java
View file @
dee5d47e
...
...
@@ -8,6 +8,8 @@ import com.wuban.tron.explore.service.AddressService;
import
com.wuban.tron.explore.util.SpringContextUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.util.CollectionUtils
;
import
org.tron.common.utils.ByteArray
;
import
org.tron.walletserver.WalletApi
;
import
java.util.List
;
import
java.util.concurrent.LinkedBlockingQueue
;
...
...
@@ -53,7 +55,9 @@ public class AddressBalanceHandler extends AbstractJob implements IAddressBalanc
public
void
flush
(
List
<
TronAccount
>
e
)
{
if
(!
CollectionUtils
.
isEmpty
(
e
))
{
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
());
this
.
addressService
.
updateById
(
obj
);
log
.
info
(
"更新账户余额 account:{}"
,
obj
.
toString
());
...
...
src/main/java/com/wuban/tron/explore/param/response/AccountInfoModel.java
0 → 100644
View file @
dee5d47e
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
();
}
}
src/main/java/com/wuban/tron/explore/param/response/AddessInfoModel.java
0 → 100644
View file @
dee5d47e
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
();
}
}
src/main/java/com/wuban/tron/explore/param/response/BlockInfoModel.java
0 → 100644
View file @
dee5d47e
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
();
}
}
src/main/java/com/wuban/tron/explore/param/response/HomeChartModel.java
0 → 100644
View file @
dee5d47e
package
com
.
wuban
.
tron
.
explore
.
param
.
response
;
import
lombok.Data
;
@Data
public
class
HomeChartModel
{
private
int
id
;
private
long
time
;
private
int
count
;
}
src/main/java/com/wuban/tron/explore/param/response/ResDataModel.java
0 → 100644
View file @
dee5d47e
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
;
}
src/main/java/com/wuban/tron/explore/param/response/TransInfoModel.java
0 → 100644
View file @
dee5d47e
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
();
}
}
src/main/java/com/wuban/tron/explore/service/BaseCommonService.java
View file @
dee5d47e
...
...
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
import
com.wuban.tron.explore.constant.Constant
;
import
lombok.extern.slf4j.Slf4j
;
import
okhttp3.*
;
import
org.springframework.beans.factory.annotation.Value
;
import
java.io.IOException
;
import
java.util.Map
;
...
...
@@ -36,6 +37,9 @@ public abstract class BaseCommonService {
*/
protected
static
final
String
GET_ACCOUNT
=
PREFIX
+
"/getaccount"
;
@Value
(
"${tron.site}"
)
private
String
tronSite
;
/**
* http请求
*
...
...
@@ -79,7 +83,7 @@ public abstract class BaseCommonService {
protected
Request
builder
(
String
uri
,
Map
<
String
,
Object
>
paramMap
)
{
String
param
=
JSON
.
toJSONString
(
paramMap
);
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
();
}
...
...
src/main/java/com/wuban/tron/explore/service/BlockHeaderService.java
View file @
dee5d47e
package
com
.
wuban
.
tron
.
explore
.
service
;
import
com.github.pagehelper.PageInfo
;
import
com.wuban.tron.explore.entity.BlockHeader
;
import
com.wuban.tron.explore.entity.example.BlockHeaderExample
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
/**
* <core>区块头服务接口</core>
*
...
...
@@ -20,4 +23,14 @@ public interface BlockHeaderService {
*/
BlockHeader
getOneByExample
(
@Param
(
"example"
)
BlockHeaderExample
example
);
/**
* 分页查询
*
* @param startIndex
* @param pageSize
* @param example 查询条件参数
* @return 分页记录列表
*/
PageInfo
<
BlockHeader
>
getByPagerEx
(
Integer
startIndex
,
Integer
pageSize
,
@Param
(
"example"
)
BlockHeaderExample
example
);
}
src/main/java/com/wuban/tron/explore/service/TransactionService.java
View file @
dee5d47e
...
...
@@ -77,7 +77,18 @@ public interface TransactionService {
* @param pageSize
* @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
);
}
src/main/java/com/wuban/tron/explore/service/impl/BlockHeaderServiceImpl.java
View file @
dee5d47e
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.entity.BlockHeader
;
import
com.wuban.tron.explore.entity.example.BlockHeaderExample
;
...
...
@@ -8,6 +11,8 @@ import lombok.RequiredArgsConstructor;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
/**
* <core>区块头服务接口实现类</core>
*
...
...
@@ -31,5 +36,33 @@ public class BlockHeaderServiceImpl implements BlockHeaderService {
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
;
}
}
src/main/java/com/wuban/tron/explore/service/impl/TransactionServiceImpl.java
View file @
dee5d47e
...
...
@@ -8,7 +8,6 @@ import com.wuban.tron.explore.dao.*;
import
com.wuban.tron.explore.domain.*
;
import
com.wuban.tron.explore.entity.*
;
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.util.BigDecimalUtil
;
import
com.wuban.tron.explore.util.DateUtil
;
...
...
@@ -24,6 +23,8 @@ import org.springframework.stereotype.Service;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.StringUtils
;
import
org.tron.common.utils.ByteArray
;
import
org.tron.walletserver.WalletApi
;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
...
...
@@ -54,8 +55,6 @@ public class TransactionServiceImpl implements TransactionService {
private
final
StringRedisTemplate
stringRedisTemplate
;
private
Executor
excutor
;
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
save
(
List
<
TronResponseData
>
dataList
)
{
...
...
@@ -103,17 +102,31 @@ public class TransactionServiceImpl implements TransactionService {
区块头、区块交易、hex持久化
*/
this
.
blockHeaderRepository
.
batchInsert
(
headerList
);
Set
<
String
>
set
=
new
HashSet
<>();
Set
<
String
>
hexSet
=
new
HashSet
<>();
Set
<
String
>
base58Set
=
new
HashSet
<>();
if
(
transactionList
.
size
()
!=
0
)
{
transactionList
.
forEach
(
o
->
{
// hex 数据转换成base58
String
ownerAddress
;
String
toAddress
;
String
contractAddress
;
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
()))
{
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
()))
{
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
);
...
...
@@ -127,12 +140,10 @@ public class TransactionServiceImpl implements TransactionService {
this
.
lastBlockRepository
.
updateCurBlockNumById
(
lastBlock
);
log
.
info
(
"已同步数据区块高度num:{}"
,
headerList
.
get
(
0
).
getNumber
());
List
<
Address
>
records
=
transferAddress
(
s
et
);
List
<
Address
>
records
=
transferAddress
(
base58S
et
);
if
(!
CollectionUtils
.
isEmpty
(
records
))
{
this
.
addressRepository
.
batchInsertOnDuplicateKey
(
records
);
/* AccountBalanceTask task = new AccountBalanceTask(set);
excutor.execute(task);*/
addressPushRedis
(
set
);
addressPushRedis
(
hexSet
);
}
}
...
...
@@ -204,6 +215,7 @@ public class TransactionServiceImpl implements TransactionService {
Contract
contract
=
rawData
.
getContract
().
get
(
0
);
ContractParameter
contractParameter
=
contract
.
getParameter
();
ContractParameterValue
val
=
contractParameter
.
getValue
();
Transaction
tr
=
Transaction
.
builder
()
.
blockId
(
blockId
)
.
txId
(
o
.
getTxID
())
...
...
@@ -229,13 +241,6 @@ public class TransactionServiceImpl implements TransactionService {
return
retList
;
}
/*public synchronized void initExcutor() {
if (excutor == null) {
excutor = new Executor(Constant.EXCUTOR_NAME_ACCOUNT, 3);
new AccountBalanceTask();
}
}*/
@Override
public
Long
getBlockMinTime
()
{
return
this
.
blockHeaderRepository
.
selectBlockMinTime
();
...
...
@@ -252,6 +257,7 @@ public class TransactionServiceImpl implements TransactionService {
@Override
public
void
censusBlockByDate
(
String
startDate
,
String
endDate
)
{
log
.
info
(
"按天统计交易数据开始startDate:{} 结束endDate:{}"
,
startDate
,
endDate
);
if
(
StringUtils
.
isEmpty
(
endDate
)
||
(
startDate
.
equals
(
endDate
)))
{
String
_startDate
=
startDate
+
" 00:00:00"
;
String
_endDate
=
startDate
+
" 23:59:59"
;
...
...
@@ -263,14 +269,14 @@ public class TransactionServiceImpl implements TransactionService {
while
(
true
)
{
String
_startDate
=
date
+
" 00:00:00"
;
String
_endDate
=
date
+
" 23:59:59"
;
this
.
census
(
startD
ate
,
_startDate
,
_endDate
);
this
.
census
(
d
ate
,
_startDate
,
_endDate
);
if
(
date
==
endDate
)
{
if
(
date
.
equals
(
endDate
)
)
{
break
;
}
Date
nextDate
=
DateUtil
.
addDays
(
new
Date
()
,
1
);
date
=
DateUtil
.
getFormatDate
(
nextDate
,
DateUtil
.
PATTERN_YMD
);
Date
nextDate
=
DateUtil
.
addDays
(
date
,
1
);
date
=
DateUtil
.
getFormatDate
(
nextDate
,
DateUtil
.
PATTERN_YMD
);
}
}
...
...
@@ -316,7 +322,7 @@ public class TransactionServiceImpl implements TransactionService {
}
@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
;
switch
(
type
)
{
case
1
:
...
...
@@ -329,10 +335,10 @@ public class TransactionServiceImpl implements TransactionService {
date
=
DateUtil
.
addDays
(
new
Date
(),
-
30
);
break
;
default
:
date
=
DateUtil
.
addDays
(
new
Date
(),
-
7
)
;
date
=
null
;
}
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
)
{
startIndex
=
PageConstant
.
DEFAULT_START_INDEX
;
...
...
@@ -353,9 +359,38 @@ public class TransactionServiceImpl implements TransactionService {
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
)
{
Long
startDateSeconds
=
DateUtil
.
getDateFromDateStr
(
startDate
);
Long
endDateSeconds
=
DateUtil
.
getDateFromDateStr
(
endDate
);
Long
startDateSeconds
=
DateUtil
.
getDateFromDateStr
(
startDate
,
DateUtil
.
PATTERN_YMD_HMS
);
Long
endDateSeconds
=
DateUtil
.
getDateFromDateStr
(
endDate
,
DateUtil
.
PATTERN_YMD_HMS
);
BlockDayCensus
data
=
this
.
blockDayCensusRepository
.
censusBlockByTime
(
startDateSeconds
,
endDateSeconds
);
if
(
data
!=
null
)
{
Long
totalSeconds
=
24
*
60
*
60L
;
...
...
@@ -367,6 +402,9 @@ public class TransactionServiceImpl implements TransactionService {
BigDecimal
averBlockBytes
=
BigDecimalUtil
.
getDevide
(
new
BigDecimal
(
data
.
getTotalBlockBytes
()),
new
BigDecimal
(
data
.
getGenBlockTotalNum
()));
data
.
setAverBlockBytes
(
averBlockBytes
.
intValue
());
this
.
blockDayCensusRepository
.
insert
(
data
);
log
.
info
(
"date:{} 交易数据已统计完成"
,
date
);
}
else
{
log
.
info
(
"date:{} 暂无交易数据统计"
,
date
);
}
}
...
...
src/main/java/com/wuban/tron/explore/util/ApiResponse.java
View file @
dee5d47e
...
...
@@ -21,46 +21,36 @@ public class ApiResponse<T> {
public
static
final
String
DEFAULT_SUCCESS_MESSAGE
=
"操作成功"
;
private
Boolean
success
;
private
Integer
code
;
private
String
msg
;
private
Integer
error
;
private
String
err_msg
;
private
T
data
;
public
ApiResponse
()
{
}
public
ApiResponse
(
Boolean
success
,
Integer
code
,
String
message
,
T
data
)
{
this
.
success
=
success
;
this
.
code
=
code
;
this
.
msg
=
message
;
public
ApiResponse
(
Integer
error
,
String
message
,
T
data
)
{
this
.
error
=
error
;
this
.
err_msg
=
message
;
this
.
data
=
data
;
}
public
Boolean
getSuccess
()
{
return
success
;
public
Integer
getError
()
{
return
error
;
}
public
void
set
Success
(
Boolean
success
)
{
this
.
success
=
success
;
public
void
set
Error
(
Integer
error
)
{
this
.
error
=
error
;
}
public
Integer
getCode
()
{
return
code
;
public
String
getErr_msg
()
{
return
err_msg
;
}
public
void
set
Code
(
Integer
code
)
{
this
.
code
=
code
;
public
void
set
Err_msg
(
String
err_msg
)
{
this
.
err_msg
=
err_msg
;
}
public
String
getMsg
()
{
return
msg
;
}
public
void
setMsg
(
String
msg
)
{
this
.
msg
=
msg
;
}
public
Object
getData
()
{
public
T
getData
()
{
return
data
;
}
...
...
src/main/java/com/wuban/tron/explore/util/DateUtil.java
View file @
dee5d47e
...
...
@@ -165,6 +165,31 @@ public class DateUtil {
* @return
*/
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
();
if
(
date
!=
null
)
{
cal
.
setTime
(
date
);
...
...
@@ -231,8 +256,8 @@ public class DateUtil {
* @param date
* @return
*/
public
static
Long
getDateFromDateStr
(
String
date
)
{
SimpleDateFormat
format
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
public
static
Long
getDateFromDateStr
(
String
date
,
String
pattern
)
{
SimpleDateFormat
format
=
new
SimpleDateFormat
(
pattern
);
try
{
Date
dateTime
=
format
.
parse
(
date
);
return
dateTime
.
getTime
();
...
...
src/main/java/com/wuban/tron/explore/util/ErrorResponseData.java
View file @
dee5d47e
...
...
@@ -12,11 +12,11 @@ package com.wuban.tron.explore.util;
public
class
ErrorResponseData
extends
ApiResponse
{
public
ErrorResponseData
(
Integer
code
,
String
message
)
{
super
(
false
,
code
,
message
,
null
);
super
(
code
,
message
,
null
);
}
public
ErrorResponseData
(
Integer
code
,
String
message
,
Object
object
)
{
super
(
false
,
code
,
message
,
object
);
super
(
code
,
message
,
object
);
}
}
src/main/java/com/wuban/tron/explore/util/SuccessResponseData.java
View file @
dee5d47e
...
...
@@ -12,14 +12,14 @@ package com.wuban.tron.explore.util;
public
class
SuccessResponseData
<
T
>
extends
ApiResponse
{
public
SuccessResponseData
()
{
super
(
true
,
OK
,
DEFAULT_SUCCESS_MESSAGE
,
null
);
super
(
OK
,
DEFAULT_SUCCESS_MESSAGE
,
null
);
}
public
SuccessResponseData
(
T
object
)
{
super
(
true
,
OK
,
DEFAULT_SUCCESS_MESSAGE
,
object
);
super
(
OK
,
DEFAULT_SUCCESS_MESSAGE
,
object
);
}
public
SuccessResponseData
(
String
message
,
Object
object
)
{
super
(
true
,
OK
,
message
,
object
);
super
(
OK
,
message
,
object
);
}
}
src/main/resources/application-dev.yml
0 → 100644
View file @
dee5d47e
# 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
src/main/resources/application-test.yml
0 → 100644
View file @
dee5d47e
# 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
src/main/resources/application.yml
View file @
dee5d47e
server
:
port
:
8080
# config
spring
:
datasource
:
type
:
com.alibaba.druid.pool.DruidDataSource
driverClassName
:
com.mysql.cj.jdbc.Driver
url
:
jdbc:mysql://coupon-d.mysql.db.wuban.net.cn:30101/tron-explore?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
username
:
root
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
profiles
:
active
:
-
dev
application
:
name
:
tron-explore
mybatis
:
mapper-locations
:
classpath:*.xml
type-aliases-package
:
com.wuban.tron.explore.entity
logging
:
level
:
com.wuban.tron.explore.dao
:
error
\ No newline at end of file
com.wuban.tron.explore.dao
:
debug
\ No newline at end of file
src/main/resources/mapper/BlockHeaderMapper.xml
View file @
dee5d47e
...
...
@@ -266,4 +266,16 @@
from
<include
refid=
"Table_Name"
/>
</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>
src/main/resources/mapper/TransactionMapper.xml
View file @
dee5d47e
...
...
@@ -305,4 +305,12 @@
where (`timestamp`
>
#{t}) and (owner_address = #{address} or to_address = #{address})
order by `timestamp` desc
</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>
src/test/java/com/wuban/tron/explore/dao/BlockHeaderRepositoryTest.java
View file @
dee5d47e
...
...
@@ -53,7 +53,7 @@ class BlockHeaderRepositoryTest {
void
testDateDely
()
{
Date
nextDate
=
DateUtil
.
addDays
(
new
Date
(),
1
);
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
+
"--------------------"
);
}
...
...
src/test/java/com/wuban/tron/explore/dao/TransactionRepositoryTest.java
View file @
dee5d47e
...
...
@@ -5,8 +5,6 @@ import com.wuban.tron.explore.entity.Transaction;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.tron.common.utils.ByteArray
;
import
org.tron.walletserver.WalletApi
;
import
java.util.List
;
...
...
@@ -32,9 +30,9 @@ class TransactionRepositoryTest extends BaseTest {
@Test
void
test
()
{
String
hexString
=
"416c4858d8d3435d278a34146d49dd7e126879ba0d"
;
/*
String hexString = "416c4858d8d3435d278a34146d49dd7e126879ba0d";
String base58check = WalletApi.encode58Check(ByteArray.fromHexString(hexString));
System
.
out
.
println
(
base58check
);
System.out.println(base58check);
*/
}
}
\ No newline at end of file
tron-explore.sql
View file @
dee5d47e
...
...
@@ -129,7 +129,7 @@ CREATE TABLE `tron_transaction` (
DROP
TABLE
IF
EXISTS
`tron_transaction_hex`
;
CREATE
TABLE
`tron_transaction_hex`
(
`id`
bigint
(
20
)
NOT
NULL
AUTO_INCREMENT
,
`hex`
text
COLLATE
utf8mb4_unicode_ci
,
`hex`
long
text
COLLATE
utf8mb4_unicode_ci
,
`block_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
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment