1
您好我想通過導入作爲QSCC一部分的分類包來查詢這些代碼塊,但在嘗試調用時出現一些錯誤,請澄清這是否是正確的方式。查詢系統chaincode的使用
func (t *SimpleChaincode) expt(stub shim.ChaincodeStubInterface, args []string) pb.Response{
var plp ledger.PeerLedgerProvider
var pl ledger.PeerLedger
lId,err:=plp.List()
if err != nil {
return shim.Error("Invalid transaction amount, expecting a integer value")
}
fmt.Println(" List lists the ids of the existing ledgers")
fmt.Println(lId)
yesNO,err:=plp.Exists(lId[0])
if err != nil {
return shim.Error("Invalid transaction amount, expecting a integer value")
}
fmt.Println(" tells whether the ledger with given id exists")
fmt.Println(yesNO)
txid:=args[0]
tx,err:=pl.GetTransactionByID(txid)
if err != nil {
return shim.Error("Invalid transaction amount, expecting a integer value")
}
fmt.Println("transaction")
fmt.Println(tx)
return shim.Success(nil)
}
錯誤是
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x38 pc=0x40301b]
goroutine 7 [running]:
panic(0x9eb1a0, 0xc420016040)
/opt/go/src/runtime/panic.go:500 +0x1a1
main.(*SimpleChaincode).expt(0xfaa000, 0xf71120, 0xc42016ae80, 0xc4202faad0, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, ...)
/chaincode/input/src/github.com/example_cc/example_cc.go:191 +0x5b
main.(*SimpleChaincode).Invoke(0xfaa000, 0xf71120, 0xc42016ae80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
/chaincode/input/src/github.com/example_cc/example_cc.go:98 +0x430
github.com/hyperledger/fabric/core/chaincode/shim.(*Handler).handleTransaction.func1(0xc4202389a0, 0xc4200119a0)
/opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/shim/handler.go:317 +0x483
created by github.com/hyperledger/fabric/core/chaincode/shim.(*Handler).handleTransaction
/opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/shim/handler.go:328 +0x49
你爲什麼要從chaincode查詢塊? –
如果我發送一個TxId給chaincode,我需要知道它已經對哪個密鑰採取了行動,哪個是該密鑰的前一個交易,誰是那些以前的交易的創建者,基於這個我會做出一些決定 –
如果這不是合適的執行出處的方式可能是什麼? –