无法查询从blockchain
我创建了一个简单的织物blockchain使用./byfn.sh无法查询从blockchain
hyperledger面料V1.0.0结果后,我开始我设法安装和实例化网络和docker exe -it cli bash
我chaincode没有任何错误。 然后我调用我chaincode用这个命令
> peer chaincode invoke -o orderer.example.com:7050 --tls
> $CORE_PEER_TLS_ENABLED --cafile
> /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
> -C ethos -n ethos_ccv100 -c '{"Args":["CreatePatientInfo","123456", "22", "175","74","133","37","Eggs","Fever", "Wei Quan", "Tsu",
> "11April1995","[email protected]","96259561", "SINGAPOREAN",
> "Chinese", "Buddist", "Single","13Aug2017"]}'
调用是成功的返回200
但是当我运行一个查询,以取回数据,也没有输出。
peer chaincode query -C ethos -n ethos_ccv100 -c '{"Args["queryPatientInfo","123456"]}'
或
peer chaincode query -C ethos -n ethos_ccv100 -c '{"function":"queryPatientInfo","Args":["123456"]}'
这是我的chaincode (pastebin link)。 任我没有正确调用或查询错误......我也不太清楚
[email protected]:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode query -C ethos -n ethos_ccv100 -v 0.2 -c '{"Args":["queryPatientInfo","S9511924G"]}' -r 2017-08-13 12:48:32.066 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP 2017-08-13 12:48:32.066 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity 2017-08-13 12:48:32.066 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc 2017-08-13 12:48:32.067 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc 2017-08-13 12:48:32.067 UTC [msp/identity] Sign -> DEBU 005 Sign: plaintext: 0A98070A6A08031A0B08A095C1CC0510...74496E666F0A09533935313139323447 2017-08-13 12:48:32.067 UTC [msp/identity] Sign -> DEBU 006 Sign: digest: 4920E5394B2048EC5629886A51A0F022BED4803495C9FC08B5AB62A1463B92BD Query Result (Raw): 2017-08-13 12:48:32.073 UTC [main] main -> INFO 007 Exiting..... [email protected]:/opt/gopath/src/github.com/hyperledger/fabric/peer#
在Hyperledger面料V1.0.0 chaincode应确认下列API:
// Chaincode interface must be implemented by all chaincodes. The fabric runs
// the transactions by calling these functions as specified.
type Chaincode interface {
// Init is called during Instantiate transaction after the chaincode container
// has been established for the first time, allowing the chaincode to
// initialize its internal data
Init(stub ChaincodeStubInterface) pb.Response
// Invoke is called to update or query the ledger in a proposal transaction.
// Updated state variables are not committed to the ledger until the
// transaction is committed.
Invoke(stub ChaincodeStubInterface) pb.Response
}
备注
Query(stub shim.ChaincodeStubInterface) pb.Response
是不是它的一部分,因此能够从你需要明确地添加派遣到该功能的Invoke
里面的账,例如查询状态:
func (t *SampleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
function, args := stub.GetFunctionAndParameters()
if function == "CreatePatientInfo" {
return CreatePatientInfo(stub, args)
} else if function == "queryPatientInfo" {
return t.Query(stub)
}
return shim.Success(nil)
}
还可以防止如果出现混淆,建议您处理出现意外功能名称并返回错误的情况,以便您清楚地表明您执行错误操作。因此,而不是返回
return shim.Success(nil)
做
return shim.Error(fmt.Errorf("Wrong function name, %s", function))
谢谢!这解决了它:D欣赏你的帮助,再次感谢 –
你做到:
回报shim.Success(无)
虽然你需要做的是将一些数据放在里面:
jsonResp:= “{\” 名称\ “:\” “+ A + ”\“ \ ”金额\“:\ ”“ + 串(Avalbytes)+ ”\“}” FMT。的printf( “查询响应:%S \ n”,jsonResp)
回报shim.Success(Avalbytes)
嗯,我已更新我的代码并重新编译,安装并重新实例化。但我仍然没有查询结果在我的cli ... 我重新修改了我的pastebin代码 –
没有足够的信息来帮助您调试的...建议你从后同行和CLI容器相关日志输出为chaincode实例化和查询调用。 – christo4ferris
您在查询中的参数后缺少冒号。我认为它应该是:对等链代码查询-C ethos -n ethos_ccv100 -c'{“Args”:[“queryPatientInfo”,“123456”]}' –