【发布时间】:2019-09-29 21:15:02
【问题描述】:
我有三个客户端应用程序,它们分别使用 Java、Node.js 和 Go SDK 与我的区块链 Fabric 进行交互。使用它们,我可以成功地查询和更新账本。
现在我想测量账本更新期间的延迟。所以,我想在提交请求之前获取一个时间戳,在事务成功提交到账本之后再获取一个时间戳,然后计算差异。
我的问题是我找不到任何关于Java、Go和Node.js的SDK API的完整文档,所以我不知道当提交方法返回时,我是否可以认为事务已正确提交到账本。
这是我的三个客户的代码。 爪哇:
NetworkConfig ccp = NetworkConfig.fromJsonFile(networkConfigPath.toFile());
// initialize default cryptosuite and setup the client
CryptoSuite cryptoSuite = CryptoSuite.Factory.getCryptoSuite();
HFClient client = HFClient.createNewInstance();
client.setCryptoSuite(cryptoSuite);
Channel channel = client.loadChannelFromConfig(ccp.getChannelNames().iterator().next(), ccp);
channel.initialize();
TransactionProposalRequest transactionProposal = client.newTransactionProposalRequest();
// build chaincode id providing the chaincode name
ChaincodeID mychaincodeID = ChaincodeID.newBuilder().setName("mychaincode").build();
transactionProposal.setChaincodeID(mychaincodeID);
// calling chaincode function
transactionProposal.setFcn("mymethod");
transactionProposal.setArgs("a1");
Collection<ProposalResponse> res = channel.sendTransactionProposal(transactionProposal);
channel.sendTransaction(res);
Node.js:
const gateway = new Gateway();
await gateway.connect(ccp, { wallet: wallet, identity: userName, discovery: { enabled: false } });
// Get the network (channel) our contract is deployed to.
const network = await gateway.getNetwork('mychannel');
// Get the contract from the network.
const contract = network.getContract('mychaincode');
const result = await contract.submitTransaction('mymethod', 'a1');
去:
sdk, err := fabsdk.New(config.FromFile(configFile))
if err != nil {
fmt.Printf("failed to create SDK: %v\n", err)
return
}
fmt.Println("SDK created")
// Prepare channel client context using client context
clientChannelContext := sdk.ChannelContext(channelID, fabsdk.WithUser(userName), fabsdk.WithOrg(orgName))
// ChannelClient is used to query and execute transactions
client, err := channel.New(clientChannelContext)
if err != nil {
fmt.Printf("failed to create new channel client: %v\n", err)
return
}
fmt.Println("channel client created")
response, err := client.Execute(channel.Request{ChaincodeID: ccID, Fcn: "mymethod", Args: [][]byte{[]byte("a1")}}, channel.WithRetry(retry.DefaultChannelOpts))
if err != nil {
fmt.Printf("failed to execute the invoke function: %v\n", err)
} else {
fmt.Println("Proposal responses: ")
for _, element := range response.Responses {
fmt.Printf("Endorser: %s Status: %d ChaincodeStatus: %d\n", element.Endorser, element.Status, element.ChaincodeStatus)
}
fmt.Println("chaincode transaction completed: " + string(response.Payload))
}
// Close SDK
sdk.Close()
这些代码有效。我的问题是:我可以确定在这些行之后
channel.sendTransaction(res)
(在 Java 中)
const result = await contract.submitTransaction('mymethod', 'a1');
(在 Node.js 中)
response, err := client.Execute(channel.Request{ChaincodeID: ccID, Fcn: "mymethod", Args: [][]byte{[]byte("a1")}}, channel.WithRetry(retry.DefaultChannelOpts))
(在围棋中) 交易是否已提交到账本?
我只在文档中发现:
"向账本提交交易。交易函数名称将在背书节点上进行评估,然后提交给排序服务以提交账本。"在https://fabric-sdk-node.github.io/release-1.4/module-fabric-network.Contract.html#submitTransaction__anchorhttps://fabric-sdk-node.github.io/release-1.4/module-fabric-network.Contract.html#submitTransaction__anchor
的 Node.js 中的 submitTransaction和
“使用请求和可选请求选项执行准备和执行事务”用于在 Go 中执行 https://godoc.org/github.com/hyperledger/fabric-sdk-go/pkg/client/channel#Client.Execute
对于 Java,我找不到文档...我也不确定 Node.js 和 Go。
【问题讨论】:
标签: hyperledger-fabric hyperledger-fabric-sdk-js hyperledger-fabric-sdk-go