gohyperledger-fabrichyperledger

Not able to set multiple events in chaincode per transaction, getting only last event


I have applied multiple events in a function of a chaincode (Hyperledger Fabric v1.1).

func (t *SimpleChaincode) initUsers(stub shim.ChaincodeStubInterface, args []string) pb.Response {
...
//Event supplier_bare
err = stub.SetEvent("supplier_bare", userAsbytes)
if err != nil {
    return shim.Error(err.Error())
}
//Event supplier_bare_1
err = stub.SetEvent("supplier_bare_1", userAsbytes)
if err != nil {
    return shim.Error(err.Error())
}
...
return shim.Success(nil)
}

When I invoke the function, I only get the last event ('supplier_bare_1') per transaction.

Transaction (events):

...
 "events": {
            "chaincode_id": "mycc10",
            "tx_id":"5421ae37d6e1947b7121f411d64dc215ccacbe45b2d0a9c796cc4a3715c922d6",
            "event_name": "supplier_bare_1",
            "payload": {
                        "type": "Buffer",
                        "data": [
                                 ...
                                ]
                       }
           },
...

Does the chaincode works this way or there is a different approach to achieve multiple events in a single function.


Solution

  • From looking at the shim code, there is only one slot in the shim for a chaincode event, so only the last call to setEvent will take effect.