我有三个客户端应用程序,它们分别使用 Java、Node.js 和 Go SDK 与我的区块链 Fabric 进行交互。使用它们,我可以成功查询和更新分类帐。
现在我想测量更新分类帐期间的延迟。所以,我想在提交请求之前获取一个时间戳,然后在事务成功提交到账本之后再获取一个时间戳,然后计算差异。
我的问题是我找不到任何关于 SDK 的 Java、Go 和 Node.js 的 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);
节点.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))
(在 Go 中)交易是否已提交到账本?
我只在文档中发现:
“向账本提交交易。交易函数名称将在背书节点上进行评估,然后提交给排序服务以提交到账本。” 在https://fabric-sdk-node.github.io/release-1.4/module-fabric-network.Contract.html#submitTransaction__anchor的 Node.js 中的 submitTransaction
和
在https://godoc.org/github.com/hyperledger/fabric-sdk-go/pkg/client/channel#Client.Execute在 Go 中执行的“使用请求和可选请求选项执行准备和执行事务”
对于 Java,我找不到文档……我也不确定 Node.js 和 Go。