@@ -24,10 +24,10 @@ import (
24
24
25
25
"github.com/hyperledger/fabric/common/util"
26
26
"github.com/hyperledger/fabric/core/chaincode/accesscontrol"
27
+ "github.com/hyperledger/fabric/core/chaincode/shim"
27
28
"github.com/hyperledger/fabric/core/common/ccprovider"
28
29
"github.com/hyperledger/fabric/core/peer"
29
30
"github.com/hyperledger/fabric/core/scc"
30
- "github.com/hyperledger/fabric/core/scc/samplesyscc"
31
31
pb "github.com/hyperledger/fabric/protos/peer"
32
32
"github.com/spf13/viper"
33
33
"golang.org/x/net/context"
@@ -44,6 +44,66 @@ func (osyscc *oldSysCCInfo) reset() {
44
44
viper .Set ("chaincode.system" , osyscc .origSysCCWhitelist )
45
45
}
46
46
47
+ type SampleSysCC struct {}
48
+
49
+ func (t * SampleSysCC ) Init (stub shim.ChaincodeStubInterface ) pb.Response {
50
+ return shim .Success (nil )
51
+ }
52
+
53
+ func (t * SampleSysCC ) Invoke (stub shim.ChaincodeStubInterface ) pb.Response {
54
+ f , args := stub .GetFunctionAndParameters ()
55
+
56
+ switch f {
57
+ case "putval" :
58
+ if len (args ) != 2 {
59
+ return shim .Error ("need 2 args (key and a value)" )
60
+ }
61
+
62
+ // Initialize the chaincode
63
+ key := args [0 ]
64
+ val := args [1 ]
65
+
66
+ _ , err := stub .GetState (key )
67
+ if err != nil {
68
+ jsonResp := "{\" Error\" :\" Failed to get val for " + key + "\" }"
69
+ return shim .Error (jsonResp )
70
+ }
71
+
72
+ // Write the state to the ledger
73
+ err = stub .PutState (key , []byte (val ))
74
+ if err != nil {
75
+ return shim .Error (err .Error ())
76
+ }
77
+
78
+ return shim .Success (nil )
79
+ case "getval" :
80
+ var err error
81
+
82
+ if len (args ) != 1 {
83
+ return shim .Error ("Incorrect number of arguments. Expecting key to query" )
84
+ }
85
+
86
+ key := args [0 ]
87
+
88
+ // Get the state from the ledger
89
+ valbytes , err := stub .GetState (key )
90
+ if err != nil {
91
+ jsonResp := "{\" Error\" :\" Failed to get state for " + key + "\" }"
92
+ return shim .Error (jsonResp )
93
+ }
94
+
95
+ if valbytes == nil {
96
+ jsonResp := "{\" Error\" :\" Nil val for " + key + "\" }"
97
+ return shim .Error (jsonResp )
98
+ }
99
+
100
+ return shim .Success (valbytes )
101
+ default :
102
+ jsonResp := "{\" Error\" :\" Unknown function " + f + "\" }"
103
+ return shim .Error (jsonResp )
104
+ }
105
+ }
106
+
47
107
func initSysCCTests () (* oldSysCCInfo , net.Listener , error ) {
48
108
var opts []grpc.ServerOption
49
109
grpcServer := grpc .NewServer (opts ... )
@@ -81,7 +141,7 @@ func initSysCCTests() (*oldSysCCInfo, net.Listener, error) {
81
141
Name : "sample_syscc" ,
82
142
Path : "github.com/hyperledger/fabric/core/scc/samplesyscc" ,
83
143
InitArgs : [][]byte {},
84
- Chaincode : & samplesyscc. SampleSysCC {},
144
+ Chaincode : & SampleSysCC {},
85
145
},
86
146
}
87
147
0 commit comments