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
6de5665d
Commit
6de5665d
authored
Nov 30, 2020
by
jianhua.zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
合约校验接口功能开发
parent
367fbe7b
Changes
27
Hide whitespace changes
Inline
Side-by-side
Showing
27 changed files
with
1630 additions
and
18 deletions
+1630
-18
ContractController.java
...com/wuban/tron/explore/controller/ContractController.java
+79
-0
TransactionController.java
.../wuban/tron/explore/controller/TransactionController.java
+1
-0
ContractRepository.java
...n/java/com/wuban/tron/explore/dao/ContractRepository.java
+33
-0
Keys.java
src/main/java/com/wuban/tron/explore/domain/Keys.java
+6
-0
TransactionsRawData.java
...va/com/wuban/tron/explore/domain/TransactionsRawData.java
+1
-1
TronContract.java
...main/java/com/wuban/tron/explore/domain/TronContract.java
+1
-1
TronTransEvent.java
...in/java/com/wuban/tron/explore/domain/TronTransEvent.java
+25
-0
TronTransEventResult.java
...a/com/wuban/tron/explore/domain/TronTransEventResult.java
+43
-0
TronTransEventResultType.java
...m/wuban/tron/explore/domain/TronTransEventResultType.java
+19
-0
Contract.java
src/main/java/com/wuban/tron/explore/entity/Contract.java
+67
-0
ContractExample.java
...om/wuban/tron/explore/entity/example/ContractExample.java
+696
-0
ContractRequest.java
...com/wuban/tron/explore/param/request/ContractRequest.java
+29
-0
AccountInfoModel.java
...m/wuban/tron/explore/param/response/AccountInfoModel.java
+6
-0
BaseCommonService.java
...ava/com/wuban/tron/explore/service/BaseCommonService.java
+41
-4
ContractComplierService.java
...m/wuban/tron/explore/service/ContractComplierService.java
+21
-0
ContractService.java
.../java/com/wuban/tron/explore/service/ContractService.java
+31
-0
TronService.java
...main/java/com/wuban/tron/explore/service/TronService.java
+20
-3
ContractComplierServiceImpl.java
...ron/explore/service/impl/ContractComplierServiceImpl.java
+39
-0
ContractServiceImpl.java
.../wuban/tron/explore/service/impl/ContractServiceImpl.java
+46
-0
TransactionServiceImpl.java
...ban/tron/explore/service/impl/TransactionServiceImpl.java
+1
-1
TronServiceImpl.java
.../com/wuban/tron/explore/service/impl/TronServiceImpl.java
+66
-5
BizExceptionEnum.java
...in/java/com/wuban/tron/explore/util/BizExceptionEnum.java
+46
-0
application-dev.yml
src/main/resources/application-dev.yml
+4
-0
application-test.yml
src/main/resources/application-test.yml
+4
-0
ContractMapper.xml
src/main/resources/mapper/ContractMapper.xml
+239
-0
ContractComplierServiceImplTest.java
...explore/service/impl/ContractComplierServiceImplTest.java
+49
-0
TronServiceImplTest.java
.../wuban/tron/explore/service/impl/TronServiceImplTest.java
+17
-3
No files found.
src/main/java/com/wuban/tron/explore/controller/ContractController.java
0 → 100644
View file @
6de5665d
package
com
.
wuban
.
tron
.
explore
.
controller
;
import
com.wuban.tron.explore.entity.Contract
;
import
com.wuban.tron.explore.entity.example.ContractExample
;
import
com.wuban.tron.explore.param.request.ContractRequest
;
import
com.wuban.tron.explore.service.ContractComplierService
;
import
com.wuban.tron.explore.service.ContractService
;
import
com.wuban.tron.explore.service.TronService
;
import
com.wuban.tron.explore.util.ApiResponse
;
import
com.wuban.tron.explore.util.BizExceptionEnum
;
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.StringUtils
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.validation.Valid
;
/**
* <core>合约校验API接口</core>
*
* @author sky
* @date 2020/11/30
*/
@Slf4j
@RestController
@RequestMapping
(
"/api/explorer/v1/"
)
@RequiredArgsConstructor
(
onConstructor_
=
@Autowired
)
public
class
ContractController
{
private
final
ContractService
contractService
;
private
final
TronService
tronService
;
private
final
ContractComplierService
contractComplierService
;
@RequestMapping
(
value
=
"compileSolidity"
,
method
=
RequestMethod
.
POST
)
public
ApiResponse
checkContract
(
@RequestBody
@Valid
ContractRequest
reqParam
)
{
String
address
=
reqParam
.
getAddress
();
if
(
StringUtils
.
isEmpty
(
address
))
{
return
ResponseKit
.
fail
(
BizExceptionEnum
.
REQUEST_NULL
.
getCode
(),
BizExceptionEnum
.
REQUEST_NULL
.
getMessage
());
}
/*
按照合约地址查询DB中是否存在此合约,如果不存在,调用链上接口API
*/
ContractExample
example
=
new
ContractExample
();
example
.
createCriteria
().
andContractAddressEqualTo
(
address
);
Contract
con
=
this
.
contractService
.
selectOneByExample
(
example
);
if
(
con
!=
null
)
{
return
ResponseKit
.
success
(
con
);
}
// 调用链上接口API
Contract
contract
=
this
.
tronService
.
getContract
(
address
);
if
(
contract
==
null
)
{
return
ResponseKit
.
fail
(
BizExceptionEnum
.
SERVER_ERROR
.
getCode
(),
BizExceptionEnum
.
SERVER_ERROR
.
getMessage
());
}
// 编译合约
String
code
=
this
.
contractComplierService
.
complier
(
reqParam
.
getName
(),
reqParam
.
getValue
(),
reqParam
.
getCompiler
());
// 校验btyecode是否一致,不一致返回,一致持久化
if
(!
contract
.
getBytecode
().
equals
(
code
))
{
return
ResponseKit
.
fail
(
BizExceptionEnum
.
SERVER_ERROR
.
getCode
(),
BizExceptionEnum
.
SERVER_ERROR
.
getMessage
());
}
this
.
contractService
.
insert
(
contract
);
return
ResponseKit
.
success
();
}
}
src/main/java/com/wuban/tron/explore/controller/TransactionController.java
View file @
6de5665d
...
...
@@ -45,6 +45,7 @@ import java.util.List;
@RestController
@RequestMapping
(
"/api/tron"
)
@RequiredArgsConstructor
(
onConstructor_
=
@Autowired
)
@Deprecated
public
class
TransactionController
{
private
final
TransactionService
transactionService
;
...
...
src/main/java/com/wuban/tron/explore/dao/ContractRepository.java
0 → 100644
View file @
6de5665d
package
com
.
wuban
.
tron
.
explore
.
dao
;
import
com.wuban.tron.explore.entity.Contract
;
import
com.wuban.tron.explore.entity.example.ContractExample
;
import
org.apache.ibatis.annotations.Param
;
import
org.springframework.stereotype.Repository
;
/**
* <core>合约DAO</core>
*
* @author sky
* @date 2020/11/30
*/
@Repository
public
interface
ContractRepository
{
/**
* 添加合约信息
*
* @param record
* @return
*/
int
insert
(
@Param
(
"record"
)
Contract
record
);
/**
* 查询合约信息
*
* @param example 检索条件
* @return
*/
Contract
selectOneByExample
(
@Param
(
"example"
)
ContractExample
example
);
}
src/main/java/com/wuban/tron/explore/domain/Keys.java
View file @
6de5665d
...
...
@@ -2,6 +2,12 @@ package com.wuban.tron.explore.domain;
import
lombok.Data
;
/**
* <core>权限MODEL</core>
*
* @author sky
* @date 2020/11/02
*/
@Data
public
class
Keys
{
private
String
address
;
...
...
src/main/java/com/wuban/tron/explore/domain/TransactionsRawData.java
View file @
6de5665d
...
...
@@ -13,7 +13,7 @@ import java.util.List;
@Data
public
class
TransactionsRawData
{
private
List
<
Contract
>
contract
;
private
List
<
Tron
Contract
>
contract
;
private
String
ref_block_bytes
;
private
String
ref_block_hash
;
private
Long
expiration
;
...
...
src/main/java/com/wuban/tron/explore/domain/Contract.java
→
src/main/java/com/wuban/tron/explore/domain/
Tron
Contract.java
View file @
6de5665d
...
...
@@ -9,7 +9,7 @@ import lombok.Data;
* @date 2020/11/02
*/
@Data
public
class
Contract
{
public
class
Tron
Contract
{
private
ContractParameter
parameter
;
private
String
type
;
...
...
src/main/java/com/wuban/tron/explore/domain/TronTransEvent.java
0 → 100644
View file @
6de5665d
package
com
.
wuban
.
tron
.
explore
.
domain
;
import
lombok.Data
;
/**
* <core>合约事件</core>
*
* @author sky
* @date 2020/11/30
*/
@Data
public
class
TronTransEvent
{
private
String
caller_contract_address
;
private
TronTransEventResult
result
;
private
String
transaction_id
;
private
TronTransEventResultType
result_type
;
private
long
block_timestamp
;
private
int
block_number
;
private
String
event_name
;
private
String
contract_address
;
private
int
event_index
;
}
src/main/java/com/wuban/tron/explore/domain/TronTransEventResult.java
0 → 100644
View file @
6de5665d
package
com
.
wuban
.
tron
.
explore
.
domain
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
lombok.Data
;
/**
* <core>合约事件结果</core>
*
* @author sky
* @date 2020/11/30
*/
@Data
public
class
TronTransEventResult
{
@JsonProperty
(
value
=
"0"
)
private
String
_
$
0
;
@JsonProperty
(
value
=
"1"
)
private
String
_
$
1
;
@JsonProperty
(
value
=
"2"
)
private
String
_
$
2
;
@JsonProperty
(
value
=
"3"
)
private
String
_
$
3
;
@JsonProperty
(
value
=
"4"
)
private
String
_
$
4
;
@JsonProperty
(
value
=
"5"
)
private
String
_
$
5
;
@JsonProperty
(
value
=
"6"
)
private
String
_
$
6
;
@JsonProperty
(
value
=
"7"
)
private
String
_
$
7
;
@JsonProperty
(
value
=
"8"
)
private
String
_
$
8
;
@JsonProperty
(
value
=
"9"
)
private
String
_
$
9
;
@JsonProperty
(
value
=
"10"
)
private
String
_
$
10
;
private
String
callContractAddr
;
private
String
amount
;
private
String
marketIdx
;
private
String
userAddr
;
}
src/main/java/com/wuban/tron/explore/domain/TronTransEventResultType.java
0 → 100644
View file @
6de5665d
package
com
.
wuban
.
tron
.
explore
.
domain
;
import
lombok.Data
;
/**
* <core>合约事件结果类型</core>
*
* @author sky
* @date 2020/11/30
*/
@Data
public
class
TronTransEventResultType
{
private
String
callContractAddr
;
private
String
amount
;
private
String
marketIdx
;
private
String
userAddr
;
}
src/main/java/com/wuban/tron/explore/entity/Contract.java
0 → 100644
View file @
6de5665d
package
com
.
wuban
.
tron
.
explore
.
entity
;
import
lombok.AccessLevel
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.io.Serializable
;
import
java.util.Date
;
/**
* 合约表
* @author sky
* @date 2020-11-30
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
(
access
=
AccessLevel
.
PRIVATE
)
public
class
Contract
{
/**
*
*/
private
Long
id
;
/**
*
*/
private
String
bytecode
;
/**
* 名称
*/
private
String
name
;
/**
*
*/
private
String
originAddress
;
/**
*
*/
private
String
abi
;
/**
*
*/
private
Long
originEnergyLimit
;
/**
* 合约地址
*/
private
String
contractAddress
;
/**
*
*/
private
String
codeHash
;
public
static
Contract
getInstance
()
{
return
Contract
.
builder
()
.
id
(
0L
)
.
bytecode
(
""
)
.
name
(
""
)
.
originAddress
(
""
)
.
abi
(
""
)
.
originEnergyLimit
(
0L
)
.
contractAddress
(
""
)
.
codeHash
(
""
)
.
build
();
}
}
\ No newline at end of file
src/main/java/com/wuban/tron/explore/entity/example/ContractExample.java
0 → 100644
View file @
6de5665d
package
com
.
wuban
.
tron
.
explore
.
entity
.
example
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
/**
* 合约表 查询条件example类
* @author sky
* @date 2020-11-30
*/
public
class
ContractExample
{
protected
String
orderByClause
;
protected
boolean
distinct
;
protected
List
<
Criteria
>
oredCriteria
;
public
ContractExample
()
{
oredCriteria
=
new
ArrayList
<>();
}
public
void
setOrderByClause
(
String
orderByClause
)
{
this
.
orderByClause
=
orderByClause
;
}
public
String
getOrderByClause
()
{
return
orderByClause
;
}
public
void
setDistinct
(
boolean
distinct
)
{
this
.
distinct
=
distinct
;
}
public
boolean
isDistinct
()
{
return
distinct
;
}
public
List
<
Criteria
>
getOredCriteria
()
{
return
oredCriteria
;
}
public
void
or
(
Criteria
criteria
)
{
oredCriteria
.
add
(
criteria
);
}
public
Criteria
or
()
{
Criteria
criteria
=
createCriteriaInternal
();
oredCriteria
.
add
(
criteria
);
return
criteria
;
}
public
Criteria
createCriteria
()
{
Criteria
criteria
=
createCriteriaInternal
();
if
(
oredCriteria
.
size
()
==
0
)
{
oredCriteria
.
add
(
criteria
);
}
return
criteria
;
}
protected
Criteria
createCriteriaInternal
()
{
Criteria
criteria
=
new
Criteria
();
return
criteria
;
}
public
void
clear
()
{
oredCriteria
.
clear
();
orderByClause
=
null
;
distinct
=
false
;
}
protected
abstract
static
class
GeneratedCriteria
{
protected
List
<
Criterion
>
criteria
;
protected
GeneratedCriteria
()
{
super
();
criteria
=
new
ArrayList
<
Criterion
>();
}
public
boolean
isValid
()
{
return
criteria
.
size
()
>
0
;
}
public
List
<
Criterion
>
getAllCriteria
()
{
return
criteria
;
}
public
List
<
Criterion
>
getCriteria
()
{
return
criteria
;
}
protected
void
addCriterion
(
String
condition
)
{
if
(
condition
==
null
)
{
throw
new
RuntimeException
(
"Value for condition cannot be null"
);
}
criteria
.
add
(
new
Criterion
(
condition
));
}
protected
void
addCriterion
(
String
condition
,
Object
value
,
String
property
)
{
if
(
value
==
null
)
{
throw
new
RuntimeException
(
"Value for "
+
property
+
" cannot be null"
);
}
criteria
.
add
(
new
Criterion
(
condition
,
value
));
}
protected
void
addCriterion
(
String
condition
,
Object
value1
,
Object
value2
,
String
property
)
{
if
(
value1
==
null
||
value2
==
null
)
{
throw
new
RuntimeException
(
"Between values for "
+
property
+
" cannot be null"
);
}
criteria
.
add
(
new
Criterion
(
condition
,
value1
,
value2
));
}
public
Criteria
andIdIsNull
()
{
addCriterion
(
"id is null"
);
return
(
Criteria
)
this
;
}
public
Criteria
andIdIsNotNull
()
{
addCriterion
(
"id is not null"
);
return
(
Criteria
)
this
;
}
public
Criteria
andIdEqualTo
(
Long
value
)
{
addCriterion
(
"id ="
,
value
,
"id"
);
return
(
Criteria
)
this
;
}
public
Criteria
andIdNotEqualTo
(
Long
value
)
{
addCriterion
(
"id <>"
,
value
,
"id"
);
return
(
Criteria
)
this
;
}
public
Criteria
andIdIn
(
List
<
Long
>
values
)
{
addCriterion
(
"id in"
,
values
,
"id"
);
return
(
Criteria
)
this
;
}
public
Criteria
andIdNotIn
(
List
<
Long
>
values
)
{
addCriterion
(
"id not in"
,
values
,
"id"
);
return
(
Criteria
)
this
;
}
public
Criteria
andIdBetween
(
Long
value1
,
Long
value2
)
{
addCriterion
(
"id between"
,
value1
,
value2
,
"id"
);
return
(
Criteria
)
this
;
}
public
Criteria
andIdNotBetween
(
Long
value1
,
Long
value2
)
{
addCriterion
(
"id not between"
,
value1
,
value2
,
"id"
);
return
(
Criteria
)
this
;
}
public
Criteria
andIdGreaterThan
(
Long
value
)
{
addCriterion
(
"id >"
,
value
,
"id"
);
return
(
Criteria
)
this
;
}
public
Criteria
andIdGreaterThanOrEqualTo
(
Long
value
)
{
addCriterion
(
"id >="
,
value
,
"id"
);
return
(
Criteria
)
this
;
}
public
Criteria
andIdLessThan
(
Long
value
)
{
addCriterion
(
"id <"
,
value
,
"id"
);
return
(
Criteria
)
this
;
}
public
Criteria
andIdLessThanOrEqualTo
(
Long
value
)
{
addCriterion
(
"id <="
,
value
,
"id"
);
return
(
Criteria
)
this
;
}
public
Criteria
andBytecodeIsNull
()
{
addCriterion
(
"bytecode is null"
);
return
(
Criteria
)
this
;
}
public
Criteria
andBytecodeIsNotNull
()
{
addCriterion
(
"bytecode is not null"
);
return
(
Criteria
)
this
;
}
public
Criteria
andBytecodeEqualTo
(
String
value
)
{
addCriterion
(
"bytecode ="
,
value
,
"bytecode"
);
return
(
Criteria
)
this
;
}
public
Criteria
andBytecodeNotEqualTo
(
String
value
)
{
addCriterion
(
"bytecode <>"
,
value
,
"bytecode"
);
return
(
Criteria
)
this
;
}
public
Criteria
andBytecodeIn
(
List
<
String
>
values
)
{
addCriterion
(
"bytecode in"
,
values
,
"bytecode"
);
return
(
Criteria
)
this
;
}
public
Criteria
andBytecodeNotIn
(
List
<
String
>
values
)
{
addCriterion
(
"bytecode not in"
,
values
,
"bytecode"
);
return
(
Criteria
)
this
;
}
public
Criteria
andBytecodeBetween
(
String
value1
,
String
value2
)
{
addCriterion
(
"bytecode between"
,
value1
,
value2
,
"bytecode"
);
return
(
Criteria
)
this
;
}
public
Criteria
andBytecodeNotBetween
(
String
value1
,
String
value2
)
{
addCriterion
(
"bytecode not between"
,
value1
,
value2
,
"bytecode"
);
return
(
Criteria
)
this
;
}
public
Criteria
andBytecodeLike
(
String
value
)
{
addCriterion
(
"bytecode like"
,
value
,
"bytecode"
);
return
(
Criteria
)
this
;
}
public
Criteria
andBytecodeNotLike
(
String
value
)
{
addCriterion
(
"bytecode not like"
,
value
,
"bytecode"
);
return
(
Criteria
)
this
;
}
public
Criteria
andNameIsNull
()
{
addCriterion
(
"name is null"
);
return
(
Criteria
)
this
;
}
public
Criteria
andNameIsNotNull
()
{
addCriterion
(
"name is not null"
);
return
(
Criteria
)
this
;
}
public
Criteria
andNameEqualTo
(
String
value
)
{
addCriterion
(
"name ="
,
value
,
"name"
);
return
(
Criteria
)
this
;
}
public
Criteria
andNameNotEqualTo
(
String
value
)
{
addCriterion
(
"name <>"
,
value
,
"name"
);
return
(
Criteria
)
this
;
}
public
Criteria
andNameIn
(
List
<
String
>
values
)
{
addCriterion
(
"name in"
,
values
,
"name"
);
return
(
Criteria
)
this
;
}
public
Criteria
andNameNotIn
(
List
<
String
>
values
)
{
addCriterion
(
"name not in"
,
values
,
"name"
);
return
(
Criteria
)
this
;
}
public
Criteria
andNameBetween
(
String
value1
,
String
value2
)
{
addCriterion
(
"name between"
,
value1
,
value2
,
"name"
);
return
(
Criteria
)
this
;
}
public
Criteria
andNameNotBetween
(
String
value1
,
String
value2
)
{
addCriterion
(
"name not between"
,
value1
,
value2
,
"name"
);
return
(
Criteria
)
this
;
}
public
Criteria
andNameLike
(
String
value
)
{
addCriterion
(
"name like"
,
value
,
"name"
);
return
(
Criteria
)
this
;
}
public
Criteria
andNameNotLike
(
String
value
)
{
addCriterion
(
"name not like"
,
value
,
"name"
);
return
(
Criteria
)
this
;
}
public
Criteria
andOriginAddressIsNull
()
{
addCriterion
(
"origin_address is null"
);
return
(
Criteria
)
this
;
}
public
Criteria
andOriginAddressIsNotNull
()
{
addCriterion
(
"origin_address is not null"
);
return
(
Criteria
)
this
;
}
public
Criteria
andOriginAddressEqualTo
(
String
value
)
{
addCriterion
(
"origin_address ="
,
value
,
"originAddress"
);
return
(
Criteria
)
this
;
}
public
Criteria
andOriginAddressNotEqualTo
(
String
value
)
{
addCriterion
(
"origin_address <>"
,
value
,
"originAddress"
);
return
(
Criteria
)
this
;
}
public
Criteria
andOriginAddressIn
(
List
<
String
>
values
)
{
addCriterion
(
"origin_address in"
,
values
,
"originAddress"
);
return
(
Criteria
)
this
;
}
public
Criteria
andOriginAddressNotIn
(
List
<
String
>
values
)
{
addCriterion
(
"origin_address not in"
,
values
,
"originAddress"
);
return
(
Criteria
)
this
;
}
public
Criteria
andOriginAddressBetween
(
String
value1
,
String
value2
)
{
addCriterion
(
"origin_address between"
,
value1
,
value2
,
"originAddress"
);
return
(
Criteria
)
this
;
}
public
Criteria
andOriginAddressNotBetween
(
String
value1
,
String
value2
)
{
addCriterion
(
"origin_address not between"
,
value1
,
value2
,
"originAddress"
);
return
(
Criteria
)
this
;
}
public
Criteria
andOriginAddressLike
(
String
value
)
{
addCriterion
(
"origin_address like"
,
value
,
"originAddress"
);
return
(
Criteria
)
this
;
}
public
Criteria
andOriginAddressNotLike
(
String
value
)
{
addCriterion
(
"origin_address not like"
,
value
,
"originAddress"
);
return
(
Criteria
)
this
;
}
public
Criteria
andAbiIsNull
()
{
addCriterion
(
"abi is null"
);
return
(
Criteria
)
this
;
}
public
Criteria
andAbiIsNotNull
()
{
addCriterion
(
"abi is not null"
);
return
(
Criteria
)
this
;
}
public
Criteria
andAbiEqualTo
(
String
value
)
{
addCriterion
(
"abi ="
,
value
,
"abi"
);
return
(
Criteria
)
this
;
}
public
Criteria
andAbiNotEqualTo
(
String
value
)
{
addCriterion
(
"abi <>"
,
value
,
"abi"
);
return
(
Criteria
)
this
;
}
public
Criteria
andAbiIn
(
List
<
String
>
values
)
{
addCriterion
(
"abi in"
,
values
,
"abi"
);
return
(
Criteria
)
this
;
}
public
Criteria
andAbiNotIn
(
List
<
String
>
values
)
{
addCriterion
(
"abi not in"
,
values
,
"abi"
);
return
(
Criteria
)
this
;
}
public
Criteria
andAbiBetween
(
String
value1
,
String
value2
)
{
addCriterion
(
"abi between"
,
value1
,
value2
,
"abi"
);
return
(
Criteria
)
this
;
}
public
Criteria
andAbiNotBetween
(
String
value1
,
String
value2
)
{
addCriterion
(
"abi not between"
,
value1
,
value2
,
"abi"
);
return
(
Criteria
)
this
;
}
public
Criteria
andAbiLike
(
String
value
)
{
addCriterion
(
"abi like"
,
value
,
"abi"
);
return
(
Criteria
)
this
;
}
public
Criteria
andAbiNotLike
(
String
value
)
{
addCriterion
(
"abi not like"
,
value
,
"abi"
);
return
(
Criteria
)
this
;
}
public
Criteria
andOriginEnergyLimitIsNull
()
{
addCriterion
(
"origin_energy_limit is null"
);
return
(
Criteria
)
this
;
}
public
Criteria
andOriginEnergyLimitIsNotNull
()
{
addCriterion
(
"origin_energy_limit is not null"
);
return
(
Criteria
)
this
;
}
public
Criteria
andOriginEnergyLimitEqualTo
(
Long
value
)
{
addCriterion
(
"origin_energy_limit ="
,
value
,
"originEnergyLimit"
);
return
(
Criteria
)
this
;
}
public
Criteria
andOriginEnergyLimitNotEqualTo
(
Long
value
)
{
addCriterion
(
"origin_energy_limit <>"
,
value
,
"originEnergyLimit"
);
return
(
Criteria
)
this
;
}
public
Criteria
andOriginEnergyLimitIn
(
List
<
Long
>
values
)
{
addCriterion
(
"origin_energy_limit in"
,
values
,
"originEnergyLimit"
);
return
(
Criteria
)
this
;
}
public
Criteria
andOriginEnergyLimitNotIn
(
List
<
Long
>
values
)
{
addCriterion
(
"origin_energy_limit not in"
,
values
,
"originEnergyLimit"
);
return
(
Criteria
)
this
;
}
public
Criteria
andOriginEnergyLimitBetween
(
Long
value1
,
Long
value2
)
{
addCriterion
(
"origin_energy_limit between"
,
value1
,
value2
,
"originEnergyLimit"
);
return
(
Criteria
)
this
;
}
public
Criteria
andOriginEnergyLimitNotBetween
(
Long
value1
,
Long
value2
)
{
addCriterion
(
"origin_energy_limit not between"
,
value1
,
value2
,
"originEnergyLimit"
);
return
(
Criteria
)
this
;
}
public
Criteria
andOriginEnergyLimitGreaterThan
(
Long
value
)
{
addCriterion
(
"origin_energy_limit >"
,
value
,
"originEnergyLimit"
);
return
(
Criteria
)
this
;
}
public
Criteria
andOriginEnergyLimitGreaterThanOrEqualTo
(
Long
value
)
{
addCriterion
(
"origin_energy_limit >="
,
value
,
"originEnergyLimit"
);
return
(
Criteria
)
this
;
}
public
Criteria
andOriginEnergyLimitLessThan
(
Long
value
)
{
addCriterion
(
"origin_energy_limit <"
,
value
,
"originEnergyLimit"
);
return
(
Criteria
)
this
;
}
public
Criteria
andOriginEnergyLimitLessThanOrEqualTo
(
Long
value
)
{
addCriterion
(
"origin_energy_limit <="
,
value
,
"originEnergyLimit"
);
return
(
Criteria
)
this
;
}
public
Criteria
andContractAddressIsNull
()
{
addCriterion
(
"contract_address is null"
);
return
(
Criteria
)
this
;
}
public
Criteria
andContractAddressIsNotNull
()
{
addCriterion
(
"contract_address is not null"
);
return
(
Criteria
)
this
;
}
public
Criteria
andContractAddressEqualTo
(
String
value
)
{
addCriterion
(
"contract_address ="
,
value
,
"contractAddress"
);
return
(
Criteria
)
this
;
}
public
Criteria
andContractAddressNotEqualTo
(
String
value
)
{
addCriterion
(
"contract_address <>"
,
value
,
"contractAddress"
);
return
(
Criteria
)
this
;
}
public
Criteria
andContractAddressIn
(
List
<
String
>
values
)
{
addCriterion
(
"contract_address in"
,
values
,
"contractAddress"
);
return
(
Criteria
)
this
;
}
public
Criteria
andContractAddressNotIn
(
List
<
String
>
values
)
{
addCriterion
(
"contract_address not in"
,
values
,
"contractAddress"
);
return
(
Criteria
)
this
;
}
public
Criteria
andContractAddressBetween
(
String
value1
,
String
value2
)
{
addCriterion
(
"contract_address between"
,
value1
,
value2
,
"contractAddress"
);
return
(
Criteria
)
this
;
}
public
Criteria
andContractAddressNotBetween
(
String
value1
,
String
value2
)
{
addCriterion
(
"contract_address not between"
,
value1
,
value2
,
"contractAddress"
);
return
(
Criteria
)
this
;
}
public
Criteria
andContractAddressLike
(
String
value
)
{
addCriterion
(
"contract_address like"
,
value
,
"contractAddress"
);
return
(
Criteria
)
this
;
}
public
Criteria
andContractAddressNotLike
(
String
value
)
{
addCriterion
(
"contract_address not like"
,
value
,
"contractAddress"
);
return
(
Criteria
)
this
;
}
public
Criteria
andCodeHashIsNull
()
{
addCriterion
(
"code_hash is null"
);
return
(
Criteria
)
this
;
}
public
Criteria
andCodeHashIsNotNull
()
{
addCriterion
(
"code_hash is not null"
);
return
(
Criteria
)
this
;
}
public
Criteria
andCodeHashEqualTo
(
String
value
)
{
addCriterion
(
"code_hash ="
,
value
,
"codeHash"
);
return
(
Criteria
)
this
;
}
public
Criteria
andCodeHashNotEqualTo
(
String
value
)
{
addCriterion
(
"code_hash <>"
,
value
,
"codeHash"
);
return
(
Criteria
)
this
;
}
public
Criteria
andCodeHashIn
(
List
<
String
>
values
)
{
addCriterion
(
"code_hash in"
,
values
,
"codeHash"
);
return
(
Criteria
)
this
;
}
public
Criteria
andCodeHashNotIn
(
List
<
String
>
values
)
{
addCriterion
(
"code_hash not in"
,
values
,
"codeHash"
);
return
(
Criteria
)
this
;
}
public
Criteria
andCodeHashBetween
(
String
value1
,
String
value2
)
{
addCriterion
(
"code_hash between"
,
value1
,
value2
,
"codeHash"
);
return
(
Criteria
)
this
;
}
public
Criteria
andCodeHashNotBetween
(
String
value1
,
String
value2
)
{
addCriterion
(
"code_hash not between"
,
value1
,
value2
,
"codeHash"
);
return
(
Criteria
)
this
;
}
public
Criteria
andCodeHashLike
(
String
value
)
{
addCriterion
(
"code_hash like"
,
value
,
"codeHash"
);
return
(
Criteria
)
this
;
}
public
Criteria
andCodeHashNotLike
(
String
value
)
{
addCriterion
(
"code_hash not like"
,
value
,
"codeHash"
);
return
(
Criteria
)
this
;
}
public
Criteria
andFieldIsNull
(
final
String
fieldName
)
{
addCriterion
(
fieldName
+
" is null"
);
return
(
Criteria
)
this
;
}
public
Criteria
andFieldIsNotNull
(
final
String
fieldName
)
{
addCriterion
(
fieldName
+
" is not null"
);
return
(
Criteria
)
this
;
}
public
Criteria
andFieldEqualTo
(
final
String
fieldName
,
final
Object
fieldValue
)
{
addCriterion
(
fieldName
+
" = "
,
fieldValue
,
fieldName
);
return
(
Criteria
)
this
;
}
public
Criteria
andFieldNotEqualTo
(
final
String
fieldName
,
final
Object
fieldValue
)
{
addCriterion
(
fieldName
+
" <> "
,
fieldValue
,
fieldName
);
return
(
Criteria
)
this
;
}
public
Criteria
andFieldIn
(
final
String
fieldName
,
final
List
<
Object
>
values
)
{
addCriterion
(
fieldName
+
" in "
,
values
,
fieldName
);
return
(
Criteria
)
this
;
}
public
Criteria
andFieldNotIn
(
final
String
fieldName
,
final
List
<
Object
>
values
)
{
addCriterion
(
fieldName
+
" not in "
,
values
,
fieldName
);
return
(
Criteria
)
this
;
}
public
Criteria
andFieldBetween
(
final
String
fieldName
,
final
Object
fieldValue1
,
final
Object
fieldValue2
)
{
addCriterion
(
fieldName
+
" between "
,
fieldValue1
,
fieldValue2
,
fieldName
);
return
(
Criteria
)
this
;
}
public
Criteria
andFieldNotBetween
(
final
String
fieldName
,
final
Object
fieldValue1
,
final
Object
fieldValue2
)
{
addCriterion
(
fieldName
+
" not between "
,
fieldValue1
,
fieldValue2
,
fieldName
);
return
(
Criteria
)
this
;
}
public
Criteria
andFieldGreaterThan
(
final
String
fieldName
,
final
Object
fieldValue
)
{
addCriterion
(
fieldName
+
" > "
,
fieldValue
,
fieldName
);
return
(
Criteria
)
this
;
}
public
Criteria
andFieldGreaterThanOrEqualTo
(
final
String
fieldName
,
final
Object
fieldValue
)
{
addCriterion
(
fieldName
+
" >= "
,
fieldValue
,
fieldName
);
return
(
Criteria
)
this
;
}
public
Criteria
andFieldLessThan
(
final
String
fieldName
,
final
Object
fieldValue
)
{
addCriterion
(
fieldName
+
" < "
,
fieldValue
,
fieldName
);
return
(
Criteria
)
this
;
}
public
Criteria
andFieldLessThanOrEqualTo
(
final
String
fieldName
,
final
Object
fieldValue
)
{
addCriterion
(
fieldName
+
" <= "
,
fieldValue
,
fieldName
);
return
(
Criteria
)
this
;
}
public
Criteria
andFieldLike
(
final
String
fieldName
,
final
String
fieldValue
)
{
addCriterion
(
fieldName
+
" like "
,
fieldValue
,
fieldName
);
return
(
Criteria
)
this
;
}
public
Criteria
andFieldNotLike
(
final
String
fieldName
,
final
String
fieldValue
)
{
addCriterion
(
fieldName
+
" not like "
,
fieldValue
,
fieldName
);
return
(
Criteria
)
this
;
}
}
public
static
class
Criteria
extends
GeneratedCriteria
{
protected
Criteria
()
{
super
();
}
}
public
static
class
Criterion
{
private
String
condition
;
private
Object
value
;
private
Object
secondValue
;
private
boolean
noValue
;
private
boolean
singleValue
;
private
boolean
betweenValue
;
private
boolean
listValue
;
private
String
typeHandler
;
public
String
getCondition
()
{
return
condition
;
}
public
Object
getValue
()
{
return
value
;
}
public
Object
getSecondValue
()
{
return
secondValue
;
}
public
boolean
isNoValue
()
{
return
noValue
;
}
public
boolean
isSingleValue
()
{
return
singleValue
;
}
public
boolean
isBetweenValue
()
{
return
betweenValue
;
}
public
boolean
isListValue
()
{
return
listValue
;
}
public
String
getTypeHandler
()
{
return
typeHandler
;
}
protected
Criterion
(
String
condition
)
{
super
();
this
.
condition
=
condition
;
this
.
typeHandler
=
null
;
this
.
noValue
=
true
;
}
protected
Criterion
(
String
condition
,
Object
value
,
String
typeHandler
)
{
super
();
this
.
condition
=
condition
;
this
.
value
=
value
;
this
.
typeHandler
=
typeHandler
;
if
(
value
instanceof
List
<?>)
{
this
.
listValue
=
true
;
}
else
{
this
.
singleValue
=
true
;
}
}
protected
Criterion
(
String
condition
,
Object
value
)
{
this
(
condition
,
value
,
null
);
}
protected
Criterion
(
String
condition
,
Object
value
,
Object
secondValue
,
String
typeHandler
)
{
super
();
this
.
condition
=
condition
;
this
.
value
=
value
;
this
.
secondValue
=
secondValue
;
this
.
typeHandler
=
typeHandler
;
this
.
betweenValue
=
true
;
}
protected
Criterion
(
String
condition
,
Object
value
,
Object
secondValue
)
{
this
(
condition
,
value
,
secondValue
,
null
);
}
}
}
src/main/java/com/wuban/tron/explore/param/request/ContractRequest.java
0 → 100644
View file @
6de5665d
package
com
.
wuban
.
tron
.
explore
.
param
.
request
;
import
lombok.Data
;
/**
* <core>合约校验请求参数</core>
*
* @author sky
* @date 2020/11/02
*/
@Data
public
class
ContractRequest
{
private
String
address
;
private
String
name
;
private
String
value
;
private
String
version
;
private
String
compiler
;
private
String
optimization
;
private
String
code
;
private
String
parameters
;
private
String
library
;
private
String
runs
;
private
String
evm_version
;
private
String
license_type
;
}
src/main/java/com/wuban/tron/explore/param/response/AccountInfoModel.java
View file @
6de5665d
...
...
@@ -3,6 +3,12 @@ package com.wuban.tron.explore.param.response;
import
lombok.Builder
;
import
lombok.Data
;
/**
* <core>账户信息MODEL</core>
*
* @author sky
* @date 2020/11/02
*/
@Data
@Builder
public
class
AccountInfoModel
{
...
...
src/main/java/com/wuban/tron/explore/service/BaseCommonService.java
View file @
6de5665d
...
...
@@ -27,21 +27,34 @@ public abstract class BaseCommonService {
protected
static
final
String
GET_BLOCK_BYNUM
=
PREFIX
+
"/getblockbynum"
;
/**
* 查询最新的几个块
* 查询最新的几个块
API
*/
protected
static
final
String
GET_BLOCK_BYLATESTNUM
=
PREFIX
+
"/getblockbylatestnum"
;
/**
* 查询账户信息
* 查询账户信息
API
*/
protected
static
final
String
GET_ACCOUNT
=
PREFIX
+
"/getaccount"
;
protected
static
final
String
FREEZE_BALANCE
=
"/wallet/freezebalance"
;
/**
* 事件日志API
*/
protected
static
final
String
CONTRACT_EVENT
=
"/event/contract/"
;
/**
* 获取合约API
*/
protected
static
final
String
GET_CONTRACT
=
"/wallet/getcontract"
;
@Value
(
"${tron.site}"
)
private
String
tronSite
;
@Value
(
"${contract.complier.site}"
)
String
contractComplierSite
;
/**
* http请求
*
...
...
@@ -76,17 +89,41 @@ public abstract class BaseCommonService {
}
/**
* 构建签名
* 构建请求体
*
* @param paramMap 请求参数
* @return Request
*/
protected
Request
builderPost
(
Map
<
String
,
Object
>
paramMap
)
{
String
param
=
JSON
.
toJSONString
(
paramMap
);
RequestBody
postBody
=
RequestBody
.
create
(
param
,
Constant
.
JSON_TYPE
);
return
new
Request
.
Builder
().
url
(
this
.
contractComplierSite
).
post
(
postBody
)
.
addHeader
(
Constant
.
CONTENT_TYPE_KEY
,
Constant
.
CONTENT_TYPE_VAL
).
build
();
}
/**
* 构建请求体
*
* @param uri 合约方法名称
* @param paramMap 请求参数
* @return Request
*/
protected
Request
builder
(
String
uri
,
Map
<
String
,
Object
>
paramMap
)
{
protected
Request
builder
Post
(
String
uri
,
Map
<
String
,
Object
>
paramMap
)
{
String
param
=
JSON
.
toJSONString
(
paramMap
);
RequestBody
postBody
=
RequestBody
.
create
(
param
,
Constant
.
JSON_TYPE
);
return
new
Request
.
Builder
().
url
(
this
.
tronSite
+
uri
).
post
(
postBody
)
.
addHeader
(
Constant
.
CONTENT_TYPE_KEY
,
Constant
.
CONTENT_TYPE_VAL
).
build
();
}
/**
* 构建请求体
*
* @param uri 合约方法名称
* @return Request
*/
protected
Request
builderGet
(
String
uri
)
{
return
new
Request
.
Builder
().
url
(
this
.
tronSite
+
uri
).
get
()
.
addHeader
(
Constant
.
CONTENT_TYPE_KEY
,
Constant
.
CONTENT_TYPE_VAL
).
build
();
}
}
src/main/java/com/wuban/tron/explore/service/ContractComplierService.java
0 → 100644
View file @
6de5665d
package
com
.
wuban
.
tron
.
explore
.
service
;
/**
* <core>编译合约服务接口</core>
*
* @author sky
* @date 2020/11/30
*/
public
interface
ContractComplierService
{
/**
* 编译合约
*
* @param name 名称
* @param value 合约内容
* @param complier solidity版本号
* @return
*/
String
complier
(
String
name
,
String
value
,
String
complier
);
}
src/main/java/com/wuban/tron/explore/service/ContractService.java
0 → 100644
View file @
6de5665d
package
com
.
wuban
.
tron
.
explore
.
service
;
import
com.wuban.tron.explore.entity.Contract
;
import
com.wuban.tron.explore.entity.example.ContractExample
;
import
org.apache.ibatis.annotations.Param
;
/**
* <core>合约服务接口</core>
*
* @author sky
* @date 2020/11/30
*/
public
interface
ContractService
{
/**
* 添加合约信息
*
* @param record
* @return
*/
int
insert
(
@Param
(
"record"
)
Contract
record
);
/**
* 查询合约信息
*
* @param example 检索条件
* @return
*/
Contract
selectOneByExample
(
@Param
(
"example"
)
ContractExample
example
);
}
src/main/java/com/wuban/tron/explore/service/TronService.java
View file @
6de5665d
package
com
.
wuban
.
tron
.
explore
.
service
;
import
com.wuban.tron.explore.domain.TronAccount
;
import
com.wuban.tron.explore.domain.TronResponseArrayData
;
import
com.wuban.tron.explore.domain.TronResponseData
;
import
com.wuban.tron.explore.domain.*
;
import
com.wuban.tron.explore.entity.Contract
;
import
java.util.List
;
/**
* <core>波场区块服务接口</core>
...
...
@@ -36,4 +37,20 @@ public interface TronService {
*/
TronAccount
getAccount
(
String
address
);
/**
* 根据合约地址获取事件信息
*
* @param address 合约地址
* @return
*/
List
<
TronTransEvent
>
getContractEvent
(
String
address
);
/**
* 根据合约地址获取合约信息
*
* @param address 合约地址
* @return
*/
Contract
getContract
(
String
address
);
}
src/main/java/com/wuban/tron/explore/service/impl/ContractComplierServiceImpl.java
0 → 100644
View file @
6de5665d
package
com
.
wuban
.
tron
.
explore
.
service
.
impl
;
import
com.alibaba.fastjson.JSONObject
;
import
com.wuban.tron.explore.service.BaseCommonService
;
import
com.wuban.tron.explore.service.ContractComplierService
;
import
com.wuban.tron.explore.util.ApiResponse
;
import
okhttp3.Request
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.StringUtils
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* <core>编译合约服务接口实现类</core>
*
* @author sky
* @date 2020/11/30
*/
@Service
public
class
ContractComplierServiceImpl
extends
BaseCommonService
implements
ContractComplierService
{
@Override
public
String
complier
(
String
name
,
String
value
,
String
complier
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>(
3
);
map
.
put
(
"name"
,
name
);
map
.
put
(
"value"
,
value
);
map
.
put
(
"complier"
,
complier
);
Request
request
=
this
.
builderPost
(
map
);
String
str
=
this
.
execute
(
request
);
if
(
StringUtils
.
isEmpty
(
str
))
{
return
null
;
}
return
(
String
)
JSONObject
.
parseObject
(
str
,
ApiResponse
.
class
).
getData
();
}
}
src/main/java/com/wuban/tron/explore/service/impl/ContractServiceImpl.java
0 → 100644
View file @
6de5665d
package
com
.
wuban
.
tron
.
explore
.
service
.
impl
;
import
com.wuban.tron.explore.dao.ContractRepository
;
import
com.wuban.tron.explore.entity.Contract
;
import
com.wuban.tron.explore.entity.example.ContractExample
;
import
com.wuban.tron.explore.service.ContractService
;
import
lombok.RequiredArgsConstructor
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
/**
* <core>合约服务接口实现类</core>
*
* @author sky
* @date 2020/11/30
*/
@Service
@RequiredArgsConstructor
(
onConstructor_
=
@Autowired
)
public
class
ContractServiceImpl
implements
ContractService
{
private
final
ContractRepository
contractRepository
;
/**
* 添加合约信息
*
* @param record
* @return
*/
@Override
public
int
insert
(
Contract
record
)
{
return
this
.
contractRepository
.
insert
(
record
);
}
/**
* 查询合约信息
*
* @param example 检索条件
* @return
*/
@Override
public
Contract
selectOneByExample
(
ContractExample
example
)
{
return
this
.
contractRepository
.
selectOneByExample
(
example
);
}
}
src/main/java/com/wuban/tron/explore/service/impl/TransactionServiceImpl.java
View file @
6de5665d
...
...
@@ -223,7 +223,7 @@ public class TransactionServiceImpl implements TransactionService {
List
<
Transaction
>
retList
=
new
ArrayList
<>(
transactionsList
.
size
());
transactionsList
.
forEach
(
o
->
{
TransactionsRawData
rawData
=
o
.
getRaw_data
();
Contract
contract
=
rawData
.
getContract
().
get
(
0
);
Tron
Contract
contract
=
rawData
.
getContract
().
get
(
0
);
ContractParameter
contractParameter
=
contract
.
getParameter
();
ContractParameterValue
val
=
contractParameter
.
getValue
();
...
...
src/main/java/com/wuban/tron/explore/service/impl/TronServiceImpl.java
View file @
6de5665d
package
com
.
wuban
.
tron
.
explore
.
service
.
impl
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.wuban.tron.explore.constant.Constant
;
import
com.wuban.tron.explore.domain.TronAccount
;
import
com.wuban.tron.explore.domain.TronResponseArrayData
;
import
com.wuban.tron.explore.domain.TronResponseData
;
import
com.wuban.tron.explore.domain.*
;
import
com.wuban.tron.explore.entity.Contract
;
import
com.wuban.tron.explore.service.BaseCommonService
;
import
com.wuban.tron.explore.service.TronService
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -15,6 +15,7 @@ import org.springframework.stereotype.Service;
import
org.springframework.util.StringUtils
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
...
...
@@ -56,7 +57,7 @@ public class TronServiceImpl extends BaseCommonService implements TronService {
Map
<
String
,
Object
>
map
=
new
HashMap
<>(
1
);
map
.
put
(
"num"
,
param
);
Request
request
=
this
.
builder
(
interfaceName
,
map
);
Request
request
=
this
.
builder
Post
(
interfaceName
,
map
);
String
str
=
this
.
execute
(
request
);
return
str
;
}
...
...
@@ -71,7 +72,7 @@ public class TronServiceImpl extends BaseCommonService implements TronService {
Map
<
String
,
Object
>
map
=
new
HashMap
<>(
1
);
map
.
put
(
"address"
,
address
);
Request
request
=
this
.
builder
(
GET_ACCOUNT
,
map
);
Request
request
=
this
.
builder
Post
(
GET_ACCOUNT
,
map
);
String
str
=
this
.
execute
(
request
);
if
(
StringUtils
.
isEmpty
(
str
))
{
this
.
stringRedisTemplate
.
opsForSet
().
add
(
Constant
.
ADDRESS_KEY
,
address
);
...
...
@@ -82,5 +83,65 @@ public class TronServiceImpl extends BaseCommonService implements TronService {
return
JSONObject
.
parseObject
(
str
,
TronAccount
.
class
);
}
@Override
public
List
<
TronTransEvent
>
getContractEvent
(
String
address
)
{
Request
request
=
this
.
builderGet
(
CONTRACT_EVENT
+
address
);
String
str
=
this
.
execute
(
request
);
if
(
StringUtils
.
isEmpty
(
str
))
{
return
null
;
}
System
.
out
.
println
(
"处理前:》》》》》"
+
str
);
String
ret
=
clearData
(
str
);
System
.
out
.
println
(
"处理后:》》》》》"
+
ret
);
return
JSONArray
.
parseArray
(
ret
,
TronTransEvent
.
class
);
}
@Override
public
Contract
getContract
(
String
address
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>(
1
);
map
.
put
(
"value"
,
address
);
Request
request
=
this
.
builderPost
(
GET_CONTRACT
,
map
);
String
str
=
this
.
execute
(
request
);
if
(
StringUtils
.
isEmpty
(
str
))
{
return
null
;
}
return
JSONObject
.
parseObject
(
str
,
Contract
.
class
);
}
/**
* 数据清洗
*
* 清洗前:
* "1":"2",
* "2":"0x67c62732f1f6086a98310aa5c83163977394f92e",
* "3":"0x4f948b55157ed879a2b6863c22a4e31d28ceebb7",
* "4":"300000000",
* "5":"285000000",
* "6":"15000000",
* 清洗后:
* "_$1":"2",
* "_$2":"0x67c62732f1f6086a98310aa5c83163977394f92e",
* "_$3":"0x4f948b55157ed879a2b6863c22a4e31d28ceebb7",
* "_$4":"300000000",
* "_$5":"285000000",
* "_$6":"15000000",
* @param data
* @return
*/
private
String
clearData
(
String
data
)
{
int
range
=
10
;
String
ret
=
data
;
String
regex
=
"\":"
;
for
(
int
i
=
0
;
i
<
range
;
i
++)
{
String
tmp
=
i
+
regex
;
ret
=
ret
.
replaceAll
(
tmp
,
"_\\$"
+
i
+
"\":"
);
}
return
ret
;
}
}
src/main/java/com/wuban/tron/explore/util/BizExceptionEnum.java
0 → 100644
View file @
6de5665d
package
com
.
wuban
.
tron
.
explore
.
util
;
/**
* @author sky
*
**/
public
enum
BizExceptionEnum
{
/**
* 通用异常.
*/
SERVER_ERROR
(
1000
,
"服务器异常"
),
REQUEST_NULL
(
1001
,
"请求参数有错误"
),
SESSION_TIMEOUT
(
1002
,
"会话超时"
),
PARAM_INVALID
(
1003
,
"参数无效"
),
PARAM_MISS
(
1004
,
"参数丢失"
),
METHOD_NOT_ALLOWED
(
1005
,
"不支持当前请求类型"
),
SQL_EX
(
1006
,
"运行SQL出现异常"
);
BizExceptionEnum
(
int
code
,
String
message
)
{
this
.
code
=
code
;
this
.
message
=
message
;
}
private
Integer
code
;
private
String
message
;
public
Integer
getCode
()
{
return
code
;
}
public
void
setCode
(
Integer
code
)
{
this
.
code
=
code
;
}
public
String
getMessage
()
{
return
message
;
}
public
void
setMessage
(
String
message
)
{
this
.
message
=
message
;
}
}
src/main/resources/application-dev.yml
View file @
6de5665d
...
...
@@ -3,6 +3,10 @@
tron
:
site
:
https://api.shasta.trongrid.io
contract
:
complier
:
site
:
http://47.115.200.174:8080/api/explorer/v1/compileSolidity
spring
:
datasource
:
type
:
com.alibaba.druid.pool.DruidDataSource
...
...
src/main/resources/application-test.yml
View file @
6de5665d
...
...
@@ -3,6 +3,10 @@
tron
:
site
:
https://api.shasta.trongrid.io
contract
:
complier
:
site
:
http://47.115.200.174:8080/api/explorer/v1/compileSolidity
spring
:
datasource
:
type
:
com.alibaba.druid.pool.DruidDataSource
...
...
src/main/resources/mapper/ContractMapper.xml
0 → 100644
View file @
6de5665d
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper
namespace=
"com.wuban.tron.explore.dao.ContractRepository"
>
<!-- CodeBuilder Generated-->
<resultMap
id=
"ContractMap"
type=
"com.wuban.tron.explore.entity.Contract"
>
<result
column=
"id"
property=
"id"
jdbcType=
"BIGINT"
/>
<result
column=
"bytecode"
property=
"bytecode"
jdbcType=
"VARCHAR"
/>
<result
column=
"name"
property=
"name"
jdbcType=
"VARCHAR"
/>
<result
column=
"origin_address"
property=
"originAddress"
jdbcType=
"VARCHAR"
/>
<result
column=
"abi"
property=
"abi"
jdbcType=
"VARCHAR"
/>
<result
column=
"origin_energy_limit"
property=
"originEnergyLimit"
jdbcType=
"BIGINT"
/>
<result
column=
"contract_address"
property=
"contractAddress"
jdbcType=
"VARCHAR"
/>
<result
column=
"code_hash"
property=
"codeHash"
jdbcType=
"VARCHAR"
/>
</resultMap>
<sql
id=
"Example_Where_Clause"
>
<where>
<foreach
collection=
"example.oredCriteria"
item=
"criteria"
separator=
"or"
>
<if
test=
"criteria.valid"
>
<trim
prefix=
"("
suffix=
")"
prefixOverrides=
"and"
>
<foreach
collection=
"criteria.criteria"
item=
"criterion"
>
<choose>
<when
test=
"criterion.noValue"
>
and ${criterion.condition}
</when>
<when
test=
"criterion.singleValue"
>
and ${criterion.condition} #{criterion.value}
</when>
<when
test=
"criterion.betweenValue"
>
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when
test=
"criterion.listValue"
>
and ${criterion.condition}
<foreach
collection=
"criterion.value"
item=
"listItem"
open=
"("
close=
")"
separator=
","
>
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql
id=
"Table_Name"
>
tron_contract
</sql>
<sql
id=
"Base_Column_List_Without_Id"
>
id , bytecode , name , origin_address , abi , origin_energy_limit , contract_address , code_hash
</sql>
<sql
id=
"Base_Column_List"
>
<include
refid=
"Base_Column_List_Without_Id"
/>
</sql>
<sql
id=
"Insert_Columns"
>
<if
test=
"record.id != null"
>
id,
</if>
<if
test=
"record.bytecode != null"
>
bytecode,
</if>
<if
test=
"record.name != null"
>
name,
</if>
<if
test=
"record.originAddress != null"
>
origin_address,
</if>
<if
test=
"record.abi != null"
>
abi,
</if>
<if
test=
"record.originEnergyLimit != null"
>
origin_energy_limit,
</if>
<if
test=
"record.contractAddress != null"
>
contract_address,
</if>
<if
test=
"record.codeHash != null"
>
code_hash,
</if>
</sql>
<sql
id=
"Insert_Values"
>
<if
test=
"record.id != null"
>
#{record.id,jdbcType=BIGINT},
</if>
<if
test=
"record.bytecode != null"
>
#{record.bytecode,jdbcType=VARCHAR},
</if>
<if
test=
"record.name != null"
>
#{record.name,jdbcType=VARCHAR},
</if>
<if
test=
"record.originAddress != null"
>
#{record.originAddress,jdbcType=VARCHAR},
</if>
<if
test=
"record.abi != null"
>
#{record.abi,jdbcType=VARCHAR},
</if>
<if
test=
"record.originEnergyLimit != null"
>
#{record.originEnergyLimit,jdbcType=BIGINT},
</if>
<if
test=
"record.contractAddress != null"
>
#{record.contractAddress,jdbcType=VARCHAR},
</if>
<if
test=
"record.codeHash != null"
>
#{record.codeHash,jdbcType=VARCHAR},
</if>
</sql>
<sql
id=
"Batch_Insert_Values"
>
#{record.id,jdbcType=BIGINT},
#{record.bytecode,jdbcType=VARCHAR},
#{record.name,jdbcType=VARCHAR},
#{record.originAddress,jdbcType=VARCHAR},
#{record.abi,jdbcType=VARCHAR},
#{record.originEnergyLimit,jdbcType=BIGINT},
#{record.contractAddress,jdbcType=VARCHAR},
#{record.codeHash,jdbcType=VARCHAR},
</sql>
<sql
id=
"Batch_Insert_Values_On_DuplicateKey"
>
<include
refid=
"Batch_Insert_Values"
/>
</sql>
<sql
id=
"Update_Set_From_Bean"
>
<if
test=
"record.id != null"
>
id = #{record.id,jdbcType=BIGINT} ,
</if>
<if
test=
"record.bytecode != null"
>
bytecode = #{record.bytecode,jdbcType=VARCHAR} ,
</if>
<if
test=
"record.name != null"
>
name = #{record.name,jdbcType=VARCHAR} ,
</if>
<if
test=
"record.originAddress != null"
>
origin_address = #{record.originAddress,jdbcType=VARCHAR} ,
</if>
<if
test=
"record.abi != null"
>
abi = #{record.abi,jdbcType=VARCHAR} ,
</if>
<if
test=
"record.originEnergyLimit != null"
>
origin_energy_limit = #{record.originEnergyLimit,jdbcType=BIGINT} ,
</if>
<if
test=
"record.contractAddress != null"
>
contract_address = #{record.contractAddress,jdbcType=VARCHAR} ,
</if>
<if
test=
"record.codeHash != null"
>
code_hash = #{record.codeHash,jdbcType=VARCHAR} ,
</if>
</sql>
<!-- insert -->
<insert
id=
"insert"
parameterType=
"java.util.Map"
>
insert into
<include
refid=
"Table_Name"
/>
<trim
prefix=
"("
suffix=
")"
suffixOverrides=
","
>
<include
refid=
"Insert_Columns"
/>
</trim>
<trim
prefix=
"values ("
suffix=
")"
suffixOverrides=
","
>
<include
refid=
"Insert_Values"
/>
</trim>
</insert>
<insert
id=
"batchInsert"
parameterType=
"java.util.Map"
>
insert into
<include
refid=
"Table_Name"
/>
<trim
prefix=
"("
suffix=
")"
suffixOverrides=
","
>
<include
refid=
"Base_Column_List_Without_Id"
/>
</trim>
values
<foreach
collection=
"records"
item=
"record"
index=
"index"
separator=
","
>
<trim
prefix=
"("
suffix=
")"
suffixOverrides=
","
>
<include
refid=
"Batch_Insert_Values"
/>
</trim>
</foreach>
</insert>
<insert
id=
"batchInsertOnDuplicateKey"
parameterType=
"java.util.Map"
>
insert into
<include
refid=
"Table_Name"
/>
<trim
prefix=
"("
suffix=
")"
suffixOverrides=
","
>
<include
refid=
"Base_Column_List"
/>
</trim>
values
<foreach
collection=
"records"
item=
"record"
index=
"index"
separator=
","
>
<trim
prefix=
"("
suffix=
")"
suffixOverrides=
","
>
<include
refid=
"Batch_Insert_Values_On_DuplicateKey"
/>
</trim>
</foreach>
ON DUPLICATE KEY UPDATE
id = VALUES(id) , bytecode = VALUES(bytecode) , name = VALUES(name) , origin_address = VALUES(origin_address) , abi = VALUES(abi) , origin_energy_limit = VALUES(origin_energy_limit) , contract_address = VALUES(contract_address) , code_hash = VALUES(code_hash)
</insert>
<!-- end insert -->
<!-- delete -->
<delete
id=
"deleteById"
parameterType=
"java.util.Map"
>
delete from
<include
refid=
"Table_Name"
/>
where id = #{id,jdbcType=BIGINT}
</delete>
<delete
id=
"deleteByExample"
parameterType=
"java.util.Map"
>
delete from
<include
refid=
"Table_Name"
/>
<if
test=
"example != null"
>
<include
refid=
"Example_Where_Clause"
/>
</if>
</delete>
<delete
id=
"deleteIn"
parameterType=
"java.util.Map"
>
delete from
<include
refid=
"Table_Name"
/>
where id in
<foreach
collection=
"records"
item=
"record"
index=
"index"
open=
"("
separator=
","
close=
")"
>
#{record.id,jdbcType=BIGINT}
</foreach>
</delete>
<!-- end delete -->
<!-- update -->
<update
id=
"updateById"
parameterType=
"java.util.Map"
>
update
<include
refid=
"Table_Name"
/>
<set>
<include
refid=
"Update_Set_From_Bean"
/>
</set>
where id = #{record.id,jdbcType=BIGINT}
</update>
<update
id=
"updateByExample"
parameterType=
"java.util.Map"
>
update
<include
refid=
"Table_Name"
/>
<set>
<include
refid=
"Update_Set_From_Bean"
/>
</set>
<if
test=
"example != null"
>
<include
refid=
"Example_Where_Clause"
/>
</if>
</update>
<update
id=
"batchUpdate"
parameterType=
"java.util.Map"
>
<foreach
collection=
"records"
item=
"record"
index=
"index"
open=
""
close=
""
separator=
";"
>
update
<include
refid=
"Table_Name"
/>
<set>
<include
refid=
"Update_Set_From_Bean"
/>
</set>
where id=#{record.id,jdbcType=BIGINT}
</foreach>
</update>
<!-- end update -->
<!-- select -->
<select
id=
"selectById"
resultMap=
"ContractMap"
parameterType=
"java.util.Map"
>
select
<include
refid=
"Base_Column_List"
/>
from
<include
refid=
"Table_Name"
/>
where id = #{id,jdbcType=BIGINT}
</select>
<select
id=
"selectByExample"
resultMap=
"ContractMap"
parameterType=
"java.util.Map"
>
select
<if
test=
"example != null and example.distinct"
>
distinct
</if>
<include
refid=
"Base_Column_List"
/>
from
<include
refid=
"Table_Name"
/>
<if
test=
"example != null"
>
<include
refid=
"Example_Where_Clause"
/>
</if>
<if
test=
"example != null and example.orderByClause != null"
>
order by ${example.orderByClause}
</if>
</select>
<select
id=
"selectOneByExample"
resultMap=
"ContractMap"
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>
limit 1
</select>
<select
id=
"selectIn"
resultMap=
"ContractMap"
parameterType=
"java.util.Map"
>
select
<include
refid=
"Base_Column_List"
/>
from
<include
refid=
"Table_Name"
/>
where id IN
<foreach
collection=
"records"
item=
"record"
index=
"index"
open=
"("
separator=
","
close=
")"
>
#{record.id,jdbcType=BIGINT}
</foreach>
</select>
<select
id=
"countByExample"
resultType=
"java.lang.Integer"
parameterType=
"java.util.Map"
>
select count(*) as total from
<include
refid=
"Table_Name"
/>
<if
test=
"example != null"
>
<include
refid=
"Example_Where_Clause"
/>
</if>
</select>
<select
id=
"countByPager"
resultType=
"java.lang.Integer"
parameterType=
"java.util.Map"
>
select count(*) as total from
<include
refid=
"Table_Name"
/>
<if
test=
"example != null"
>
<include
refid=
"Example_Where_Clause"
/>
</if>
</select>
<select
id=
"selectByPager"
resultMap=
"ContractMap"
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=
"pager.sortItem != null and pager.sortItem != '' "
>
order by ${pager.sortItem} ${pager.sortType}
</if>
limit #{pager.startIndex} , #{pager.pageSize}
</select>
<!-- end select -->
<!-- My Custom Interfaces -->
</mapper>
src/test/java/com/wuban/tron/explore/service/impl/ContractComplierServiceImplTest.java
0 → 100644
View file @
6de5665d
package
com
.
wuban
.
tron
.
explore
.
service
.
impl
;
import
com.wuban.tron.explore.BaseTest
;
import
com.wuban.tron.explore.service.ContractComplierService
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
class
ContractComplierServiceImplTest
extends
BaseTest
{
@Autowired
private
ContractComplierService
contractComplierService
;
@BeforeEach
void
setUp
()
{
}
@Test
void
complier
()
{
String
name
=
"Storage2"
;
String
complier
=
"solidity0.4.25+commit"
;
String
value
=
"pragma solidity ^0.4.25;\n"
+
"\n"
+
"contract Storage2 {\n"
+
" uint pos0;\n"
+
" mapping(address => uint) pos1;\n"
+
"\n"
+
" function Storage2() {\n"
+
" pos0 = 12334;\n"
+
" pos1[msg.sender] = 56278;\n"
+
" }\n"
+
" \n"
+
" function Hello() public returns (string hel) {\n"
+
" return \"Hello\";\n"
+
" }\n"
+
" \n"
+
" function GetInt() public returns (uint data) {\n"
+
" return pos0;\n"
+
" }\n"
+
" \n"
+
" function SetInt(uint val) public {\n"
+
" pos0 = val;\n"
+
" }\n"
+
"}"
;
String
str
=
this
.
contractComplierService
.
complier
(
name
,
value
,
complier
);
System
.
out
.
println
(
"*************"
+
str
);
}
}
\ No newline at end of file
src/test/java/com/wuban/tron/explore/service/impl/TronServiceImplTest.java
View file @
6de5665d
package
com
.
wuban
.
tron
.
explore
.
service
.
impl
;
import
com.wuban.tron.explore.domain.TronAccount
;
import
com.wuban.tron.explore.domain.TronResponseArrayData
;
import
com.wuban.tron.explore.domain.TronResponseData
;
import
com.wuban.tron.explore.domain.*
;
import
com.wuban.tron.explore.service.TronService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.junit.jupiter.api.Test
;
...
...
@@ -13,6 +11,8 @@ import org.springframework.test.context.junit4.SpringRunner;
import
org.tron.common.utils.ByteArray
;
import
org.tron.walletserver.WalletApi
;
import
java.util.List
;
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
@Slf4j
...
...
@@ -46,5 +46,19 @@ class TronServiceImplTest {
log
.
info
(
hexString
);
}
@Test
void
getContractEvent
()
{
List
<
TronTransEvent
>
data
=
this
.
tronService
.
getContractEvent
(
"TMypW2w7P2y8QzV8i9BAE31yzQukp63tbo"
);
System
.
out
.
println
(
data
);
}
@Test
void
getContract
()
{
String
base58check
=
"TTfwGdf3v66CaYQijg4Qb2CFtdgQnkkFko"
;
String
hexString
=
ByteArray
.
toHexString
(
WalletApi
.
decodeFromBase58Check
(
base58check
));
System
.
out
.
println
(
hexString
);
this
.
tronService
.
getContract
(
hexString
);
}
}
\ No newline at end of file
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