-
Notifications
You must be signed in to change notification settings - Fork 3
/
hstx.go
128 lines (114 loc) · 3.95 KB
/
hstx.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package main
import (
"fmt"
. "github.com/Akachain/akc-go-sdk/common"
ctl "github.com/Akachain/akc-go-sdk/hstx/controllers"
"github.com/hyperledger/fabric/core/chaincode/shim"
pb "github.com/hyperledger/fabric/protos/peer"
)
// Chaincode implementation
type Chaincode struct {
}
var controller_admin ctl.Admin
var controller_proposal ctl.Proposal
var controller_quorum ctl.Quorum
var controller_commit ctl.Commit
/*
* The Init method is called when the Chain code" is instantiated by the blockchain network
*/
func (s *Chaincode) Init(stub shim.ChaincodeStubInterface) pb.Response {
// The invokeFunction returns
// Admin1 := "Admin1"
// pubKey1, _ := ioutil.ReadFile("./sample/pk1.pem")
// pk1 := base64.StdEncoding.EncodeToString(pubKey1)
// Admin2 := "Admin2"
// pubKey2, _ := ioutil.ReadFile("./sample/pk2.pem")
// pk2 := base64.StdEncoding.EncodeToString(pubKey2)
// Admin3 := "Admin3"
// pubKey3, _ := ioutil.ReadFile("./sample/pk3.pem")
// pk3 := base64.StdEncoding.EncodeToString(pubKey3)
// rs1 := controller_admin.CreateAdmin(stub, []string{Admin1, pk1})
// rs2 := controller_admin.CreateAdmin(stub, []string{Admin2, pk2})
// rs3 := controller_admin.CreateAdmin(stub, []string{Admin3, pk3})
// if rs1.Status != shim.OK || rs2.Status != shim.OK || rs3.Status != shim.OK {
// return shim.Error("Init chaincode with 3 admin fail")
// }
return shim.Success(nil)
}
/*
* The Invoke method is called as a result of an application request to run the chain code
* The calling application program has also specified the particular smart contract function to be called, with arguments
*/
func (t *Chaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
Logger.Info("########### Hstx Invoke ###########")
// Retrieve the requested Smart Contract function and arguments
function, args := stub.GetFunctionAndParameters()
switch function {
//CreateAdmin
case "CreateAdmin":
return controller_admin.CreateAdmin(stub, args)
//UpdateAdmin -> For testing
case "UpdateAdmin":
return controller_admin.UpdateAdmin(stub, args)
//CreateProposal
case "CreateProposal":
return controller_proposal.CreateProposal(stub, args)
//CreateQuorum
case "CreateQuorum":
return controller_quorum.CreateQuorum(stub, args)
//CreateReject
case "CreateReject":
return controller_quorum.CreateReject(stub, args)
//CreateCommit
case "CreateCommit":
return controller_commit.CreateCommit(stub, args)
default:
return t.Query(stub)
}
}
// Query callback representing the query of a chaincode
func (t *Chaincode) Query(stub shim.ChaincodeStubInterface) pb.Response {
Logger.Info("########### Hstx Query ###########")
function, args := stub.GetFunctionAndParameters()
switch function {
// GetAdminByID
case "GetAdminByID":
return controller_admin.GetAdminByID(stub, args)
// GetAllAdmin
case "GetAllAdmin":
return controller_admin.GetAllAdmin(stub)
// GetProposalByID
case "GetProposalByID":
return controller_proposal.GetProposalByID(stub, args)
// GetProposalNotSign
case "GetProposalNotSign":
return controller_proposal.GetProposalNotSign(stub, args)
// GetAllProposal
case "GetAllProposal":
return controller_proposal.GetAllProposal(stub)
// GetQuorumByID
case "GetQuorumByID":
return controller_quorum.GetQuorumByID(stub, args)
// GetQuorumByProposalID
case "GetQuorumByProposalID":
return controller_quorum.GetQuorumByProposalID(stub, args)
// GetAllQuorum
case "GetAllQuorum":
return controller_quorum.GetAllQuorum(stub)
// GetCommitByID
case "GetCommitByID":
return controller_commit.GetCommitByID(stub, args)
// GetAllCommit
case "GetAllCommit":
return controller_commit.GetAllCommit(stub)
}
return shim.Error(fmt.Sprintf("[Hstx Chaincode] Invoke and Query not find function " + function))
}
// The main function is only relevant in unit test mode. Only included here for completeness.
func main() {
// Create a new Chain code
err := shim.Start(new(Chaincode))
if err != nil {
fmt.Printf("Error creating new Chain code: %s", err)
}
}