Skip to content

Commit

Permalink
Merge pull request #245 from WeBankFinTech/dev
Browse files Browse the repository at this point in the history
v1.4.1
  • Loading branch information
CodingCattwo authored Oct 10, 2020
2 parents a93f6d9 + 99bb905 commit 2a78ca6
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 5 deletions.
2 changes: 2 additions & 0 deletions script/webase-ddl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ CREATE TABLE IF NOT EXISTS tb_contract (
description text COMMENT '描述',
create_time datetime DEFAULT NULL COMMENT '创建时间',
modify_time datetime DEFAULT NULL COMMENT '修改时间',
deploy_address varchar(64) DEFAULT NULL COMMENT '合约部署者地址',
deploy_user_name varchar(64) DEFAULT NULL COMMENT '合约部署者用戶名',
PRIMARY KEY (contract_id),
UNIQUE KEY uk_group_path_name (group_id,contract_path,contract_name,account)
) ENGINE=InnoDB AUTO_INCREMENT=200001 DEFAULT CHARSET=utf8 COMMENT='合约表';
Expand Down
4 changes: 2 additions & 2 deletions script/webase-dml.sql
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,5 @@ INSERT INTO `tb_mail_server_config`(`server_name`,`host`,`port`,`username`,`pass
-- ----------------------------
-- 8、init tb_config
-- ----------------------------
INSERT INTO `tb_config`(`config_name`, `config_type`, `config_value`, `create_time`, `modify_time`) VALUES ('docker 镜像版本', 1, 'v2.5.0', '2020-07-22 17:14:23', '2020-07-22 17:14:23');
INSERT INTO `tb_config`(`config_name`, `config_type`, `config_value`, `create_time`, `modify_time`) VALUES ('docker 镜像版本', 1, 'v2.5.0-gm', '2020-07-22 17:14:23', '2020-07-22 17:14:23');
INSERT INTO `tb_config`(`config_name`, `config_type`, `config_value`, `create_time`, `modify_time`) VALUES ('docker 镜像版本', 1, 'v2.6.0', '2020-09-22 17:14:23', '2020-09-22 17:14:23');
INSERT INTO `tb_config`(`config_name`, `config_type`, `config_value`, `create_time`, `modify_time`) VALUES ('docker 镜像版本', 1, 'v2.6.0-gm', '2020-09-22 17:14:23', '2020-09-22 17:14:23');
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
package com.webank.webase.node.mgr.contract;

import com.webank.webase.node.mgr.user.entity.TbUser;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -253,9 +254,13 @@ public TbContract deployContract(DeployInputParam inputParam) throws NodeMgrExce
throw new NodeMgrException(ConstantCode.CONTRACT_DEPLOY_FAIL);
}

// get deploy user name
String userName = userService.getUserNameByAddress(groupId, inputParam.getUser());
//save contract
TbContract tbContract = new TbContract();
BeanUtils.copyProperties(inputParam, tbContract);
tbContract.setDeployAddress(inputParam.getUser());
tbContract.setDeployUserName(userName);
tbContract.setContractAddress(contractAddress);
tbContract.setContractStatus(ContractStatus.DEPLOYED.getValue());
//tbContract.setContractVersion(version);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class ContractParam extends BaseQueryParam {
private Integer contractStatus;
private Integer contractType;
private String partOfBytecodeBin;
private String deployAddress;

/**
* init by contractId.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public class TbContract {
private String description;
private LocalDateTime createTime;
private LocalDateTime modifyTime;

private String deployAddress;
private String deployUserName;
/**
* init by contractId、contractName、groupId、contractPath.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,14 @@ public String getSignUserIdByAddress(int groupId, String address) throws NodeMgr
return user.getSignUserId();
}

public String getUserNameByAddress(int groupId, String address) throws NodeMgrException {
TbUser user = queryUser(null, groupId, null, address, null);
if (user == null) {
throw new NodeMgrException(ConstantCode.USER_NOT_EXIST);
}
return user.getUserName();
}

/**
* update user info.
*/
Expand Down
23 changes: 21 additions & 2 deletions src/main/resources/mapper/ContractMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@
property="createTime"/>
<result column="modify_time" javaType="java.time.LocalDateTime" jdbcType="TIMESTAMP"
property="modifyTime"/>
<result column="deploy_address" javaType="java.lang.String" jdbcType="VARCHAR"
property="deployAddress"/>
<result column="deploy_user_name" javaType="java.lang.String" jdbcType="VARCHAR"
property="deployUserName"/>
</resultMap>


<insert id="add" parameterType="com.webank.webase.node.mgr.contract.entity.TbContract">
insert into
tb_contract(group_id,contract_path,contract_version,contract_name,account,contract_source,contract_abi,contract_bin,bytecodeBin,contract_address,description,deploy_time,create_time,modify_time)
values(#{groupId},#{contractPath},#{contractVersion},#{contractName},#{account},#{contractSource},#{contractAbi},#{contractBin},#{bytecodeBin},#{contractAddress},#{description},#{deployTime},NOW(),NOW())
tb_contract(group_id,contract_path,contract_version,contract_name,account,contract_source,contract_abi,contract_bin,bytecodeBin,contract_address,description,deploy_time,create_time,modify_time,deploy_address,deploy_user_name)
values(#{groupId},#{contractPath},#{contractVersion},#{contractName},#{account},#{contractSource},#{contractAbi},#{contractBin},#{bytecodeBin},#{contractAddress},#{description},#{deployTime},NOW(),NOW(),#{deployAddress},#{deployUserName})
<selectKey keyProperty="contractId" order="AFTER" resultType="java.lang.Integer">
SELECT LAST_INSERT_ID()
</selectKey>
Expand Down Expand Up @@ -91,6 +95,12 @@
<if test="description != null and description != ''">
,description = #{description}
</if>
<if test="deployAddress != null and deployAddress != ''">
,deploy_address = #{deployAddress}
</if>
<if test="deployUserName != null and deployUserName != ''">
,deploy_user_name = #{deployUserName}
</if>
where contract_id = #{contractId}
</update>

Expand Down Expand Up @@ -133,6 +143,9 @@
<if test="contractStatus != null and contractStatus != ''">
and contract_status = #{contractStatus}
</if>
<if test="deployAddress != null and deployAddress != ''">
and deploy_address = #{deployAddress}
</if>
</select>


Expand Down Expand Up @@ -160,6 +173,9 @@
<if test="contractAddress != null and contractAddress != ''">
and contract_address = #{contractAddress}
</if>
<if test="deployAddress != null and deployAddress != ''">
and deploy_address = #{deployAddress}
</if>
<if test="flagSortedByTime != null and flagSortedByTime != ''">
order by modify_time ${flagSortedByTime}
</if>
Expand Down Expand Up @@ -193,6 +209,9 @@
<if test="contractAddress != null and contractAddress != ''">
and contract_address = #{contractAddress}
</if>
<if test="deployAddress != null and deployAddress != ''">
and deploy_address = #{deployAddress}
</if>
<if test="contractStatus != null and contractStatus != ''">
and contract_status = #{contractStatus}
</if>
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/node/mgr/test/contract/ContractServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package node.mgr.test.contract;


import com.webank.webase.node.mgr.contract.entity.ContractParam;
import java.util.Arrays;
import java.util.List;

Expand Down Expand Up @@ -79,4 +80,10 @@ public void sendTransactionTest(){
assert (transRsp!=null);
}

@Test
public void testGetContractList() {
List<TbContract> resList = contractService.qureyContractList(new ContractParam());
System.out.println("list:");
System.out.println(resList);
}
}

0 comments on commit 2a78ca6

Please sign in to comment.