-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathInvokeTest.java
43 lines (32 loc) · 1.59 KB
/
InvokeTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.hyperledger.fabric.sdk.handler;
import com.hyperledger.fabric.sdk.entity.dto.api.BuildClientDTO;
import com.hyperledger.fabric.sdk.entity.dto.api.ExecuteCCDTO;
import org.hyperledger.fabric.sdk.ChaincodeID;
import org.hyperledger.fabric.sdk.Channel;
import org.hyperledger.fabric.sdk.HFClient;
/**
* Created by L.Answer on 2018-09-04 16:47
*
* 操作智能合约测试用例
*/
public class InvokeTest {
public static void main(String[] args) throws Exception {
/* 通道名称 */
String channelName = "mychannel";
/* 智能合约配置信息 */
String chaincodeName = "mycc";
String chaincodeVersion = "1.0";
String chaincodePath = "github.com/chaincode_example02";
ChaincodeID chaincodeID = ChaincodeID.newBuilder().setName(chaincodeName).setVersion(chaincodeVersion).setPath(chaincodePath).build();
// 1. 初始化客户端
String mspPath = "crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/";
BuildClientDTO buildClientDTO = new BuildClientDTO.Builder()
.name("org1.example.com").mspId("Org1MSP").mspPath(mspPath).build();
HFClient client = ApiHandler.clientBuild(buildClientDTO);
// 2. 创建通道
Channel channel = ApiHandler.createChannel(client, channelName);
// 3. 转账, 账户a转7 RMVB到账户b
ExecuteCCDTO invokeCCDTO = new ExecuteCCDTO.Builder().funcName("invoke").params(new String[] {"a", "b", "7"}).chaincodeID(chaincodeID).build();
ApiHandler.invokeChainCode(client, channel, invokeCCDTO);
}
}