forked from chainHero/heroes-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
invoke.go
46 lines (37 loc) · 1.33 KB
/
invoke.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package blockchain
import (
"fmt"
"github.com/hyperledger/fabric-sdk-go/pkg/client/channel"
"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")
reg, notifier, err := setup.event.RegisterChaincodeEvent(setup.ChainCodeID, eventID)
if err != nil {
return "", err
}
defer setup.event.Unregister(reg)
// Create a request (proposal) and send it
response, err := setup.client.Execute(channel.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: %v\n", ccEvent)
case <-time.After(time.Second * 20):
return "", fmt.Errorf("did NOT receive CC event for eventId(%s)", eventID)
}
return string(response.TransactionID), nil
}