无法在查询上下文中放置状态 [英] Cannot put state in query context

查看:123
本文介绍了无法在查询上下文中放置状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



  func(

我试图在chaincode中使用一个ticker来定期更新chaincode状态。 t * SimpleChaincode)Invoke(stub * shim.ChaincodeStub,函数字符串,args []字符串)([]字节,错误){

ticker:= time.NewTicker(time.Millisecond * 10000)
去func(){
for t:= range ticker.C {
fmt.Println(Tick at,t)
a = a + 5
err: = stub.PutState(a,[] byte(strconv.Itoa(a)))
fmt.Println(err.Error())
}
}()

return nil,nil

}

我使用链式代码REST api发送调用事务以进行调用:

  POST http://< ip> ;:< port> / chaincode 
{
jsonrpc:2.0,
method:invoke,
params:{
type:1,
chaincodeID:{
name:c7b3c82f1170423115dcfc2524189f96f156b309 61e0a0e84426c425c22f3b4e8b6ecbf477b76e014bfce74b996dee476a2470cbddc14d390617192f00c22c38

ctorMsg:{
function:invoke,
args:[]
},
secureContext:tom
},
id:1
}

但是PutState失败并显示以下日志:

  2016/05/20 13:44:04 [8bcbe40e ]内putstate,isTransaction = false 
在2016-05-20 13:44:04.609079034 +0000 UTC
嘀嗒不能在查询上下文中放置状态
在2016-05-20 13:44 :14.609093012 +0000 UTC
无法在查询上下文中放置状态
2016/05/20 13:44:14 [8bcbe40e] Inside putstate,isTransaction = false
在2016-05-20 13 :44:24.609070317 +0000 UTC
无法在查询语境中放置状态

为什么 isTransaction = false ,为什么它将此上下文视为查询上下文 >解决方案

原始调用事务已完成并返回。来自goroutine的PutState在事务上下文之外继续(正如它本身成为由链式代码本身启动的事务)。这是不允许的。与分类账的所有交互都是外部交易的一部分。


Im trying to use a ticker in my chaincode to update the chaincode state periodically, based on some condition:

func (t *SimpleChaincode) Invoke(stub *shim.ChaincodeStub, function string, args []string) ([]byte, error) {

  ticker := time.NewTicker(time.Millisecond * 10000)
    go func() {
        for t := range ticker.C {
            fmt.Println("Tick at", t)
            a = a+5
            err:= stub.PutState("a", []byte(strconv.Itoa(a)))     
            fmt.Println(err.Error())
        }
    }()

return nil, nil

}

I am sending the invoke transaction using the chaincode REST api for invoke :

POST http://<ip>:<port>/chaincode
{
  "jsonrpc": "2.0",
  "method": "invoke",
  "params": {
    "type": 1,
    "chaincodeID":{
        "name":"c7b3c82f1170423115dcfc2524189f96f156b30961e0a0e84426c425c22f3b4e8b6ecbf477b76e014bfce74b996dee476a2470cbddc14d390617192f00c22c38"
    },
    "ctorMsg": {
        "function":"invoke",
        "args":[]
    },
 "secureContext": "tom"
 },
  "id": 1
}

But PutState is failing with the following log:

2016/05/20 13:44:04 [8bcbe40e]Inside putstate, isTransaction = false
Tick at 2016-05-20 13:44:04.609079034 +0000 UTC
Cannot put state in query context
Tick at 2016-05-20 13:44:14.609093012 +0000 UTC
Cannot put state in query context
2016/05/20 13:44:14 [8bcbe40e]Inside putstate, isTransaction = false
Tick at 2016-05-20 13:44:24.609070317 +0000 UTC
Cannot put state in query context

Why is isTransaction = false , and why does it consider this context as a query context ?

解决方案

The original invoke transaction has completed and returned. The PutState from goroutine continues outside the transaction context (becoming, as it were, "a transaction" initiated by the chaincode itself). This is not allowed. All interactions with the ledger have to be part of an external transaction.

这篇关于无法在查询上下文中放置状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆