Skip to content

Commit

Permalink
Merge pull request #56 from hyperledger-labs/fix/custom-event-reception
Browse files Browse the repository at this point in the history
Fix CCAPI waiting for inexistant Custom Event response
  • Loading branch information
andremacedopv authored Dec 12, 2023
2 parents e5e0455 + 1116799 commit 1de9739
Showing 1 changed file with 6 additions and 20 deletions.
26 changes: 6 additions & 20 deletions ccapi/chaincode/eventHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"os"

"github.com/hyperledger/fabric-sdk-go/pkg/client/channel"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
)

Expand Down Expand Up @@ -81,30 +80,17 @@ func (event EventHandler) Execute(ccEvent *fab.CCEvent) {
return
}

// Invoke executeEvent tx
var res *channel.Response
var err error
// Invoke tx
txName := "executeEvent"
if event.ReadOnly {
res, _, err = Invoke(os.Getenv("CHANNEL"), os.Getenv("CCNAME"), "runEvent", [][]byte{args}, nil)
if err != nil {
fmt.Println("error invoking transaction: ", err)
return
}
} else {
res, _, err = Invoke(os.Getenv("CHANNEL"), os.Getenv("CCNAME"), "executeEvent", [][]byte{args}, nil)
if err != nil {
fmt.Println("error invoking transaction: ", err)
return
}
txName = "runEvent"
}

var response map[string]interface{}
nerr := json.Unmarshal(res.Payload, &response)
if nerr != nil {
fmt.Println("error unmarshalling response: ", nerr)
_, _, err := Invoke(os.Getenv("CHANNEL"), os.Getenv("CCNAME"), txName, [][]byte{args}, nil)
if err != nil {
fmt.Println("error invoking transaction: ", err)
return
}
fmt.Println("Response: ", response)
} else {
fmt.Println("Event type not supported")
}
Expand Down

0 comments on commit 1de9739

Please sign in to comment.