Skip to content
This repository was archived by the owner on Apr 22, 2025. It is now read-only.

Commit 0f77959

Browse files
committed
FABJ-447 Update chaincode to not use Shim logger
Minor fix peer orderer Fix lifecycle can't have collections missing in updates. Change-Id: I4b38aff04412b583bc8e27f55a4e5c81bbc5012a Signed-off-by: rickr <cr22rc@gmail.com>
1 parent 519cc0a commit 0f77959

File tree

11 files changed

+104
-81
lines changed

11 files changed

+104
-81
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ and execute the following commands:
278278

279279
For v2.0 integration, cd to the `src/test/fixture/sdkintegration/e2e-2Orgs/v2.0` directory
280280
* configtxgen --configPath . -outputCreateChannelTx v2channel.tx -profile TwoOrgsChannel_v20 -channelID v2channel
281-
* configtxgen --configPath . -outputBlock orderer.block -profile TwoOrgsOrdererGenesis_v20 -channelID systemOrdererChannel
281+
* configtxgen --configPath . -outputBlock orderer.block -profile TwoOrgsOrdererGenesis_v20 -channelID systemordererchannel
282282

283283

284284
This should produce the following files in the same directory: orderer.block, foo.tx, and bar.tx

src/main/java/org/hyperledger/fabric/sdk/Orderer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ void setChannel(Channel channel) throws InvalidArgumentException {
141141

142142
this.channel = channel;
143143
this.channelName = channel.getName();
144+
toString = null; //recalculate
144145

145146
}
146147

src/main/java/org/hyperledger/fabric/sdk/Peer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ void setChannel(Channel channel) throws InvalidArgumentException {
185185

186186
this.channel = channel;
187187
this.channelName = channel.getName();
188+
toString = null; //recalculated
188189

189190
}
190191

src/test/fixture/sdkintegration/.env

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ ORG_HYPERLEDGER_FABRIC_SDKTEST_INTEGRATIONTESTS_CLIENT_AUTH_REQUIRED=false
4949
#IMAGE_TAG_FABRIC_CA=:1.4
5050

5151
##V 2.0
52+
# FAB_CONFIG_GEN_VERS=v2.0
53+
# V11_IDENTITIES_ALLOWREMOVE=--cfg.identities.allowremove
54+
# V11_AFFILIATIONS_ALLOWREMOVE=--cfg.affiliations.allowremove
55+
# IMAGE_TAG_FABRIC=:2.0
56+
# IMAGE_TAG_FABRIC_CA=:2.0
57+
58+
## Latest
5259
FAB_CONFIG_GEN_VERS=v2.0
5360
V11_IDENTITIES_ALLOWREMOVE=--cfg.identities.allowremove
5461
V11_AFFILIATIONS_ALLOWREMOVE=--cfg.affiliations.allowremove
55-
IMAGE_TAG_FABRIC=:2.0
56-
IMAGE_TAG_FABRIC_CA=:2.0
57-
58-
## Latest
59-
#FAB_CONFIG_GEN_VERS=v2.0
60-
#V11_IDENTITIES_ALLOWREMOVE=--cfg.identities.allowremove
61-
#V11_AFFILIATIONS_ALLOWREMOVE=--cfg.affiliations.allowremove
62-
#IMAGE_TAG_FABRIC=
63-
#IMAGE_TAG_FABRIC_CA=
62+
IMAGE_TAG_FABRIC=
63+
IMAGE_TAG_FABRIC_CA=

src/test/fixture/sdkintegration/gocc/sample1/src/github.com/example_cc/example_cc.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright IBM Corp. 2016 All Rights Reserved.
2+
Copyright IBM Corp. 2019 All Rights Reserved.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -18,21 +18,24 @@ package main
1818

1919
import (
2020
"fmt"
21+
"log"
22+
"os"
2123
"strconv"
2224

2325
"github.com/hyperledger/fabric/core/chaincode/shim"
2426
pb "github.com/hyperledger/fabric/protos/peer"
2527
)
2628

27-
var logger = shim.NewLogger("example_cc0")
29+
var Info = log.New(os.Stdout, "INFO: ", log.Ldate|log.Ltime|log.Lshortfile)
30+
var Error = log.New(os.Stderr, "ERROR: ", log.Ldate|log.Ltime|log.Lshortfile)
2831

2932
// SimpleChaincode example simple Chaincode implementation
3033
type SimpleChaincode struct {
3134
}
3235

3336
// Init initializes the chaincode state
3437
func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response {
35-
logger.Info("########### example_cc Init ###########")
38+
Info.Println("########### example_cc Init ###########")
3639

3740
_, args := stub.GetFunctionAndParameters()
3841
var A, B string // Entities
@@ -54,7 +57,7 @@ func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response {
5457
if err != nil {
5558
return shim.Error("Expecting integer value for asset holding")
5659
}
57-
logger.Infof("Aval = %d, Bval = %d\n", Aval, Bval)
60+
Info.Printf("Aval = %d, Bval = %d\n", Aval, Bval)
5861

5962
// Write the state to the ledger
6063
err = stub.PutState(A, []byte(strconv.Itoa(Aval)))
@@ -96,7 +99,7 @@ func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response {
9699

97100
// Invoke makes payment of X units from A to B
98101
func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
99-
logger.Info("########### example_cc Invoke ###########")
102+
Info.Println("########### example_cc Invoke ###########")
100103

101104
function, args := stub.GetFunctionAndParameters()
102105

@@ -115,7 +118,7 @@ func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
115118
return t.move(stub, args)
116119
}
117120

118-
logger.Errorf("Unknown action, check the first argument, must be one of 'delete', 'query', or 'move'. But got: %v", args[0])
121+
Error.Printf("Unknown action, check the first argument, must be one of 'delete', 'query', or 'move'. But got: %v", args[0])
119122
return shim.Error(fmt.Sprintf("Unknown action, check the first argument, must be one of 'delete', 'query', or 'move'. But got: %v", args[0]))
120123
}
121124

@@ -160,7 +163,7 @@ func (t *SimpleChaincode) move(stub shim.ChaincodeStubInterface, args []string)
160163
}
161164
Aval = Aval - X
162165
Bval = Bval + X
163-
logger.Infof("Aval = %d, Bval = %d\n", Aval, Bval)
166+
Info.Printf("Aval = %d, Bval = %d\n", Aval, Bval)
164167

165168
// Write the state back to the ledger
166169
err = stub.PutState(A, []byte(strconv.Itoa(Aval)))
@@ -192,8 +195,7 @@ func (t *SimpleChaincode) move(stub shim.ChaincodeStubInterface, args []string)
192195
return shim.Error(err.Error())
193196
}
194197

195-
196-
logger.Infof("Status = %d \n", vrc)
198+
Info.Printf("Status = %d \n", vrc)
197199

198200
return pb.Response{
199201
Status: int32(vrc),
@@ -246,13 +248,13 @@ func (t *SimpleChaincode) query(stub shim.ChaincodeStubInterface, args []string)
246248
}
247249

248250
jsonResp := "{\"Name\":\"" + A + "\",\"Amount\":\"" + string(Avalbytes) + "\"}"
249-
logger.Infof("Query Response:%s\n", jsonResp)
251+
Info.Printf("Query Response:%s\n", jsonResp)
250252
return shim.Success(Avalbytes)
251253
}
252254

253255
func main() {
254256
err := shim.Start(new(SimpleChaincode))
255257
if err != nil {
256-
logger.Errorf("Error starting Simple chaincode: %s", err)
258+
Error.Printf("Error starting Simple chaincode: %s", err)
257259
}
258260
}

src/test/fixture/sdkintegration/gocc/sample1NoInit/src/github.com/example_cc/example_cc.go

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright IBM Corp. 2016 All Rights Reserved.
2+
Copyright IBM Corp. 2019 All Rights Reserved.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -18,27 +18,29 @@ package main
1818

1919
import (
2020
"fmt"
21+
"log"
22+
"os"
2123
"strconv"
22-
2324
"github.com/hyperledger/fabric/core/chaincode/shim"
2425
pb "github.com/hyperledger/fabric/protos/peer"
2526
)
2627

27-
var logger = shim.NewLogger("example_cc0")
28+
var Info = log.New(os.Stdout, "INFO: ", log.Ldate|log.Ltime|log.Lshortfile)
29+
var Error = log.New(os.Stderr, "ERROR: ", log.Ldate|log.Ltime|log.Lshortfile)
2830

2931
// SimpleChaincode example simple Chaincode implementation
3032
type SimpleChaincode struct {
3133
}
3234

3335
// Init initializes the chaincode state
3436
func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response {
35-
logger.Info("########### example_cc Init ###########")
37+
Info.Println("########### example_cc Init ###########")
3638
panic("We shouldn't be here.")
3739
}
3840

3941
// this NOT the standard init function (trust me ) also note starts with lower case not available outside the pacakge.
4042
func (t *SimpleChaincode) ricksInit(stub shim.ChaincodeStubInterface, args []string) pb.Response {
41-
logger.Info("########### example_cc ricksInit ###########")
43+
Info.Println("########### example_cc ricksInit ###########")
4244

4345
var A, B string // Entities
4446
var Aval, Bval int // Asset holdings
@@ -59,7 +61,7 @@ func (t *SimpleChaincode) ricksInit(stub shim.ChaincodeStubInterface, args []str
5961
if err != nil {
6062
return shim.Error("Expecting integer value for asset holding")
6163
}
62-
logger.Infof("Aval = %d, Bval = %d\n", Aval, Bval)
64+
Info.Printf("Aval = %d, Bval = %d\n", Aval, Bval)
6365

6466
// Write the state to the ledger
6567
err = stub.PutState(A, []byte(strconv.Itoa(Aval)))
@@ -101,15 +103,15 @@ func (t *SimpleChaincode) ricksInit(stub shim.ChaincodeStubInterface, args []str
101103

102104
// Invoke makes payment of X units from A to B
103105
func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
104-
logger.Info("########### example_cc Invoke ###########")
106+
Info.Println("########### example_cc Invoke ###########")
105107

106108
function, args := stub.GetFunctionAndParameters()
107109

108110

109111
if function == "init" { // this is just a regular fcn that we need to dispatch here.
110-
// Does our own initialize
111-
return t.ricksInit(stub, args) // are own init.
112-
}
112+
// Does our own initialize
113+
return t.ricksInit(stub, args) // are own init.
114+
}
113115

114116
if function == "delete" {
115117
// Deletes an entity from its state
@@ -126,7 +128,7 @@ func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
126128
return t.move(stub, args)
127129
}
128130

129-
logger.Errorf("Unknown action, check the first argument, must be one of 'delete', 'query', or 'move'. But got: %v", args[0])
131+
Error.Printf("Unknown action, check the first argument, must be one of 'delete', 'query', or 'move'. But got: %v", args[0])
130132
return shim.Error(fmt.Sprintf("Unknown action, check the first argument, must be one of 'delete', 'query', or 'move'. But got: %v", args[0]))
131133
}
132134

@@ -171,7 +173,7 @@ func (t *SimpleChaincode) move(stub shim.ChaincodeStubInterface, args []string)
171173
}
172174
Aval = Aval - X
173175
Bval = Bval + X
174-
logger.Infof("Aval = %d, Bval = %d\n", Aval, Bval)
176+
Info.Printf("Aval = %d, Bval = %d\n", Aval, Bval)
175177

176178
// Write the state back to the ledger
177179
err = stub.PutState(A, []byte(strconv.Itoa(Aval)))
@@ -204,7 +206,7 @@ func (t *SimpleChaincode) move(stub shim.ChaincodeStubInterface, args []string)
204206
}
205207

206208

207-
logger.Infof("Status = %d \n", vrc)
209+
Info.Printf("Status = %d \n", vrc)
208210

209211
return pb.Response{
210212
Status: int32(vrc),
@@ -257,13 +259,13 @@ func (t *SimpleChaincode) query(stub shim.ChaincodeStubInterface, args []string)
257259
}
258260

259261
jsonResp := "{\"Name\":\"" + A + "\",\"Amount\":\"" + string(Avalbytes) + "\"}"
260-
logger.Infof("Query Response:%s\n", jsonResp)
262+
Info.Printf("Query Response:%s\n", jsonResp)
261263
return shim.Success(Avalbytes)
262264
}
263265

264266
func main() {
265267
err := shim.Start(new(SimpleChaincode))
266268
if err != nil {
267-
logger.Errorf("Error starting Simple chaincode: %s", err)
269+
Error.Printf("Error starting Simple chaincode: %s", err)
268270
}
269271
}

src/test/fixture/sdkintegration/gocc/sampleIdemix/src/github.com/example_cc/example_cc.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ package main
1818

1919
import (
2020
"fmt"
21+
"log"
22+
"os"
2123
"strconv"
2224
"strings"
2325

@@ -26,15 +28,16 @@ import (
2628
pb "github.com/hyperledger/fabric/protos/peer"
2729
)
2830

29-
var logger = shim.NewLogger("example_cc0")
31+
var Info = log.New(os.Stdout, "INFO: ", log.Ldate|log.Ltime|log.Lshortfile)
32+
var Error = log.New(os.Stderr, "ERROR: ", log.Ldate|log.Ltime|log.Lshortfile)
3033

3134
// SimpleChaincode example simple Chaincode implementation
3235
type SimpleChaincode struct {
3336
}
3437

3538
// Init initializes the chaincode state
3639
func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response {
37-
logger.Info("########### example_cc Init ###########")
40+
Info.Println("########### example_cc Init ###########")
3841

3942
_, args := stub.GetFunctionAndParameters()
4043
var A, B string // Entities
@@ -56,7 +59,7 @@ func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response {
5659
if err != nil {
5760
return shim.Error("Expecting integer value for asset holding")
5861
}
59-
logger.Infof("Aval = %d, Bval = %d\n", Aval, Bval)
62+
Info.Printf("Aval = %d, Bval = %d\n", Aval, Bval)
6063

6164
// Write the state to the ledger
6265
err = stub.PutState(A, []byte(strconv.Itoa(Aval)))
@@ -80,7 +83,7 @@ func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response {
8083

8184
// Invoke makes payment of X units from A to B
8285
func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
83-
logger.Info("########### example_cc Invoke ###########")
86+
Info.Println("########### example_cc Invoke ###########")
8487

8588
function, args := stub.GetFunctionAndParameters()
8689

@@ -121,7 +124,7 @@ func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
121124
return t.move(stub, args)
122125
}
123126

124-
logger.Errorf("Unknown action, check the first argument, must be one of 'delete', 'query', or 'move'. But got: %v", args[0])
127+
Error.Printf("Unknown action, check the first argument, must be one of 'delete', 'query', or 'move'. But got: %v", args[0])
125128
return shim.Error(fmt.Sprintf("Unknown action, check the first argument, must be one of 'delete', 'query', or 'move'. But got: %v", args[0]))
126129
}
127130

@@ -166,7 +169,7 @@ func (t *SimpleChaincode) move(stub shim.ChaincodeStubInterface, args []string)
166169
}
167170
Aval = Aval - X
168171
Bval = Bval + X
169-
logger.Infof("Aval = %d, Bval = %d\n", Aval, Bval)
172+
Info.Printf("Aval = %d, Bval = %d\n", Aval, Bval)
170173

171174
// Write the state back to the ledger
172175
err = stub.PutState(A, []byte(strconv.Itoa(Aval)))
@@ -199,7 +202,7 @@ func (t *SimpleChaincode) move(stub shim.ChaincodeStubInterface, args []string)
199202
}
200203

201204

202-
logger.Infof("Status = %d \n", vrc)
205+
Info.Printf("Status = %d \n", vrc)
203206

204207
return pb.Response{
205208
Status: int32(vrc),
@@ -252,13 +255,13 @@ func (t *SimpleChaincode) query(stub shim.ChaincodeStubInterface, args []string)
252255
}
253256

254257
jsonResp := "{\"Name\":\"" + A + "\",\"Amount\":\"" + string(Avalbytes) + "\"}"
255-
logger.Infof("Query Response:%s\n", jsonResp)
258+
Info.Printf("Query Response:%s\n", jsonResp)
256259
return shim.Success(Avalbytes)
257260
}
258261

259262
func main() {
260263
err := shim.Start(new(SimpleChaincode))
261264
if err != nil {
262-
logger.Errorf("Error starting Simple chaincode: %s", err)
265+
Error.Printf("Error starting Simple chaincode: %s", err)
263266
}
264267
}

0 commit comments

Comments
 (0)