大家好,我是powervip!今天和大家一起探讨一下:如果Fabric的智能合约函数陷入死循环会怎么样
先看一段合约函数代码:
func (t *SimpleChaincode) Test(stub shim.ChaincodeStubInterface, args []string) pb.Response {
// 选择商品价格在1元到100元之间的商品名称和数量
s := "{\"fields\": [\"GoodsName\", \"GoodsCount\"], \"selector\":{ \"$and\": [{\"GoodPrice\":{\"$gte\": 1}}, {\"GoodPrice\":{\"$lte\": 100}}] }}"
resultsIterator, err := stub.GetQueryResult(q)
defer resultsIterator.Close()
if err != nil {
return shim.Error(err.Error())
}
var count uint64
for resultsIterator.HasNext() {
count++
// resultsIterator.Next() // 注释掉该语句,函数将陷入死循环
fmt.Println("count=", count)
}
msg := fmt.Sprintf("count: %