Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
heroes-service/blockchain/invoke.go
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
50 lines (40 sloc)
1.56 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package blockchain | |
import ( | |
"fmt" | |
"github.com/hyperledger/fabric-sdk-go/api/apitxn/chclient" | |
"time" | |
) | |
// InvokeHello | |
func (setup *FabricSetup) InvokeHello(value string) (string, error) { | |
// Prepare arguments | |
var args []string | |
args = append(args, "invoke") | |
args = append(args, "invoke") | |
args = append(args, "hello") | |
args = append(args, value) | |
eventID := "eventInvoke" | |
// Add data that will be visible in the proposal, like a description of the invoke request | |
transientDataMap := make(map[string][]byte) | |
transientDataMap["result"] = []byte("Transient data in hello invoke") | |
// Register a notification handler on the client | |
notifier := make(chan *chclient.CCEvent) | |
rce, err := setup.client.RegisterChaincodeEvent(notifier, setup.ChainCodeID, eventID) | |
if err != nil { | |
return "", fmt.Errorf("failed to register chaincode evet: %v", err) | |
} | |
// Create a request (proposal) and send it | |
response, err := setup.client.Execute(chclient.Request{ChaincodeID: setup.ChainCodeID, Fcn: args[0], Args: [][]byte{[]byte(args[1]), []byte(args[2]), []byte(args[3])}, TransientMap: transientDataMap}) | |
if err != nil { | |
return "", fmt.Errorf("failed to move funds: %v", err) | |
} | |
// Wait for the result of the submission | |
select { | |
case ccEvent := <-notifier: | |
fmt.Printf("Received CC event: %s\n", ccEvent) | |
case <-time.After(time.Second * 20): | |
return "", fmt.Errorf("did NOT receive CC event for eventId(%s)", eventID) | |
} | |
// Unregister the notification handler previously created on the client | |
err = setup.client.UnregisterChaincodeEvent(rce) | |
return response.TransactionID.ID, nil | |
} |