-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
94 lines (69 loc) · 2.27 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
"fmt"
"os"
"time"
"github.com/GamblAR/atomic_elements"
"github.com/pkg/errors"
)
var (
gameDB = make(atomic_elements.GameDB, 100)
)
func main() {
game_handler := atomic_elements.Handeler{
ChannelID: "townchannel",
//OrgInfo
OrgAdmins: map[string]string{
"Org1": "Admin",
"Org2": "Admin",
},
Organizations: []string{"Org1", "Org2"},
ConfigFile: "config.yaml",
ChainCodeID: "account",
ChaincodeGoPath: os.Getenv("GOPATH"),
ChaincodePath: "github.com/GamblAR/chaincode/",
}
try := 1
fmt.Println("-------Initializing the game handler.--------")
err := game_handler.Initializer()
if err != nil {
fmt.Println(errors.Wrap(err, "initialization of game handler failed"))
} else {
fmt.Println("-------Successful initializing the game handler.--------")
}
fmt.Println("------ Creating And Join Channel For each Organizations ----------")
err = game_handler.CreateAndJoinChannel()
if err != nil {
fmt.Println(errors.Wrap(err, "CreateAndJoinChannel game handler failed"))
} else {
fmt.Println("------- Completed Chaincode Installation and Instantiation --------")
}
time.Sleep(30 * time.Second)
fmt.Println("------- Invoking the chaincode to Create Asset and Set Value --------")
txID, err := game_handler.SetAsset([]string{"Acc1", "1000"})
if err != nil {
fmt.Println(errors.Wrap(err, "Account SetAsset game handler failed"))
} else {
fmt.Println("Setting Value TxID: ", txID)
fmt.Println("-------Successful SetAsset Account--------")
}
fmt.Println("------- Query the chaincode to Get Value of Asset --------")
txID, err = game_handler.QueryAsset("Acc1")
if err != nil {
fmt.Println(errors.Wrap(err, "Account QueryAsset game handler failed"))
} else {
fmt.Println("Query Value : ", txID)
fmt.Println("-------Successful QueryAsset Account--------")
}
gameDB.AddBet("Game1", "Acc1", "100", "Opt1", try)
fmt.Println("-------Made a bet on Game1, By Acc1 of 100 on Opt1 --------")
try++
gameDB.EndBetting("Game1")
fmt.Println("-------Betting ended for Game 1 --------")
err = game_handler.WriteBetsToLedger(gameDB, "Game1")
if err != nil {
fmt.Println(errors.Wrap(err, "Writing bets to blockchain failed"))
} else {
fmt.Println("-------Successfully written bets to blockchain--------")
}
}