-
Notifications
You must be signed in to change notification settings - Fork 33
/
main.go
executable file
·114 lines (100 loc) · 2.56 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package main
import (
"encoding/json"
"fmt"
"education/sdkInit"
"education/service"
"education/web"
"education/web/controller"
"os"
)
const (
cc_name = "simplecc"
cc_version = "1.0.0"
)
func main() {
// init orgs information
orgs := []*sdkInit.OrgInfo{
{
OrgAdminUser: "Admin",
OrgName: "Org1",
OrgMspId: "Org1MSP",
OrgUser: "User1",
OrgPeerNum: 1,
OrgAnchorFile: os.Getenv("GOPATH") + "/src/education/fixtures/channel-artifacts/Org1MSPanchors.tx",
},
}
// init sdk env info
info := sdkInit.SdkEnvInfo{
ChannelID: "mychannel",
ChannelConfig: os.Getenv("GOPATH") + "/src/education/fixtures/channel-artifacts/channel.tx",
Orgs: orgs,
OrdererAdminUser: "Admin",
OrdererOrgName: "OrdererOrg",
OrdererEndpoint: "orderer.example.com",
ChaincodeID: cc_name,
ChaincodePath: os.Getenv("GOPATH")+"/src/education/chaincode/",
ChaincodeVersion: cc_version,
}
// sdk setup
sdk, err := sdkInit.Setup("config.yaml", &info)
if err != nil {
fmt.Println(">> SDK setup error:", err)
os.Exit(-1)
}
// create channel and join
if err := sdkInit.CreateAndJoinChannel(&info); err != nil {
fmt.Println(">> Create channel and join error:", err)
os.Exit(-1)
}
// create chaincode lifecycle
if err := sdkInit.CreateCCLifecycle(&info, 1, false, sdk); err != nil {
fmt.Println(">> create chaincode lifecycle error: %v", err)
os.Exit(-1)
}
// invoke chaincode set status
fmt.Println(">> 通过链码外部服务设置链码状态......")
edu := service.Education{
Name: "张三",
Gender: "男",
Nation: "汉",
EntityID: "101",
Place: "北京",
BirthDay: "1991年01月01日",
EnrollDate: "2009年9月",
GraduationDate: "2013年7月",
SchoolName: "中国政法大学",
Major: "社会学",
QuaType: "普通",
Length: "四年",
Mode: "普通全日制",
Level: "本科",
Graduation: "毕业",
CertNo: "111",
Photo: "/static/photo/11.png",
}
serviceSetup, err := service.InitService(info.ChaincodeID, info.ChannelID, info.Orgs[0], sdk)
if err!=nil{
fmt.Println()
os.Exit(-1)
}
msg, err := serviceSetup.SaveEdu(edu)
if err != nil {
fmt.Println(err.Error())
}else {
fmt.Println("信息发布成功, 交易编号为: " + msg)
}
result, err := serviceSetup.FindEduInfoByEntityID("101")
if err != nil {
fmt.Println(err.Error())
} else {
var edu service.Education
json.Unmarshal(result, &edu)
fmt.Println("根据身份证号码查询信息成功:")
fmt.Println(edu)
}
app := controller.Application{
Setup: serviceSetup,
}
web.WebStart(app)
}