Skip to content

Commit

Permalink
Remove unused variables and functions
Browse files Browse the repository at this point in the history
Signed-off-by: Artem Barger <artem@bargr.net>
  • Loading branch information
C0rWin committed Jan 3, 2024
1 parent 64fefb4 commit ee2c565
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 84 deletions.
46 changes: 17 additions & 29 deletions internal/peer/chaincode/chaincode.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/hyperledger/fabric/bccsp"
"github.com/hyperledger/fabric/common/flogging"
"github.com/hyperledger/fabric/internal/peer/common"
"github.com/hyperledger/fabric/internal/peer/packaging"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
Expand All @@ -25,12 +24,6 @@ const (

var logger = flogging.MustGetLogger("chaincodeCmd")

// XXX This is a terrible singleton hack, however
// it simply making a latent dependency explicit.
// It should be removed along with the other package
// scoped variables
var platformRegistry = packaging.NewRegistry(packaging.SupportedPlatforms...)

func addFlags(cmd *cobra.Command) {
common.AddOrdererFlags(cmd)
flags := cmd.PersistentFlags()
Expand All @@ -49,26 +42,23 @@ func Cmd(cf *ChaincodeCmdFactory, cryptoProvider bccsp.BCCSP) *cobra.Command {

// Chaincode-related variables.
var (
chaincodeLang string
chaincodeCtorJSON string
chaincodePath string
chaincodeName string
chaincodeUsr string // Not used
chaincodeQueryRaw bool
chaincodeQueryHex bool
channelID string
chaincodeVersion string
policy string
policyMarshalled []byte
transient string
isInit bool
collectionsConfigFile string
collectionConfigBytes []byte
peerAddresses []string
tlsRootCertFiles []string
connectionProfile string
waitForEvent bool
waitForEventTimeout time.Duration
chaincodeLang string
chaincodeCtorJSON string
chaincodePath string
chaincodeName string
chaincodeUsr string // Not used
chaincodeQueryRaw bool
chaincodeQueryHex bool
channelID string
chaincodeVersion string
policy string
transient string
isInit bool
peerAddresses []string
tlsRootCertFiles []string
connectionProfile string
waitForEvent bool
waitForEventTimeout time.Duration
)

var chaincodeCmd = &cobra.Command{
Expand Down Expand Up @@ -109,8 +99,6 @@ func resetFlags() {
"The endorsement policy associated to this chaincode")
flags.BoolVarP(&isInit, "isInit", "I", false,
"Is this invocation for init (useful for supporting legacy chaincodes in the new lifecycle)")
flags.StringVar(&collectionsConfigFile, "collections-config", common.UndefinedParamValue,
"The fully qualified path to the collection JSON file including the file name")
flags.StringArrayVarP(&peerAddresses, "peerAddresses", "", []string{common.UndefinedParamValue},
"The addresses of the peers to connect to")
flags.StringArrayVarP(&tlsRootCertFiles, "tlsRootCertFiles", "", []string{common.UndefinedParamValue},
Expand Down
36 changes: 0 additions & 36 deletions internal/peer/chaincode/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,42 +32,6 @@ import (
"github.com/spf13/viper"
)

// checkSpec to see if chaincode resides within current package capture for language.
func checkSpec(spec *pb.ChaincodeSpec) error {
// Don't allow nil value
if spec == nil {
return errors.New("expected chaincode specification, nil received")
}
if spec.ChaincodeId == nil {
return errors.New("expected chaincode ID, nil received")
}

return platformRegistry.ValidateSpec(spec.Type.String(), spec.ChaincodeId.Path)
}

// getChaincodeDeploymentSpec get chaincode deployment spec given the chaincode spec
func getChaincodeDeploymentSpec(spec *pb.ChaincodeSpec, crtPkg bool) (*pb.ChaincodeDeploymentSpec, error) {
var codePackageBytes []byte
if crtPkg {
var err error
if err = checkSpec(spec); err != nil {
return nil, err
}

codePackageBytes, err = platformRegistry.GetDeploymentPayload(spec.Type.String(), spec.ChaincodeId.Path)
if err != nil {
return nil, errors.WithMessage(err, "error getting chaincode package bytes")
}
chaincodePath, err := platformRegistry.NormalizePath(spec.Type.String(), spec.ChaincodeId.Path)
if err != nil {
return nil, errors.WithMessage(err, "failed to normalize chaincode path")
}
spec.ChaincodeId.Path = chaincodePath
}

return &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec, CodePackage: codePackageBytes}, nil
}

// getChaincodeSpec get chaincode spec from the cli cmd parameters
func getChaincodeSpec(cmd *cobra.Command) (*pb.ChaincodeSpec, error) {
spec := &pb.ChaincodeSpec{}
Expand Down
19 changes: 0 additions & 19 deletions internal/peer/chaincode/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,13 @@ import (
"github.com/hyperledger/fabric/core/config/configtest"
"github.com/hyperledger/fabric/internal/peer/chaincode/mock"
"github.com/hyperledger/fabric/internal/peer/common"
"github.com/hyperledger/fabric/internal/pkg/identity"
msptesttools "github.com/hyperledger/fabric/msp/mgmt/testtools"
. "github.com/onsi/gomega"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/stretchr/testify/require"
)

//go:generate counterfeiter -o mock/signer_serializer.go --fake-name SignerSerializer . signerSerializer

type signerSerializer interface {
identity.SignerSerializer
}

//go:generate counterfeiter -o mock/deliver.go --fake-name Deliver . deliver

type deliver interface {
pb.Deliver_DeliverClient
}

//go:generate counterfeiter -o mock/deliver_client.go --fake-name PeerDeliverClient . peerDeliverClient

type peerDeliverClient interface {
pb.DeliverClient
}

func TestCheckChaincodeCmdParamsWithNewCallingSchema(t *testing.T) {
chaincodeCtorJSON = `{ "Args":["func", "param"] }`
chaincodePath = "some/path"
Expand Down

0 comments on commit ee2c565

Please sign in to comment.