Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CCAPI waiting for inexistant Custom Event response #56

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading