Commit 46768dc1 authored by jianhua.zhang's avatar jianhua.zhang

新增solidity版本功能接口开发,新增合约校验、验证接口开发

parent 9a9d02a5
package com.wuban.tron.explore.controller;
import com.wuban.tron.explore.entity.Contract;
import com.wuban.tron.explore.entity.SolidityVersion;
import com.wuban.tron.explore.entity.example.ContractExample;
import com.wuban.tron.explore.param.request.ContractCompilerRequest;
import com.wuban.tron.explore.param.request.ContractRequest;
import com.wuban.tron.explore.service.ContractComplierService;
import com.wuban.tron.explore.param.response.ContractModel;
import com.wuban.tron.explore.service.ContractCompilerService;
import com.wuban.tron.explore.service.ContractService;
import com.wuban.tron.explore.service.SolidityVersionService;
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.BeanUtils;
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 org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;
/**
* <core>合约校验API接口</core>
......@@ -36,10 +39,97 @@ public class ContractController {
private final TronService tronService;
private final ContractComplierService contractComplierService;
private final ContractCompilerService contractCompilerService;
private final SolidityVersionService solidityVersionService;
@RequestMapping(value="getVersion", method = RequestMethod.GET)
public ApiResponse getVersion() {
List<SolidityVersion> list = this.solidityVersionService.selectByExample(null);
return ResponseKit.success(list);
}
@RequestMapping(value="checkContract/{address}", method = RequestMethod.GET)
public ApiResponse checkContract(@PathVariable("address") String address) {
if (StringUtils.isEmpty(address)) {
return ResponseKit.fail(BizExceptionEnum.REQUEST_NULL.getCode(), BizExceptionEnum.REQUEST_NULL.getMessage());
}
/*
按照合约地址查询DB中是否存在此合约
*/
ContractExample example = new ContractExample();
example.createCriteria().andContractAddressEqualTo(address);
Contract con = this.contractService.selectOneByExample(example);
// 未编译
int isCompiler = 0;
if (con != null) {
isCompiler = 1;
}
return ResponseKit.success(isCompiler);
}
@RequestMapping(value="getContractInfoById/{address}", method = RequestMethod.GET)
public ApiResponse getContractInfoById(@PathVariable("address") String address) {
if (StringUtils.isEmpty(address)) {
return ResponseKit.fail(BizExceptionEnum.REQUEST_NULL.getCode(), BizExceptionEnum.REQUEST_NULL.getMessage());
}
ContractExample example = new ContractExample();
example.createCriteria().andContractAddressEqualTo(address);
Contract con = this.contractService.selectOneByExample(example);
ContractModel model = new ContractModel();
if (con != null) {
BeanUtils.copyProperties(con, model, "id");
model.setId(con.getContractAddress());
model.setCode(con.getBytecode());
}
return ResponseKit.success(model);
}
@RequestMapping(value="compileSolidityOne", method = RequestMethod.POST)
public ApiResponse compileSolidityOne(@RequestBody @Valid ContractModel reqParam) {
boolean flag = false;
Contract con = this.tronService.getContract(reqParam.getId());
if (con != null) {
if (con.getBytecode().equals(reqParam.getCode())) {
flag = true;
}
}
return ResponseKit.success(flag);
}
@RequestMapping(value="compileSolidity", method = RequestMethod.POST)
public ApiResponse checkContract(@RequestBody @Valid ContractRequest reqParam) {
public ApiResponse compileSolidity(@RequestBody @Valid ContractCompilerRequest reqParam) {
String code = this.contractCompilerService.compiler(reqParam.getName(), reqParam.getValue(), reqParam.getCompiler());
return ResponseKit.success(code);
}
@Deprecated
@RequestMapping(value="compileSolidityAll", method = RequestMethod.POST)
public ApiResponse compileSolidityAll(@RequestBody @Valid ContractRequest reqParam) {
String address = reqParam.getAddress();
if (StringUtils.isEmpty(address)) {
......@@ -63,7 +153,7 @@ public class ContractController {
}
// 编译合约
String code = this.contractComplierService.complier(reqParam.getName(), reqParam.getValue(), reqParam.getCompiler());
String code = this.contractCompilerService.compiler(reqParam.getName(), reqParam.getValue(), reqParam.getCompiler());
// 校验btyecode是否一致,不一致返回,一致持久化
if (!contract.getBytecode().equals(code)) {
......@@ -75,5 +165,4 @@ public class ContractController {
return ResponseKit.success();
}
}
......@@ -422,9 +422,11 @@ public class TransactionControllerV1 {
pageInfo.getList().forEach(o -> {
AccountInfoModel infoModel = AccountInfoModel.getInstance();
infoModel.setAddress(o.getAddress());
//BigDecimal balance = BigDecimalUtil.getDevide(new BigDecimal(o.getBalance()), BigDecimalUtil.NUM);
// 账户余额 = 可用余额+冻结余额
/*
BigDecimal balance = BigDecimalUtil.getDevide(new BigDecimal(o.getBalance()), BigDecimalUtil.NUM);
账户余额 = 可用余额+冻结余额
*/
BigDecimal accountBalance = new BigDecimal(0);
if (o.getBalance() != null) {
accountBalance = BigDecimalUtil.getAdd(accountBalance, new BigDecimal(o.getBalance()));
......@@ -592,7 +594,9 @@ public class TransactionControllerV1 {
censusModel.setTransNumber(totalVolume.toString());
}
//censusModel.setDifficulty("");
/*
censusModel.setDifficulty("");
*/
return ResponseKit.success(censusModel);
}
......
package com.wuban.tron.explore.dao;
import com.wuban.tron.explore.entity.SolidityVersion;
import com.wuban.tron.explore.entity.example.SolidityVersionExample;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* <core>solidity版本号DAO</core>
*
* @author sky
* @date 2020/11/02
*/
@Repository
public interface SolidityVersionRepository {
/**
* 获取solidity版本号列表
*
* @param example 检索条件
* @return
*/
List<SolidityVersion> selectByExample(@Param("example") SolidityVersionExample example);
}
......@@ -22,22 +22,22 @@ import javax.sql.DataSource;
*/
@Configuration
@MapperScan(basePackages = "com.wuban.tron.explore.dao", sqlSessionTemplateRef = "sqlSessionTemplateEX")
public class DataSourceConfigEX {
@MapperScan(basePackages = "com.wuban.tron.explore.dao", sqlSessionTemplateRef = "sqlSessionTemplateEx")
public class DataSourceConfigEx {
@Value("${spring.datasource.type}")
private Class<? extends DataSource> dataSourceType;
@Bean(name = "dataSourceEX")
@Bean(name = "dataSourceEx")
@ConfigurationProperties(prefix = "spring.datasource")
@Primary
public DataSource buildDataSource() {
return DataSourceBuilder.create().type(this.dataSourceType).build();
}
@Bean(name = "sqlSessionFactoryEX")
@Bean(name = "sqlSessionFactoryEx")
@Primary
public SqlSessionFactory buildSqlSessionFactory(@Qualifier("dataSourceEX") final DataSource dataSource)
public SqlSessionFactory buildSqlSessionFactory(@Qualifier("dataSourceEx") final DataSource dataSource)
throws Exception {
final SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
bean.setDataSource(dataSource);
......@@ -48,17 +48,17 @@ public class DataSourceConfigEX {
return bean.getObject();
}
@Bean(name = "transactionManagerEX")
@Bean(name = "transactionManagerEx")
@Primary
public DataSourceTransactionManager buildTransactionManager(
@Qualifier("dataSourceEX") final DataSource dataSource) {
@Qualifier("dataSourceEx") final DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
@Bean(name = "sqlSessionTemplateEX")
@Bean(name = "sqlSessionTemplateEx")
@Primary
public SqlSessionTemplate buildSqlSessionTemplate(
@Qualifier("sqlSessionFactoryEX") final SqlSessionFactory sqlSessionFactory) {
@Qualifier("sqlSessionFactoryEx") final SqlSessionFactory sqlSessionFactory) {
return new SqlSessionTemplate(sqlSessionFactory);
}
......
......@@ -19,39 +19,75 @@ import java.util.Date;
@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;
/**
*
*/
private Long id;
/**
* 合约code
*/
private String bytecode;
/**
* 合约名称
*/
private String name;
/**
*
*/
private String originAddress;
/**
* 合约ABI
*/
private String abi;
/**
*
*/
private Long originEnergyLimit;
/**
* 合约地址
*/
private String contractAddress;
/**
*
*/
private String codeHash;
/**
* solidity版本号
*/
private String version;
/**
* 合约代码
*/
private String source;
/**
*
*/
private String enabled;
/**
*
*/
private String other;
/**
*
*/
private String runs;
/**
*
*/
private String evmVersion;
/**
*
*/
private String licenseType;
/**
*
*/
private String parameters;
/**
*
*/
private String optimization;
public static Contract getInstance() {
return Contract.builder()
.id(0L)
......@@ -61,7 +97,17 @@ public class Contract {
.abi("")
.originEnergyLimit(0L)
.contractAddress("")
.codeHash("")
.build();
.codeHash("")
.version("")
.source("")
.enabled("")
.other("")
.runs("")
.evmVersion("")
.licenseType("")
.parameters("")
.optimization("")
.build();
}
}
\ No newline at end of file
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;
/**
* solidity版本号
* @author sky
* @date 2020-12-01
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class SolidityVersion {
/**
*
*/
private Long id;
/**
*
*/
private String version;
public static SolidityVersion getInstance() {
return SolidityVersion.builder()
.id(0L)
.version("")
.build();
}
}
\ No newline at end of file
......@@ -43,7 +43,7 @@ public class Executor {
}
public void rebuild() {
this.pool = new ThreadPoolExecutor(SIZE, SIZE, 0L, TimeUnit.SECONDS,
this.pool = new ThreadPoolExecutor(SIZE, SIZE*2, 10L, TimeUnit.SECONDS,
new LinkedBlockingQueue<>(), new ExecutorThreadFactory());
}
......
package com.wuban.tron.explore.param.request;
import lombok.Data;
/**
* <core>编译合约请求参数</core>
*
* @author sky
* @date 2020/11/02
*/
@Data
public class ContractCompilerRequest {
private String name;
private String value;
private String compiler;
}
......@@ -24,7 +24,9 @@ public class CensusModel {
@JsonProperty(value="block_number")
private String blockNumber;
private String tps;
//private String difficulty;
/*
private String difficulty;
*/
@JsonProperty(value="address_number")
private String addressNumber;
......
package com.wuban.tron.explore.param.response;
import lombok.Data;
/**
* <core>合约详情MODEL</core>
*
* @author sky
* @date 2020/11/02
*/
@Data
public class ContractModel {
/**
* 合约地址
*/
private String id;
/**
* 合约名称
*/
private String name;
/**
* solidity版本号
*/
private String version;
/**
* 合约代码
*/
private String source;
/**
* 合约ABI
*/
private String abi;
/**
* 合约code
*/
private String code;
/**
*
*/
private String enabled;
/**
*
*/
private String other;
/**
*
*/
private String runs;
/**
*
*/
private String evmVersion;
/**
*
*/
private String licenseType;
/**
*
*/
private String parameters;
/**
*
*/
private String optimization;
}
......@@ -6,16 +6,16 @@ package com.wuban.tron.explore.service;
* @author sky
* @date 2020/11/30
*/
public interface ContractComplierService {
public interface ContractCompilerService {
/**
* 编译合约
*
* @param name 名称
* @param value 合约内容
* @param complier solidity版本号
* @param compiler solidity版本号
* @return
*/
String complier(String name, String value, String complier);
String compiler(String name, String value, String compiler);
}
package com.wuban.tron.explore.service;
import com.wuban.tron.explore.entity.SolidityVersion;
import com.wuban.tron.explore.entity.example.SolidityVersionExample;
import java.util.List;
/**
* <core>solidity版本号服务接口</core>
*
* @author sky
* @date 2020/12/1
*/
public interface SolidityVersionService {
/**
* 版本号列表
*
* @param example
* @return
*/
List<SolidityVersion> selectByExample(SolidityVersionExample example);
}
......@@ -2,7 +2,7 @@ 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.service.ContractCompilerService;
import com.wuban.tron.explore.util.ApiResponse;
import okhttp3.Request;
import org.springframework.stereotype.Service;
......@@ -18,14 +18,14 @@ import java.util.Map;
* @date 2020/11/30
*/
@Service
public class ContractComplierServiceImpl extends BaseCommonService implements ContractComplierService {
public class ContractCompilerServiceImpl extends BaseCommonService implements ContractCompilerService {
@Override
public String complier(String name, String value, String complier) {
public String compiler(String name, String value, String compiler) {
Map<String, Object> map = new HashMap<>(3);
map.put("name", name);
map.put("value", value);
map.put("complier", complier);
map.put("compiler", compiler);
Request request = this.builderPost(map);
String str = this.execute(request);
if (StringUtils.isEmpty(str)) {
......
package com.wuban.tron.explore.service.impl;
import com.wuban.tron.explore.dao.SolidityVersionRepository;
import com.wuban.tron.explore.entity.SolidityVersion;
import com.wuban.tron.explore.entity.example.SolidityVersionExample;
import com.wuban.tron.explore.service.SolidityVersionService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* <core>solidity版本号服务接口实现类</core>
*
* @author sky
* @date 2020/12/1
*/
@Service
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class SolidityVersionServiceImpl implements SolidityVersionService {
private final SolidityVersionRepository solidityVersionRepository;
@Override
public List<SolidityVersion> selectByExample(SolidityVersionExample example) {
return this.solidityVersionRepository.selectByExample(example);
}
}
<?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-->
<!-- 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" />
......@@ -11,6 +11,15 @@
<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" />
<result column="version" property="version" jdbcType="VARCHAR" />
<result column="source" property="source" jdbcType="LONGVARCHAR" />
<result column="enabled" property="enabled" jdbcType="VARCHAR" />
<result column="other" property="other" jdbcType="VARCHAR" />
<result column="runs" property="runs" jdbcType="VARCHAR" />
<result column="evm_version" property="evmVersion" jdbcType="VARCHAR" />
<result column="license_type" property="licenseType" jdbcType="VARCHAR" />
<result column="parameters" property="parameters" jdbcType="VARCHAR" />
<result column="optimization" property="optimization" jdbcType="VARCHAR" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
......@@ -44,9 +53,9 @@
</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>
id , bytecode , name , origin_address , abi , origin_energy_limit , contract_address , code_hash , version , source , enabled , other , runs , evm_version , license_type , parameters , optimization </sql>
<sql id="Base_Column_List">
<include refid="Base_Column_List_Without_Id"/>
<include refid="Base_Column_List_Without_Id"/>
</sql>
<sql id="Insert_Columns">
<if test="record.id != null">id,</if>
......@@ -57,6 +66,15 @@
<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>
<if test="record.version != null">version,</if>
<if test="record.source != null">source,</if>
<if test="record.enabled != null">enabled,</if>
<if test="record.other != null">other,</if>
<if test="record.runs != null">runs,</if>
<if test="record.evmVersion != null">evm_version,</if>
<if test="record.licenseType != null">license_type,</if>
<if test="record.parameters != null">parameters,</if>
<if test="record.optimization != null">optimization,</if>
</sql>
<sql id="Insert_Values">
<if test="record.id != null">#{record.id,jdbcType=BIGINT},</if>
......@@ -67,6 +85,15 @@
<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>
<if test="record.version != null">#{record.version,jdbcType=VARCHAR},</if>
<if test="record.source != null">#{record.source,jdbcType=LONGVARCHAR},</if>
<if test="record.enabled != null">#{record.enabled,jdbcType=VARCHAR},</if>
<if test="record.other != null">#{record.other,jdbcType=VARCHAR},</if>
<if test="record.runs != null">#{record.runs,jdbcType=VARCHAR},</if>
<if test="record.evmVersion != null">#{record.evmVersion,jdbcType=VARCHAR},</if>
<if test="record.licenseType != null">#{record.licenseType,jdbcType=VARCHAR},</if>
<if test="record.parameters != null">#{record.parameters,jdbcType=VARCHAR},</if>
<if test="record.optimization != null">#{record.optimization,jdbcType=VARCHAR},</if>
</sql>
<sql id="Batch_Insert_Values">
#{record.id,jdbcType=BIGINT},
......@@ -77,9 +104,18 @@
#{record.originEnergyLimit,jdbcType=BIGINT},
#{record.contractAddress,jdbcType=VARCHAR},
#{record.codeHash,jdbcType=VARCHAR},
#{record.version,jdbcType=VARCHAR},
#{record.source,jdbcType=LONGVARCHAR},
#{record.enabled,jdbcType=VARCHAR},
#{record.other,jdbcType=VARCHAR},
#{record.runs,jdbcType=VARCHAR},
#{record.evmVersion,jdbcType=VARCHAR},
#{record.licenseType,jdbcType=VARCHAR},
#{record.parameters,jdbcType=VARCHAR},
#{record.optimization,jdbcType=VARCHAR},
</sql>
<sql id="Batch_Insert_Values_On_DuplicateKey">
<include refid="Batch_Insert_Values"/>
<include refid="Batch_Insert_Values"/>
</sql>
<sql id="Update_Set_From_Bean">
<if test="record.id != null">id = #{record.id,jdbcType=BIGINT} ,</if>
......@@ -90,6 +126,15 @@
<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>
<if test="record.version != null">version = #{record.version,jdbcType=VARCHAR} ,</if>
<if test="record.source != null">source = #{record.source,jdbcType=LONGVARCHAR} ,</if>
<if test="record.enabled != null">enabled = #{record.enabled,jdbcType=VARCHAR} ,</if>
<if test="record.other != null">other = #{record.other,jdbcType=VARCHAR} ,</if>
<if test="record.runs != null">runs = #{record.runs,jdbcType=VARCHAR} ,</if>
<if test="record.evmVersion != null">evm_version = #{record.evmVersion,jdbcType=VARCHAR} ,</if>
<if test="record.licenseType != null">license_type = #{record.licenseType,jdbcType=VARCHAR} ,</if>
<if test="record.parameters != null">parameters = #{record.parameters,jdbcType=VARCHAR} ,</if>
<if test="record.optimization != null">optimization = #{record.optimization,jdbcType=VARCHAR} ,</if>
</sql>
<!-- insert -->
<insert id="insert" parameterType="java.util.Map">
......@@ -125,7 +170,7 @@
</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>
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) , version = VALUES(version) , source = VALUES(source) , enabled = VALUES(enabled) , other = VALUES(other) , runs = VALUES(runs) , evm_version = VALUES(evm_version) , license_type = VALUES(license_type) , parameters = VALUES(parameters) , optimization = VALUES(optimization) </insert>
<!-- end insert -->
<!-- delete -->
<delete id="deleteById" parameterType="java.util.Map">
......
<?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.SolidityVersionRepository">
<!-- CodeBuilder Generated-->
<resultMap id="SolidityVersionMap" type="com.wuban.tron.explore.entity.SolidityVersion">
<result column="id" property="id" jdbcType="BIGINT" />
<result column="version" property="version" 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_solidity_version</sql>
<sql id="Base_Column_List_Without_Id">
id , version </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.version != null">version,</if>
</sql>
<sql id="Insert_Values">
<if test="record.id != null">#{record.id,jdbcType=BIGINT},</if>
<if test="record.version != null">#{record.version,jdbcType=VARCHAR},</if>
</sql>
<sql id="Batch_Insert_Values">
#{record.id,jdbcType=BIGINT},
#{record.version,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.version != null">version = #{record.version,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) , version = VALUES(version) </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="SolidityVersionMap" 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="SolidityVersionMap" 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="SolidityVersionMap" 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="SolidityVersionMap" 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="SolidityVersionMap" 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>
package com.wuban.tron.explore.service.impl;
import com.wuban.tron.explore.BaseTest;
import com.wuban.tron.explore.service.ContractComplierService;
import com.wuban.tron.explore.service.ContractCompilerService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
class ContractComplierServiceImplTest extends BaseTest {
class ContractCompilerServiceImplTest extends BaseTest {
@Autowired
private ContractComplierService contractComplierService;
private ContractCompilerService contractComplierService;
@BeforeEach
void setUp() {
}
@Test
void complier() {
void compiler() {
String name = "Storage2";
String complier = "solidity0.4.25+commit";
String compiler = "solidity0.4.25+commit";
String value = "pragma solidity ^0.4.25;\n" +
"\n" +
"contract Storage2 {\n" +
......@@ -42,8 +42,8 @@ class ContractComplierServiceImplTest extends BaseTest {
" pos0 = val;\n" +
" }\n" +
"}";
String str = this.contractComplierService.complier(name, value, complier);
System.out.println("*************"+str);
String str = this.contractComplierService.compiler(name, value, compiler);
System.out.println(str);
}
}
\ No newline at end of file
......@@ -4,7 +4,7 @@ Navicat MySQL Data Transfer
Source Server : 123.56.5.114.master
Source Server Version : 50731
Source Host : 123.56.5.114:13306
Source Database : test_tron
Source Database : tron-explore
Target Server Type : MYSQL
Target Server Version : 50731
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment