-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
53 lines (44 loc) · 1.33 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
/*
@Time : 2018/9/8 下午1:52
@Author : leixianting
@File : main
@Software: GoLand
*/
package main
import (
"./sced"
"github.com/hyperledger/fabric/core/chaincode/shim"
pb "github.com/hyperledger/fabric/protos/peer"
)
type scedSmartCode struct {
}
var LOGGER = shim.NewLogger("main")
var wcFunctions = map[string]func(shim.ChaincodeStubInterface, []string) pb.Response {
"updateData" : sced.UpdateData,
"getData" : sced.GetData,
"openData" : sced.OpenData,
}
//========================================================================
// 实例化chaincode时自动调用
//========================================================================
func (s *scedSmartCode) Init(stub shim.ChaincodeStubInterface) pb.Response {
return shim.Success(nil)
}
//========================================================================
// chaincode调用
//========================================================================
func (s *scedSmartCode) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
function, args := stub.GetFunctionAndParameters()
bcFunc := wcFunctions[function]
if bcFunc == nil {
LOGGER.Error("非法调用函数")
return shim.Error("非法调用函数")
}
return bcFunc(stub, args)
}
func main() {
err := shim.Start(new(scedSmartCode))
if err != nil {
LOGGER.Error("创建新合约失败: ", err)
}
}