Skip to content

Commit f922b70

Browse files
committed
[FAB-8705] Remove samplesyscc package
The sample system chaincode was used as part of a system chaincode test so moving it closer to where it's used. That said, the test that uses it has been skipped for a long time and it no longer passes when enabled. Change-Id: Ib94344dfb4029a7a53aaf4c90f54d8e37463eac0 Signed-off-by: Matthew Sykes <sykesmat@us.ibm.com>
1 parent 7af4f2e commit f922b70

File tree

3 files changed

+62
-356
lines changed

3 files changed

+62
-356
lines changed

core/chaincode/systemchaincode_test.go

+62-2
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ import (
2424

2525
"github.com/hyperledger/fabric/common/util"
2626
"github.com/hyperledger/fabric/core/chaincode/accesscontrol"
27+
"github.com/hyperledger/fabric/core/chaincode/shim"
2728
"github.com/hyperledger/fabric/core/common/ccprovider"
2829
"github.com/hyperledger/fabric/core/peer"
2930
"github.com/hyperledger/fabric/core/scc"
30-
"github.com/hyperledger/fabric/core/scc/samplesyscc"
3131
pb "github.com/hyperledger/fabric/protos/peer"
3232
"github.com/spf13/viper"
3333
"golang.org/x/net/context"
@@ -44,6 +44,66 @@ func (osyscc *oldSysCCInfo) reset() {
4444
viper.Set("chaincode.system", osyscc.origSysCCWhitelist)
4545
}
4646

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+
47107
func initSysCCTests() (*oldSysCCInfo, net.Listener, error) {
48108
var opts []grpc.ServerOption
49109
grpcServer := grpc.NewServer(opts...)
@@ -81,7 +141,7 @@ func initSysCCTests() (*oldSysCCInfo, net.Listener, error) {
81141
Name: "sample_syscc",
82142
Path: "github.com/hyperledger/fabric/core/scc/samplesyscc",
83143
InitArgs: [][]byte{},
84-
Chaincode: &samplesyscc.SampleSysCC{},
144+
Chaincode: &SampleSysCC{},
85145
},
86146
}
87147

core/scc/samplesyscc/samplesyscc.go

-91
This file was deleted.

0 commit comments

Comments
 (0)