Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit10cf7e8

Browse files
committed
fix bug
1 parentba09ced commit10cf7e8

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
publicstaticCryptoSuitecs =CryptoSuite.Factory.getCryptoSuite();
2020
publicstaticUserpeer0org1=null;
2121
publicstaticStringkeypath="/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp";
22-
22+
publicstaticStringCHAINCODENAME="epointchaincodecommon";
23+
publicstaticStringCHAINCODEVERSION="0.2";
2324
/**
2425
* 初始化超级账本的客户端等相关属性
2526
*/
@@ -44,9 +45,9 @@ public static void initCA() throws CryptoException, InvalidArgumentException {
4445
* */
4546
publicstaticvoidinstertFabcar(Channelchannel,LedgerRecordrecord)throwsException {
4647
QueryByChaincodeRequestreq =client.newQueryProposalRequest();
47-
ChaincodeIDcid =ChaincodeID.newBuilder().setName("epointchaincodezzk").setVersion("0.1").build();
48+
ChaincodeIDcid =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
publicstaticvoidqueryFabcar(Channelchannel,Stringkey)throwsException {
6263
QueryByChaincodeRequestreq =client.newQueryProposalRequest();
63-
ChaincodeIDcid =ChaincodeID.newBuilder().setName("epointchaincodezzk").setVersion("0.1").build();
64+
ChaincodeIDcid =ChaincodeID.newBuilder().setName(CHAINCODENAME).setVersion(CHAINCODEVERSION).build();
6465
req.setChaincodeID(cid);
6566
req.setFcn("query");
6667
req.setArgs(newString[] {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
importorg.hyperledger.fabric.sdk.security.CryptoSuite;
1212

1313
importjava.util.Collection;
14+
importjava.util.HashMap;
15+
importjava.util.Map;
16+
17+
importstaticjava.nio.charset.StandardCharsets.UTF_8;
1418

1519
publicclassFabricCAApp {
1620
privatestaticLoggerlogger=Logger.getLogger(FabricCAApp.class);
@@ -28,29 +32,40 @@ public static void init(User CAUSER) throws CryptoException, InvalidArgumentExce
2832
* 调用链码添加KV结构
2933
*/
3034
publicstaticvoidaddKV(Channelchannel,LedgerRecordrecord)throwsProposalException,InvalidArgumentException {
31-
QueryByChaincodeRequestreq =client.newQueryProposalRequest();
35+
TransactionProposalRequestreq =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 =newHashMap<>();
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 (ProposalResponseresp :resps) {
3750
Stringpayload =newString(resp.getChaincodeActionResponsePayload());
3851
logger.debug("response: " +payload);
3952
}
53+
channel.sendTransaction(resps);
4054
}
4155
/**
4256
* 调用链码更新
4357
*/
4458
publicstaticvoidupdateKV(Channelchannel,LedgerRecordrecord)throwsProposalException,InvalidArgumentException {
45-
QueryByChaincodeRequestreq =client.newQueryProposalRequest();
59+
TransactionProposalRequestreq =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 (ProposalResponseresp :resps) {
5165
Stringpayload =newString(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
importorg.hyperledger.fabric.sdk.exception.CryptoException;
88
importorg.hyperledger.fabric.sdk.exception.InvalidArgumentException;
99
importorg.junit.Before;
10+
importorg.junit.Ignore;
1011
importorg.junit.Test;
1112

1213
importjava.util.UUID;
@@ -22,7 +23,7 @@ public class AppTest {
2223
privatestaticStringCONNFIG_Peer0Org2="grpc://192.168.188.114:7051";
2324
privatestaticStringCONNFIG_Peer1Org2="grpc://192.168.188.115:7051";
2425
privatestaticStringCHANNELID="epointchannel";
25-
privatestaticLedgerRecordPERSONINFO=newLedgerRecord("liudong","刘东");
26+
privatestaticLedgerRecordPERSONINFO=newLedgerRecord("liuwenru","{name:\"liuwenhua\",cname:\"刘文华\"}");
2627
@Before
2728
publicvoidSetup()throwsCryptoException,InvalidArgumentException {
2829
logger.debug("Fabric Test Init........");
@@ -60,6 +61,7 @@ public void TestEpointChainCodeQuery() throws Exception {
6061
/**
6162
*
6263
*/
64+
@Ignore
6365
@Test
6466
publicvoidTestEpointChainCodeMutilInstert()throwsException{
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
publicclassFabricCATestUseCAServer {
2323
privatestaticLoggerlogger=Logger.getLogger(FabricCATestUseCAServer.class);
2424
HashMap<String,SampleOrg>orgHashMap=newHashMap<>();
25-
privatestaticLedgerRecordPERSONINFO=newLedgerRecord("liuwenru","刘文儒");
25+
privatestaticLedgerRecordPERSONINFO=newLedgerRecord("liuwenru","基础设置支持部");
2626

2727
@Before
2828
publicvoidSetup()throwsEnrollmentException,InvalidArgumentException,CryptoException,org.hyperledger.fabric.sdk.exception.InvalidArgumentException,MalformedURLException {
@@ -48,7 +48,7 @@ public void TestEpointChainCodeAddKV()throws Exception{
4848
@Test
4949
publicvoidTestEpointChainCodeUpdate()throwsException {
5050
logger.debug("链码测试........向链码中更新KV");
51-
LedgerRecordtmp=newLedgerRecord("liuwenru","刘美丽");
51+
LedgerRecordtmp=newLedgerRecord("liuwenru","刘美丽,刘帅帅");
5252
Channelchannel =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)

[8]ページ先頭

©2009-2025 Movatter.jp