Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 10cf7e8

Browse files
committed
fix bug
1 parent ba09ced commit 10cf7e8

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

src/main/java/ijarvis/intelliq/Fabric/FabricApp.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ public class FabricApp{
1919
public static CryptoSuite cs = CryptoSuite.Factory.getCryptoSuite();
2020
public static User peer0org1=null;
2121
public static String keypath="/crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp";
22-
22+
public static String CHAINCODENAME="epointchaincodecommon";
23+
public static String CHAINCODEVERSION="0.2";
2324
/**
2425
* 初始化超级账本的客户端等相关属性
2526
*/
@@ -44,9 +45,9 @@ public static void initCA() throws CryptoException, InvalidArgumentException {
4445
* */
4546
public static void instertFabcar(Channel channel, LedgerRecord record) throws Exception {
4647
QueryByChaincodeRequest req = client.newQueryProposalRequest();
47-
ChaincodeID cid = ChaincodeID.newBuilder().setName("epointchaincodezzk").setVersion("0.1").build();
48+
ChaincodeID cid = ChaincodeID.newBuilder().setName(CHAINCODENAME).setVersion(CHAINCODEVERSION).build();
4849
req.setChaincodeID(cid);
49-
req.setFcn("addcard");
50+
req.setFcn("addkv");
5051
req.setArgs(record.toStringArray());
5152
logger.debug("addcard data"+record.toStringArray());
5253
Collection<ProposalResponse> resps = channel.queryByChaincode(req);
@@ -60,7 +61,7 @@ public static void instertFabcar(Channel channel, LedgerRecord record) throws Ex
6061
* */
6162
public static void queryFabcar(Channel channel, String key) throws Exception {
6263
QueryByChaincodeRequest req = client.newQueryProposalRequest();
63-
ChaincodeID cid = ChaincodeID.newBuilder().setName("epointchaincodezzk").setVersion("0.1").build();
64+
ChaincodeID cid = ChaincodeID.newBuilder().setName(CHAINCODENAME).setVersion(CHAINCODEVERSION).build();
6465
req.setChaincodeID(cid);
6566
req.setFcn("query");
6667
req.setArgs(new String[] { key });

src/main/java/ijarvis/intelliq/FabricCA/FabricCAApp.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
import org.hyperledger.fabric.sdk.security.CryptoSuite;
1212

1313
import java.util.Collection;
14+
import java.util.HashMap;
15+
import java.util.Map;
16+
17+
import static java.nio.charset.StandardCharsets.UTF_8;
1418

1519
public class FabricCAApp {
1620
private static Logger logger=Logger.getLogger(FabricCAApp.class);
@@ -28,29 +32,40 @@ public static void init(User CAUSER) throws CryptoException, InvalidArgumentExce
2832
* 调用链码添加KV结构
2933
*/
3034
public static void addKV(Channel channel, LedgerRecord record) throws ProposalException, InvalidArgumentException {
31-
QueryByChaincodeRequest req = client.newQueryProposalRequest();
35+
TransactionProposalRequest req = client.newTransactionProposalRequest();
3236
req.setChaincodeID(cid);
3337
req.setFcn("addkv");
3438
req.setArgs(record.toStringArray());
35-
Collection<ProposalResponse> resps = channel.queryByChaincode(req);
39+
//TODO 该段代码必须调用,但是未在官方的代码中找到相关的代码说明
40+
Map<String, byte[]> tm2 = new HashMap<>();
41+
tm2.put("HyperLedgerFabric", "TransactionProposalRequest:JavaSDK".getBytes(UTF_8));
42+
tm2.put("method", "TransactionProposalRequest".getBytes(UTF_8));
43+
tm2.put("result", ":)".getBytes(UTF_8));
44+
req.setTransientMap(tm2);
45+
46+
47+
Collection<ProposalResponse> resps = channel.sendTransactionProposal(req);
48+
3649
for (ProposalResponse resp : resps) {
3750
String payload = new String(resp.getChaincodeActionResponsePayload());
3851
logger.debug("response: " + payload);
3952
}
53+
channel.sendTransaction(resps);
4054
}
4155
/**
4256
* 调用链码更新
4357
*/
4458
public static void updateKV(Channel channel,LedgerRecord record) throws ProposalException, InvalidArgumentException {
45-
QueryByChaincodeRequest req = client.newQueryProposalRequest();
59+
TransactionProposalRequest req = client.newTransactionProposalRequest();
4660
req.setChaincodeID(cid);
4761
req.setFcn("updatekv");
4862
req.setArgs(record.toStringArray());
49-
Collection<ProposalResponse> resps = channel.queryByChaincode(req);
63+
Collection<ProposalResponse> resps = channel.sendTransactionProposal(req);
5064
for (ProposalResponse resp : resps) {
5165
String payload = new String(resp.getChaincodeActionResponsePayload());
5266
logger.debug("response: " + payload);
5367
}
68+
channel.sendTransaction(resps);
5469
}
5570
/*
5671
* 实现根绝给定的Key查询数据

src/test/java/ijarvis/intelliq/Fabric/AppTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.hyperledger.fabric.sdk.exception.CryptoException;
88
import org.hyperledger.fabric.sdk.exception.InvalidArgumentException;
99
import org.junit.Before;
10+
import org.junit.Ignore;
1011
import org.junit.Test;
1112

1213
import java.util.UUID;
@@ -22,7 +23,7 @@ public class AppTest {
2223
private static String CONNFIG_Peer0Org2="grpc://192.168.188.114:7051";
2324
private static String CONNFIG_Peer1Org2="grpc://192.168.188.115:7051";
2425
private static String CHANNELID="epointchannel";
25-
private static LedgerRecord PERSONINFO=new LedgerRecord("liudong","刘东");
26+
private static LedgerRecord PERSONINFO=new LedgerRecord("liuwenru","{name:\"liuwenhua\",cname:\"刘文华\"}");
2627
@Before
2728
public void Setup() throws CryptoException, InvalidArgumentException {
2829
logger.debug("Fabric Test Init........");
@@ -60,6 +61,7 @@ public void TestEpointChainCodeQuery() throws Exception {
6061
/**
6162
*
6263
*/
64+
@Ignore
6365
@Test
6466
public void TestEpointChainCodeMutilInstert() throws Exception{
6567
logger.debug("测试Fabric 循环插入1000个值测试监控值是否包含变化");

src/test/java/ijarvis/intelliq/FabricCA/FabricCATestUseCAServer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
public class FabricCATestUseCAServer {
2323
private static Logger logger=Logger.getLogger(FabricCATestUseCAServer.class);
2424
HashMap<String,SampleOrg> orgHashMap=new HashMap<>();
25-
private static LedgerRecord PERSONINFO=new LedgerRecord("liuwenru","刘文儒");
25+
private static LedgerRecord PERSONINFO=new LedgerRecord("liuwenru","基础设置支持部");
2626

2727
@Before
2828
public void Setup() throws EnrollmentException, InvalidArgumentException, CryptoException, org.hyperledger.fabric.sdk.exception.InvalidArgumentException, MalformedURLException {
@@ -48,7 +48,7 @@ public void TestEpointChainCodeAddKV()throws Exception{
4848
@Test
4949
public void TestEpointChainCodeUpdate() throws Exception {
5050
logger.debug("链码测试........向链码中更新KV");
51-
LedgerRecord tmp=new LedgerRecord("liuwenru","刘美丽");
51+
LedgerRecord tmp=new LedgerRecord("liuwenru","刘美丽,刘帅帅");
5252
Channel channel = FabricCAApp.client.newChannel(TestConfigure.CHANNLNAME);
5353
channel.addPeer(FabricCAApp.client.newPeer("peer", orgHashMap.get("org1").getPeerLocation("peer0org1")));
5454
channel.addOrderer(FabricCAApp.client.newOrderer("orderer", orgHashMap.get("org1").getOrdererLocation("orderer")));

0 commit comments

Comments
 (0)