-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
80 lines (71 loc) · 2.07 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
74
75
76
77
78
79
80
package main
import (
"github.com/chainhero/heroes-service/blockchain"
"fmt"
"os"
"runtime"
"path/filepath"
"github.com/chainhero/heroes-service/web"
"github.com/chainhero/heroes-service/web/controllers"
)
// Fix empty GOPATH with golang 1.8 (see https://github.com/golang/go/blob/1363eeba6589fca217e155c829b2a7c00bc32a92/src/go/build/build.go#L260-L277)
func defaultGOPATH() string {
env := "HOME"
if runtime.GOOS == "windows" {
env = "USERPROFILE"
} else if runtime.GOOS == "plan9" {
env = "home"
}
if home := os.Getenv(env); home != "" {
def := filepath.Join(home, "go")
if filepath.Clean(def) == filepath.Clean(runtime.GOROOT()) {
// Don't set the default GOPATH to GOROOT
// as that will trigger warnings from the go tool.
return ""
}
return def
}
return ""
}
func main() {
// Setup correctly the GOPATH in the environment
if goPath := os.Getenv("GOPATH"); goPath == "" {
os.Setenv("GOPATH", defaultGOPATH())
}
// Initialize the Fabric SDK
fabricSdk, err := blockchain.Initialize()
if err != nil {
fmt.Printf("Unable to initialize the Fabric SDK: %v\n", err)
}
// Install and instantiate the chaincode
err = fabricSdk.InstallAndInstantiateCC()
if err != nil {
fmt.Printf("Unable to install and instantiate the chaincode: %v\n", err)
}
// Query the chaincode
/*response, err := fabricSdk.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 := fabricSdk.InvokeHello("chainHero")
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 = fabricSdk.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)
}*/
// Make the web application listening
app := &controllers.Application {
Fabric: fabricSdk,
}
web.Serve(app)
}