forked from chainHero/heroes-service
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
73 lines (61 loc) · 1.9 KB
/
main.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"fmt"
"os"
"github.com/leadiq/heroes-service/blockchain"
)
func main() {
// Definition of the Fabric SDK properties
fSetup := blockchain.FabricSetup{
// Channel parameters
ChannelID: "leadiq",
ChannelConfig: os.Getenv("GOPATH") + "/src/github.com/leadiq/heroes-service/network/artifacts/leadiq.channel.tx",
// Chaincode parameters
ChainCodeID: "heroes-service",
ChaincodeGoPath: os.Getenv("GOPATH"),
ChaincodePath: "github.com/leadiq/heroes-service/chaincode/",
OrgAdmin: "Admin",
OrgName: "Org1",
ConfigFile: "config.yaml",
// User parameters
UserName: "User1",
}
// Initialization of the Fabric SDK from the previously set properties
err := fSetup.Initialize()
if err != nil {
fmt.Printf("Unable to initialize the Fabric SDK: %v\n", err)
}
// Install and instantiate the chaincode
err = fSetup.InstallAndInstantiateCC()
if err != nil {
fmt.Printf("Unable to install and instantiate the chaincode: %v\n", err)
}
// Query the chaincode
response, err := fSetup.QueryHello()
if err != nil {
fmt.Printf("Unable to query hello on the chaincode: %v\n", err)
} else {
fmt.Printf("Response from the query hello: %s\n", response)
}
// Invoke the chaincode
txID, err := fSetup.PatchHello("something")
if err != nil {
fmt.Printf("Unable to invoke hello on the chaincode: %v\n", err)
} else {
fmt.Printf("Successfully invoke hello, transaction ID: %s\n", txID)
}
// Query again the chaincode
response, err = fSetup.QueryHello()
if err != nil {
fmt.Printf("Unable to query hello on the chaincode: %v\n", err)
} else {
fmt.Printf("Response from the query hello: %s\n", response)
}
// Query again the chaincode
response, err = fSetup.QueryHelloHistory()
if err != nil {
fmt.Printf("Unable to query hello on the chaincode: %v\n", err)
} else {
fmt.Printf("Response from the query hello history: %s\n", response)
}
}