Skip to content

Commit 6ced5b3

Browse files
committed
[FAB-5663] remove import from example04 and 05
Govendoring dependencies in these examples caused lot more trouble than was worth (such as goimports failures on vendored files). As the offending "util" import was just to use a simple function, just implemented the function in the samples and removed the import. Change-Id: Ie471cdcd307ae8d328134fe88037fa1afbd0e078 Signed-off-by: Srinivasan Muralidharan <srinivasan.muralidharan99@gmail.com>
1 parent 5e0727c commit 6ced5b3

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

examples/chaincode/go/chaincode_example04/chaincode_example04.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"fmt"
2121
"strconv"
2222

23-
"github.com/hyperledger/fabric/common/util"
2423
"github.com/hyperledger/fabric/core/chaincode/shim"
2524
pb "github.com/hyperledger/fabric/protos/peer"
2625
)
@@ -31,6 +30,14 @@ import (
3130
type SimpleChaincode struct {
3231
}
3332

33+
func toChaincodeArgs(args ...string) [][]byte {
34+
bargs := make([][]byte, len(args))
35+
for i, arg := range args {
36+
bargs[i] = []byte(arg)
37+
}
38+
return bargs
39+
}
40+
3441
// Init takes two arguments, a string and int. These are stored in the key/value pair in the state
3542
func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response {
3643
var event string // Indicates whether event has happened. Initially 0
@@ -84,7 +91,7 @@ func (t *SimpleChaincode) invoke(stub shim.ChaincodeStubInterface, args []string
8491
}
8592

8693
f := "invoke"
87-
invokeArgs := util.ToChaincodeArgs(f, "a", "b", "10")
94+
invokeArgs := toChaincodeArgs(f, "a", "b", "10")
8895
response := stub.InvokeChaincode(chainCodeToCall, invokeArgs, channelID)
8996
if response.Status != shim.OK {
9097
errStr := fmt.Sprintf("Failed to invoke chaincode. Got error: %s", string(response.Payload))
@@ -131,7 +138,7 @@ func (t *SimpleChaincode) query(stub shim.ChaincodeStubInterface, args []string)
131138
queryKey := args[2]
132139
channel := args[3]
133140
f := "query"
134-
invokeArgs := util.ToChaincodeArgs(f, queryKey)
141+
invokeArgs := toChaincodeArgs(f, queryKey)
135142
response := stub.InvokeChaincode(chainCodeToCall, invokeArgs, channel)
136143
if response.Status != shim.OK {
137144
errStr := fmt.Sprintf("Failed to invoke chaincode. Got error: %s", err.Error())

examples/chaincode/go/chaincode_example05/chaincode_example05.go

+12-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"fmt"
2121
"strconv"
2222

23-
"github.com/hyperledger/fabric/common/util"
2423
"github.com/hyperledger/fabric/core/chaincode/shim"
2524
pb "github.com/hyperledger/fabric/protos/peer"
2625
)
@@ -31,6 +30,14 @@ import (
3130
type SimpleChaincode struct {
3231
}
3332

33+
func toChaincodeArgs(args ...string) [][]byte {
34+
bargs := make([][]byte, len(args))
35+
for i, arg := range args {
36+
bargs[i] = []byte(arg)
37+
}
38+
return bargs
39+
}
40+
3441
// Init takes two arguments, a string and int. The string will be a key with
3542
// the int as a value.
3643
func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response {
@@ -80,7 +87,7 @@ func (t *SimpleChaincode) invoke(stub shim.ChaincodeStubInterface, args []string
8087

8188
// Query chaincode_example02
8289
f := "query"
83-
queryArgs := util.ToChaincodeArgs(f, "a")
90+
queryArgs := toChaincodeArgs(f, "a")
8491

8592
// if chaincode being invoked is on the same channel,
8693
// then channel defaults to the current channel and args[2] can be "".
@@ -100,7 +107,7 @@ func (t *SimpleChaincode) invoke(stub shim.ChaincodeStubInterface, args []string
100107
return shim.Error(errStr)
101108
}
102109

103-
queryArgs = util.ToChaincodeArgs(f, "b")
110+
queryArgs = toChaincodeArgs(f, "b")
104111
response = stub.InvokeChaincode(chaincodeName, queryArgs, channelName)
105112
if response.Status != shim.OK {
106113
errStr := fmt.Sprintf("Failed to query chaincode. Got error: %s", response.Payload)
@@ -147,7 +154,7 @@ func (t *SimpleChaincode) query(stub shim.ChaincodeStubInterface, args []string)
147154

148155
// Query chaincode_example02
149156
f := "query"
150-
queryArgs := util.ToChaincodeArgs(f, "a")
157+
queryArgs := toChaincodeArgs(f, "a")
151158

152159
// if chaincode being invoked is on the same channel,
153160
// then channel defaults to the current channel and args[2] can be "".
@@ -166,7 +173,7 @@ func (t *SimpleChaincode) query(stub shim.ChaincodeStubInterface, args []string)
166173
return shim.Error(errStr)
167174
}
168175

169-
queryArgs = util.ToChaincodeArgs(f, "b")
176+
queryArgs = toChaincodeArgs(f, "b")
170177
response = stub.InvokeChaincode(chaincodeName, queryArgs, channelName)
171178
if response.Status != shim.OK {
172179
errStr := fmt.Sprintf("Failed to query chaincode. Got error: %s", response.Payload)

0 commit comments

Comments
 (0)