Skip to content

Commit

Permalink
FABJ-447 Update chaincode to not use Shim logger
Browse files Browse the repository at this point in the history
Minor fix peer orderer
Fix lifecycle can't have collections missing in updates.

Change-Id: I4b38aff04412b583bc8e27f55a4e5c81bbc5012a
Signed-off-by: rickr <cr22rc@gmail.com>
  • Loading branch information
cr22rc committed Jun 6, 2019
1 parent 519cc0a commit 0f77959
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 81 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ and execute the following commands:

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


This should produce the following files in the same directory: orderer.block, foo.tx, and bar.tx
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/hyperledger/fabric/sdk/Orderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ void setChannel(Channel channel) throws InvalidArgumentException {

this.channel = channel;
this.channelName = channel.getName();
toString = null; //recalculate

}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/hyperledger/fabric/sdk/Peer.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ void setChannel(Channel channel) throws InvalidArgumentException {

this.channel = channel;
this.channelName = channel.getName();
toString = null; //recalculated

}

Expand Down
18 changes: 9 additions & 9 deletions src/test/fixture/sdkintegration/.env
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ ORG_HYPERLEDGER_FABRIC_SDKTEST_INTEGRATIONTESTS_CLIENT_AUTH_REQUIRED=false
#IMAGE_TAG_FABRIC_CA=:1.4

##V 2.0
# FAB_CONFIG_GEN_VERS=v2.0
# V11_IDENTITIES_ALLOWREMOVE=--cfg.identities.allowremove
# V11_AFFILIATIONS_ALLOWREMOVE=--cfg.affiliations.allowremove
# IMAGE_TAG_FABRIC=:2.0
# IMAGE_TAG_FABRIC_CA=:2.0

## Latest
FAB_CONFIG_GEN_VERS=v2.0
V11_IDENTITIES_ALLOWREMOVE=--cfg.identities.allowremove
V11_AFFILIATIONS_ALLOWREMOVE=--cfg.affiliations.allowremove
IMAGE_TAG_FABRIC=:2.0
IMAGE_TAG_FABRIC_CA=:2.0

## Latest
#FAB_CONFIG_GEN_VERS=v2.0
#V11_IDENTITIES_ALLOWREMOVE=--cfg.identities.allowremove
#V11_AFFILIATIONS_ALLOWREMOVE=--cfg.affiliations.allowremove
#IMAGE_TAG_FABRIC=
#IMAGE_TAG_FABRIC_CA=
IMAGE_TAG_FABRIC=
IMAGE_TAG_FABRIC_CA=
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright IBM Corp. 2016 All Rights Reserved.
Copyright IBM Corp. 2019 All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -18,21 +18,24 @@ package main

import (
"fmt"
"log"
"os"
"strconv"

"github.com/hyperledger/fabric/core/chaincode/shim"
pb "github.com/hyperledger/fabric/protos/peer"
)

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

// SimpleChaincode example simple Chaincode implementation
type SimpleChaincode struct {
}

// Init initializes the chaincode state
func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response {
logger.Info("########### example_cc Init ###########")
Info.Println("########### example_cc Init ###########")

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

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

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

function, args := stub.GetFunctionAndParameters()

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

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

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

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


logger.Infof("Status = %d \n", vrc)
Info.Printf("Status = %d \n", vrc)

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

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

func main() {
err := shim.Start(new(SimpleChaincode))
if err != nil {
logger.Errorf("Error starting Simple chaincode: %s", err)
Error.Printf("Error starting Simple chaincode: %s", err)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright IBM Corp. 2016 All Rights Reserved.
Copyright IBM Corp. 2019 All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -18,27 +18,29 @@ package main

import (
"fmt"
"log"
"os"
"strconv"

"github.com/hyperledger/fabric/core/chaincode/shim"
pb "github.com/hyperledger/fabric/protos/peer"
)

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

// SimpleChaincode example simple Chaincode implementation
type SimpleChaincode struct {
}

// Init initializes the chaincode state
func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response {
logger.Info("########### example_cc Init ###########")
Info.Println("########### example_cc Init ###########")
panic("We shouldn't be here.")
}

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

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

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

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

function, args := stub.GetFunctionAndParameters()


if function == "init" { // this is just a regular fcn that we need to dispatch here.
// Does our own initialize
return t.ricksInit(stub, args) // are own init.
}
// Does our own initialize
return t.ricksInit(stub, args) // are own init.
}

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

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

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

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


logger.Infof("Status = %d \n", vrc)
Info.Printf("Status = %d \n", vrc)

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

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

func main() {
err := shim.Start(new(SimpleChaincode))
if err != nil {
logger.Errorf("Error starting Simple chaincode: %s", err)
Error.Printf("Error starting Simple chaincode: %s", err)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package main

import (
"fmt"
"log"
"os"
"strconv"
"strings"

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

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

// SimpleChaincode example simple Chaincode implementation
type SimpleChaincode struct {
}

// Init initializes the chaincode state
func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response {
logger.Info("########### example_cc Init ###########")
Info.Println("########### example_cc Init ###########")

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

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

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

function, args := stub.GetFunctionAndParameters()

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

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

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

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


logger.Infof("Status = %d \n", vrc)
Info.Printf("Status = %d \n", vrc)

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

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

func main() {
err := shim.Start(new(SimpleChaincode))
if err != nil {
logger.Errorf("Error starting Simple chaincode: %s", err)
Error.Printf("Error starting Simple chaincode: %s", err)
}
}
Loading

0 comments on commit 0f77959

Please sign in to comment.