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 authored and denyeart committed Jan 12, 2024
1 parent 6e6ae22 commit 1f662e7
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 1f662e7

Please sign in to comment.