diff --git a/Makefile b/Makefile index 00be6bda199..c04bf8d2459 100644 --- a/Makefile +++ b/Makefile @@ -86,7 +86,7 @@ GO_TAGS ?= RELEASE_EXES = orderer $(TOOLS_EXES) RELEASE_IMAGES = baseos ccenv orderer peer RELEASE_PLATFORMS = darwin-amd64 darwin-arm64 linux-amd64 linux-arm64 windows-amd64 -TOOLS_EXES = configtxgen configtxlator cryptogen discover ledgerutil osnadmin peer +TOOLS_EXES = configtxgen configtxlator cryptogen discover ledgerutil osnadmin peer peercli pkgmap.configtxgen := $(PKGNAME)/cmd/configtxgen pkgmap.configtxlator := $(PKGNAME)/cmd/configtxlator @@ -96,6 +96,7 @@ pkgmap.ledgerutil := $(PKGNAME)/cmd/ledgerutil pkgmap.orderer := $(PKGNAME)/cmd/orderer pkgmap.osnadmin := $(PKGNAME)/cmd/osnadmin pkgmap.peer := $(PKGNAME)/cmd/peer +pkgmap.peercli := $(PKGNAME)/cmd/peercli .DEFAULT_GOAL := all diff --git a/RELEASING.md b/RELEASING.md index ef43e87f1f8..c3ae5e32291 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -67,9 +67,9 @@ export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.e export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp export CORE_PEER_ADDRESS=localhost:7051 -peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n basicgo --peerAddresses localhost:7051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"function":"InitLedger","Args":[]}' +peercli chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n basicgo --peerAddresses localhost:7051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"function":"InitLedger","Args":[]}' -peer chaincode query -C mychannel -n basicgo -c '{"Args":["GetAllAssets"]}' +peercli chaincode query -C mychannel -n basicgo -c '{"Args":["GetAllAssets"]}' docker logs peer0.org1.example.com diff --git a/cmd/peer/main.go b/cmd/peer/main.go index da76703cdc6..5adf35e2b0f 100644 --- a/cmd/peer/main.go +++ b/cmd/peer/main.go @@ -42,11 +42,14 @@ func main() { mainCmd.AddCommand(version.Cmd()) mainCmd.AddCommand(node.Cmd()) - mainCmd.AddCommand(chaincode.Cmd(nil, cryptoProvider)) - mainCmd.AddCommand(channel.Cmd(nil)) - mainCmd.AddCommand(lifecycle.Cmd(cryptoProvider)) - mainCmd.AddCommand(snapshot.Cmd(cryptoProvider)) - + // Deprecated: use peercli + mainCmd.AddCommand(chaincode.Cmd(nil, cryptoProvider, false)) + // Deprecated: use peercli or osnadmin + mainCmd.AddCommand(channel.Cmd(nil, false)) + // Deprecated: use peercli + mainCmd.AddCommand(lifecycle.Cmd(cryptoProvider, false)) + // Deprecated: use peercli + mainCmd.AddCommand(snapshot.Cmd(cryptoProvider, false)) // On failure Cobra prints the usage message and error string, so we only // need to exit with a non-0 status if mainCmd.Execute() != nil { diff --git a/cmd/peercli/main.go b/cmd/peercli/main.go new file mode 100644 index 00000000000..81e31386da9 --- /dev/null +++ b/cmd/peercli/main.go @@ -0,0 +1,61 @@ +/* +Copyright IBM Corp. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package main + +import ( + _ "net/http/pprof" + "os" + "strings" + + "github.com/hyperledger/fabric-lib-go/bccsp/factory" + "github.com/hyperledger/fabric/internal/peer/chaincode" + "github.com/hyperledger/fabric/internal/peer/channel" + "github.com/hyperledger/fabric/internal/peer/common" + "github.com/hyperledger/fabric/internal/peer/lifecycle" + "github.com/hyperledger/fabric/internal/peer/snapshot" + "github.com/hyperledger/fabric/internal/peer/version" + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +// The main command describes the service and +// defaults to printing the help message. +var mainCmd = &cobra.Command{Use: "peercli"} + +func main() { + setEnvConfig(viper.GetViper()) + + // Define command-line flags that are valid for all peercli commands and + // subcommands. + mainFlags := mainCmd.PersistentFlags() + + mainFlags.String("logging-level", "", "Legacy logging level flag") + viper.BindPFlag("logging_level", mainFlags.Lookup("logging-level")) + mainFlags.MarkHidden("logging-level") + + cryptoProvider := factory.GetDefault() + + mainCmd.AddCommand(version.Cmd()) + mainCmd.AddCommand(chaincode.Cmd(nil, cryptoProvider, true)) + mainCmd.AddCommand(channel.Cmd(nil, true)) + mainCmd.AddCommand(lifecycle.Cmd(cryptoProvider, true)) + mainCmd.AddCommand(snapshot.Cmd(cryptoProvider, true)) + + // On failure Cobra prints the usage message and error string, so we only + // need to exit with a non-0 status + if mainCmd.Execute() != nil { + os.Exit(1) + } +} + +func setEnvConfig(v *viper.Viper) { + v.SetEnvPrefix(common.CmdRoot) + v.AllowEmptyEnv(true) + v.AutomaticEnv() + replacer := strings.NewReplacer(".", "_") + v.SetEnvKeyReplacer(replacer) +} diff --git a/cmd/peercli/main_test.go b/cmd/peercli/main_test.go new file mode 100644 index 00000000000..38360b3a9db --- /dev/null +++ b/cmd/peercli/main_test.go @@ -0,0 +1,31 @@ +/* +Copyright IBM Corp. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package main + +import ( + "testing" + + "github.com/spf13/viper" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestSetEnvConfig(t *testing.T) { + vp := viper.New() + t.Setenv("CORE_FRUIT", "Apple") + t.Setenv("CORE_COLOR", "") + err := vp.BindEnv("Fruit") + require.NoError(t, err) + err = vp.BindEnv("Color") + require.NoError(t, err) + vp.SetDefault("Color", "Green") + + setEnvConfig(vp) + + assert.Equal(t, "Apple", vp.Get("Fruit")) + assert.Equal(t, "", vp.Get("Color")) +} diff --git a/core/chaincode/platforms/golang/platform.go b/core/chaincode/platforms/golang/platform.go index 5c2be07cb96..4ee8e074b30 100644 --- a/core/chaincode/platforms/golang/platform.go +++ b/core/chaincode/platforms/golang/platform.go @@ -39,7 +39,7 @@ func (p *Platform) Name() string { // ValidatePath is used to ensure that path provided points to something that // looks like go chainccode. // -// NOTE: this is only used at the _client_ side by the peer CLI. +// NOTE: this is only used at the _client_ side by the peercli. func (p *Platform) ValidatePath(rawPath string) error { _, err := DescribeCode(rawPath) if err != nil { @@ -52,7 +52,7 @@ func (p *Platform) ValidatePath(rawPath string) error { // NormalizePath is used to extract a relative module path from a module root. // This should not impact legacy GOPATH chaincode. // -// NOTE: this is only used at the _client_ side by the peer CLI. +// NOTE: this is only used at the _client_ side by the peercli. func (p *Platform) NormalizePath(rawPath string) (string, error) { modInfo, err := moduleInfo(rawPath) if err != nil { @@ -113,7 +113,7 @@ var gzipCompressionLevel = gzip.DefaultCompression // GetDeploymentPayload creates a gzip compressed tape archive that contains the // required assets to build and run go chaincode. // -// NOTE: this is only used at the _client_ side by the peer CLI. +// NOTE: this is only used at the _client_ side by the peercli. func (p *Platform) GetDeploymentPayload(codepath string) ([]byte, error) { codeDescriptor, err := DescribeCode(codepath) if err != nil { diff --git a/core/ledger/kvledger/kv_ledger_provider.go b/core/ledger/kvledger/kv_ledger_provider.go index 7f803ec6a79..f07a845eb73 100644 --- a/core/ledger/kvledger/kv_ledger_provider.go +++ b/core/ledger/kvledger/kv_ledger_provider.go @@ -429,7 +429,7 @@ func (p *Provider) Close() { // deletePartialLedgers scans for and deletes any ledger with a status of UNDER_CONSTRUCTION or UNDER_DELETION. // UNDER_CONSTRUCTION ledgers represent residual structures created as a side effect of a crash during ledger creation. -// UNDER_DELETION ledgers represent residual structures created as a side effect of a crash during a peer channel unjoin. +// UNDER_DELETION ledgers represent residual structures created as a side effect of a crash during a peercli channel unjoin. func (p *Provider) deletePartialLedgers() error { logger.Debug("Removing ledgers in state UNDER_CONSTRUCTION or UNDER_DELETION") itr := p.idStore.db.GetIterator(metadataKeyPrefix, metadataKeyStop) diff --git a/docs/source/command_ref.rst b/docs/source/command_ref.rst index 96bbddd2c79..2871e913e51 100644 --- a/docs/source/command_ref.rst +++ b/docs/source/command_ref.rst @@ -9,8 +9,14 @@ Commands Reference commands/peerlifecycle.md commands/peerchannel.md commands/peersnapshot.md - commands/peerversion.md commands/peernode.md + commands/peerversion.md + commands/peerclicommand.md + commands/peerclichaincode.md + commands/peerclilifecycle.md + commands/peerclichannel.md + commands/peerclisnapshot.md + commands/peercliversion.md commands/osnadminchannel.md commands/configtxgen.md commands/configtxlator.md diff --git a/docs/source/commands/peerchaincode.md b/docs/source/commands/peerchaincode.md index 95ca4673cd2..d596ab123ac 100644 --- a/docs/source/commands/peerchaincode.md +++ b/docs/source/commands/peerchaincode.md @@ -77,7 +77,7 @@ localhost:7051"`. ## peer chaincode invoke ``` -Invoke the specified chaincode. It will try to commit the endorsed transaction to the network. +[DEPRECATED] Invoke the specified chaincode. It will try to commit the endorsed transaction to the network. Instead of this command, use "peercli chaincode invoke". Usage: peer chaincode invoke [flags] @@ -110,7 +110,7 @@ Global Flags: ## peer chaincode query ``` -Get endorsed result of chaincode function call and print it. It won't generate transaction. +[DEPRECATED] Get endorsed result of chaincode function call and print it. It won't generate transaction. Instead of this command, use "peercli chaincode query". Usage: peer chaincode query [flags] diff --git a/docs/source/commands/peerchannel.md b/docs/source/commands/peerchannel.md index 57f9b75d4c7..3618fe23562 100644 --- a/docs/source/commands/peerchannel.md +++ b/docs/source/commands/peerchannel.md @@ -25,21 +25,21 @@ The `peer channel` command has the following subcommands: ## peer channel ``` -Operate a channel: create|fetch|join|joinbysnapshot|joinbysnapshotstatus|list|update|signconfigtx|getinfo. +[DEPRECATED] Operate a channel: create|fetch|join|joinbysnapshot|joinbysnapshotstatus|list|update|signconfigtx|getinfo. Instead of this command, use "peercli channel". Usage: peer channel [command] Available Commands: - create [DEPRECATED] Create a channel - fetch Fetch a block - getinfo get blockchain information of a specified channel. - join Joins the peer to a channel. - joinbysnapshot Joins the peer to a channel by the specified snapshot - joinbysnapshotstatus Query if joinbysnapshot is running for any channel - list List of channels peer has joined. - signconfigtx Signs a configtx update. - update Send a configtx update. + create [DEPRECATED] Create a channel (use the "osnadmin join"). + fetch [DEPRECATED] Fetch a block (use the "peercli channel fetch" or "osnadmin fetch"). + getinfo [DEPRECATED] get blockchain information of a specified channel (use the "peercli channel getinfo"). + join [DEPRECATED] Joins the peer to a channel (use the "peercli channel join"). + joinbysnapshot [DEPRECATED] Joins the peer to a channel by the specified snapshot (use the "peercli channel joinbysnapshot"). + joinbysnapshotstatus [DEPRECATED] Query if joinbysnapshot is running for any channel (use the "peercli channel joinbysnapshotstatus"). + list [DEPRECATED] List of channels peer has joined (use the "peercli channel list"). + signconfigtx [DEPRECATED] Signs a configtx update (use the "peercli channel signconfigtx"). + update [DEPRECATED] Send a configtx update (use the "osnadmin update"). Flags: --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint @@ -86,7 +86,7 @@ Global Flags: ## peer channel fetch ``` -Fetch a specified block, writing it to a file. +[DEPRECATED] Fetch a specified block from peer or orderer, writing it to a file. Instead of this command, use "peercli channel fetch" or "osnadmin fetch". Usage: peer channel fetch [outputfile] [flags] @@ -111,7 +111,7 @@ Global Flags: ## peer channel getinfo ``` -get blockchain information of a specified channel. Requires '-c'. +[DEPRECATED] get blockchain information of a specified channel. Requires '-c'. Instead of this command, use "peercli channel getinfo". Usage: peer channel getinfo [flags] @@ -135,7 +135,7 @@ Global Flags: ## peer channel join ``` -Joins the peer to a channel. +[DEPRECATED] Joins the peer to a channel. Instead of this command, use "peercli channel join". Usage: peer channel join [flags] @@ -159,7 +159,7 @@ Global Flags: ## peer channel joinbysnapshot ``` -Joins the peer to a channel by the specified snapshot +[DEPRECATED] Joins the peer to a channel by the specified snapshot. Instead of this command, use "peercli channel joinbysnapshot". Usage: peer channel joinbysnapshot [flags] @@ -183,7 +183,7 @@ Global Flags: ## peer channel joinbysnapshotstatus ``` -Query if joinbysnapshot is running for any channel +[DEPRECATED] Query if joinbysnapshot is running for any channel. Instead of this command, use "peercli channel joinbysnapshotstatus". Usage: peer channel joinbysnapshotstatus [flags] @@ -206,7 +206,7 @@ Global Flags: ## peer channel list ``` -List of channels peer has joined. +[DEPRECATED] List of channels peer has joined. Instead of this command, use "peercli channel list". Usage: peer channel list [flags] @@ -229,7 +229,7 @@ Global Flags: ## peer channel signconfigtx ``` -Signs the supplied configtx update file in place on the filesystem. Requires '-f'. +[DEPRECATED] Signs the supplied configtx update file in place on the filesystem. Requires '-f'. Instead of this command, use "peercli channel signconfigtx". Usage: peer channel signconfigtx [flags] @@ -253,7 +253,7 @@ Global Flags: ## peer channel update ``` -Signs and sends the supplied configtx update file to the channel. Requires '-f', '-o', '-c'. +[DEPRECATED] Signs and sends the supplied configtx update file to the channel. Requires '-f', '-o', '-c'. . Instead of this command, use Orderer Service Node (OSN). Usage: peer channel update [flags] diff --git a/docs/source/commands/peerclichaincode.md b/docs/source/commands/peerclichaincode.md new file mode 100644 index 00000000000..4568be6be66 --- /dev/null +++ b/docs/source/commands/peerclichaincode.md @@ -0,0 +1,208 @@ + + +# peercli chaincode + +The `peercli chaincode` command allows users to invoke and query chaincode. + +## Syntax + +The `peercli chaincode` command has the following subcommands: + + * invoke + * query + +The subcommands take a constructor flag (`-c` or `--ctor`) to pass arguments to a chaincode. +The value must be a JSON string that has either key 'Args' or 'Function' and 'Args'. +These keys are case-insensitive. + +If the constructor JSON string only has the Args key, the key value is an array, where the +first array element is the target function to call, and the subsequent elements +are arguments of the function. If the JSON string has both 'Function' and +'Args', the value of Function is the target function to call, and the value of +Args is an array of arguments of the function. For instance, +`{"Args":["GetAllAssets"]}` is equivalent to +`{"Function":"GetAllAssets", "Args":[]}`. + +Each peercli chaincode subcommand is described together with its options in its own +section in this topic. + +## Flags + +Each `peercli chaincode` subcommand has both a set of flags specific to an +individual subcommand, as well as a set of global flags that relate to all +`peercli chaincode` subcommands. Not all subcommands would use these flags. +For instance, the `query` subcommand does not need the `--orderer` flag. + +The individual flags are described with the relevant subcommand. The global +flags are + +* `--cafile ` + + Path to file containing PEM-encoded trusted certificate(s) for the ordering + endpoint + +* `--certfile ` + + Path to file containing PEM-encoded X509 public key to use for mutual TLS + communication with the orderer endpoint + +* `--keyfile ` + + Path to file containing PEM-encoded private key to use for mutual TLS + communication with the orderer endpoint + +* `-o` or `--orderer ` + + Ordering service endpoint specified as `:` + +* `--ordererTLSHostnameOverride ` + + The hostname override to use when validating the TLS connection to the orderer + +* `--tls` + + Use TLS when communicating with the orderer endpoint + +* `--transient ` + + Transient map of arguments in JSON encoding + +Flags of type stringArray are to be repeated rather than concatenating their +values. For example, you will use `--peerAddresses localhost:9051 +--peerAddresses localhost:7051` rather than `--peerAddresses "localhost:9051 +localhost:7051"`. + +## peercli chaincode invoke +``` +Invoke the specified chaincode. It will try to commit the endorsed transaction to the network. + +Usage: + peercli chaincode invoke [flags] + +Flags: + -C, --channelID string The channel on which this command should be executed + --connectionProfile string Connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information + -c, --ctor string Constructor message for the chaincode in JSON format (default "{}") + -h, --help help for invoke + -I, --isInit Is this invocation for init (useful for supporting legacy chaincodes in the new lifecycle) + -n, --name string Name of the chaincode + --peerAddresses stringArray The addresses of the peers to connect to + --tlsRootCertFiles stringArray If TLS is enabled, the paths to the TLS root cert files of the peers to connect to. The order and number of certs specified should match the --peerAddresses flag + --waitForEvent Whether to wait for the event from each peer's deliver filtered service signifying that the 'invoke' transaction has been committed successfully + --waitForEventTimeout duration Time to wait for the event from each peer's deliver filtered service signifying that the 'invoke' transaction has been committed successfully (default 30s) + +Global Flags: + --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint + --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint + --clientauth Use mutual TLS when communicating with the orderer endpoint + --connTimeout duration Timeout for client to connect (default 3s) + --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint + -o, --orderer string Ordering service endpoint + --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer + --tls Use TLS when communicating with the orderer endpoint + --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint + --transient string Transient map of arguments in JSON encoding +``` + + +## peercli chaincode query +``` +Get endorsed result of chaincode function call and print it. It won't generate transaction. + +Usage: + peercli chaincode query [flags] + +Flags: + -C, --channelID string The channel on which this command should be executed + --connectionProfile string Connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information + -c, --ctor string Constructor message for the chaincode in JSON format (default "{}") + -h, --help help for query + -x, --hex If true, output the query value byte array in hexadecimal. Incompatible with --raw + -n, --name string Name of the chaincode + --peerAddresses stringArray The addresses of the peers to connect to + -r, --raw If true, output the query value as raw bytes, otherwise format as a printable string + --tlsRootCertFiles stringArray If TLS is enabled, the paths to the TLS root cert files of the peers to connect to. The order and number of certs specified should match the --peerAddresses flag + +Global Flags: + --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint + --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint + --clientauth Use mutual TLS when communicating with the orderer endpoint + --connTimeout duration Timeout for client to connect (default 3s) + --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint + -o, --orderer string Ordering service endpoint + --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer + --tls Use TLS when communicating with the orderer endpoint + --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint + --transient string Transient map of arguments in JSON encoding +``` + +## Example Usage + +### peercli chaincode invoke example + +Here is an example of the `peercli chaincode invoke` command: + + * Invoke the chaincode named `mycc` at version `1.0` on channel `mychannel` + on `peer0.org1.example.com:7051` and `peer0.org2.example.com:9051` (the + peers defined by `--peerAddresses`), requesting to move 10 units from + variable `a` to variable `b`: + + ``` + peercli chaincode invoke -o orderer.example.com:7050 -C mychannel -n mycc --peerAddresses peer0.org1.example.com:7051 --peerAddresses peer0.org2.example.com:9051 -c '{"Args":["invoke","a","b","10"]}' + + 2018-02-22 16:34:27.069 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc + 2018-02-22 16:34:27.069 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc + . + . + . + 2018-02-22 16:34:27.106 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> DEBU 00a ESCC invoke result: version:1 response: payload:"\n \237mM\376? [\214\002 \332\204\035\275q\227\2132A\n\204&\2106\037W|\346#\3413\274\022Y\nE\022\024\n\004lscc\022\014\n\n\n\004mycc\022\002\010\003\022-\n\004mycc\022%\n\007\n\001a\022\002\010\003\n\007\n\001b\022\002\010\003\032\007\n\001a\032\00290\032\010\n\001b\032\003210\032\003\010\310\001\"\013\022\004mycc\032\0031.0" endorsement: + 2018-02-22 16:34:27.107 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 00b Chaincode invoke successful. result: status:200 + 2018-02-22 16:34:27.107 UTC [main] main -> INFO 00c Exiting..... + + ``` + + Here you can see that the invoke was submitted successfully based on the log + message: + + ``` + 2018-02-22 16:34:27.107 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 00b Chaincode invoke successful. result: status:200 + + ``` + + A successful response indicates that the transaction was submitted for ordering + successfully. The transaction will then be added to a block and, finally, validated + or invalidated by each peer on the channel. + +Here is an example of how to format the `peercli chaincode invoke` command when the chaincode package includes multiple smart contracts. + + * If you are using the [contract-api](https://www.npmjs.com/package/fabric-contract-api), the name you pass to `super("MyContract")` can be used as a prefix. + + ``` + peercli chaincode invoke -C $CHANNEL_NAME -n $CHAINCODE_NAME -c '{ "Args": ["MyContract:methodName", "{}"] }' + + peercli chaincode invoke -C $CHANNEL_NAME -n $CHAINCODE_NAME -c '{ "Args": ["MyOtherContract:methodName", "{}"] }' + + ``` + +### peercli chaincode query example + +Here is an example of the `peercli chaincode query` command, which queries the +peer ledger for the chaincode named `mycc` at version `1.0` for the value of +variable `a`: + + * You can see from the output that variable `a` had a value of 90 at the time of + the query. + + ``` + peercli chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}' + + 2018-02-22 16:34:30.816 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc + 2018-02-22 16:34:30.816 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc + Query Result: 90 + + ``` + +Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License. diff --git a/docs/source/commands/peerclichannel.md b/docs/source/commands/peerclichannel.md new file mode 100644 index 00000000000..54659c1c3d5 --- /dev/null +++ b/docs/source/commands/peerclichannel.md @@ -0,0 +1,402 @@ + + +# peercli channel + +The `peercli channel` command allows administrators to perform channel related +operations on a peer, such as joining a channel or listing the channels to which +a peer is joined. + +## Syntax + +The `peercli channel` command has the following subcommands: + + * fetch + * getinfo + * join + * joinbysnapshot + * joinbysnapshotstatus + * list + * signconfigtx + +## peercli channel +``` +Operate a channel: fetch|join|joinbysnapshot|joinbysnapshotstatus|list|signconfigtx|getinfo. + +Usage: + peercli channel [command] + +Available Commands: + fetch Fetch a block from peer. + getinfo get blockchain information of a specified channel. + join Joins the peer to a channel. + joinbysnapshot Joins the peer to a channel by the specified snapshot + joinbysnapshotstatus Query if joinbysnapshot is running for any channel. + list List of channels peer has joined. + signconfigtx Signs a configtx update. + +Flags: + --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint + --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint + --clientauth Use mutual TLS when communicating with the orderer endpoint + --connTimeout duration Timeout for client to connect (default 3s) + -h, --help help for channel + --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint + -o, --orderer string Ordering service endpoint + --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer + --tls Use TLS when communicating with the orderer endpoint + --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint + +Use "peercli channel [command] --help" for more information about a command. +``` + + +## peercli channel fetch +``` +Fetch a specified block from peer, writing it to a file. + +Usage: + peercli channel fetch [outputfile] [flags] + +Flags: + --bestEffort Whether fetch requests should ignore errors and return blocks on a best effort basis + -c, --channelID string In case of a newChain command, the channel ID to create. It must be all lower case, less than 250 characters long and match the regular expression: [a-z][a-z0-9.-]* + -h, --help help for fetch + +Global Flags: + --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint + --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint + --clientauth Use mutual TLS when communicating with the orderer endpoint + --connTimeout duration Timeout for client to connect (default 3s) + --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint + -o, --orderer string Ordering service endpoint + --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer + --tls Use TLS when communicating with the orderer endpoint + --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint +``` + + +## peercli channel getinfo +``` +get blockchain information of a specified channel. Requires '-c'. + +Usage: + peercli channel getinfo [flags] + +Flags: + -c, --channelID string In case of a newChain command, the channel ID to create. It must be all lower case, less than 250 characters long and match the regular expression: [a-z][a-z0-9.-]* + -h, --help help for getinfo + +Global Flags: + --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint + --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint + --clientauth Use mutual TLS when communicating with the orderer endpoint + --connTimeout duration Timeout for client to connect (default 3s) + --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint + -o, --orderer string Ordering service endpoint + --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer + --tls Use TLS when communicating with the orderer endpoint + --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint +``` + + +## peercli channel join +``` +Joins the peer to a channel. + +Usage: + peercli channel join [flags] + +Flags: + -b, --blockpath string Path to file containing genesis block + -h, --help help for join + +Global Flags: + --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint + --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint + --clientauth Use mutual TLS when communicating with the orderer endpoint + --connTimeout duration Timeout for client to connect (default 3s) + --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint + -o, --orderer string Ordering service endpoint + --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer + --tls Use TLS when communicating with the orderer endpoint + --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint +``` + + +## peercli channel joinbysnapshot +``` +Joins the peer to a channel by the specified snapshot + +Usage: + peercli channel joinbysnapshot [flags] + +Flags: + -h, --help help for joinbysnapshot + --snapshotpath string Path to the snapshot directory + +Global Flags: + --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint + --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint + --clientauth Use mutual TLS when communicating with the orderer endpoint + --connTimeout duration Timeout for client to connect (default 3s) + --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint + -o, --orderer string Ordering service endpoint + --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer + --tls Use TLS when communicating with the orderer endpoint + --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint +``` + + +## peercli channel joinbysnapshotstatus +``` +Query if joinbysnapshot is running for any channel. + +Usage: + peercli channel joinbysnapshotstatus [flags] + +Flags: + -h, --help help for joinbysnapshotstatus + +Global Flags: + --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint + --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint + --clientauth Use mutual TLS when communicating with the orderer endpoint + --connTimeout duration Timeout for client to connect (default 3s) + --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint + -o, --orderer string Ordering service endpoint + --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer + --tls Use TLS when communicating with the orderer endpoint + --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint +``` + + +## peercli channel list +``` +List of channels peer has joined. + +Usage: + peercli channel list [flags] + +Flags: + -h, --help help for list + +Global Flags: + --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint + --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint + --clientauth Use mutual TLS when communicating with the orderer endpoint + --connTimeout duration Timeout for client to connect (default 3s) + --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint + -o, --orderer string Ordering service endpoint + --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer + --tls Use TLS when communicating with the orderer endpoint + --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint +``` + + +## peercli channel signconfigtx +``` +Signs the supplied configtx update file in place on the filesystem. Requires '-f'. + +Usage: + peercli channel signconfigtx [flags] + +Flags: + -f, --file string Configuration transaction file generated by a tool such as configtxgen for submitting to orderer + -h, --help help for signconfigtx + +Global Flags: + --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint + --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint + --clientauth Use mutual TLS when communicating with the orderer endpoint + --connTimeout duration Timeout for client to connect (default 3s) + --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint + -o, --orderer string Ordering service endpoint + --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer + --tls Use TLS when communicating with the orderer endpoint + --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint +``` + +## Example Usage + +### peercli channel fetch example + +Here's some examples of the `peercli channel fetch` command. + +* Using the `newest` option to retrieve the most recent channel block, and + store it in the file `mychannel.block`. + + ``` + peercli channel fetch newest mychannel.block -c mychannel + + 2018-02-25 13:10:16.137 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized + 2018-02-25 13:10:16.144 UTC [channelCmd] readBlock -> INFO 00a Received block: 32 + 2018-02-25 13:10:16.145 UTC [main] main -> INFO 00b Exiting..... + + ls -l + + -rw-r--r-- 1 root root 11982 Feb 25 13:10 mychannel.block + + ``` + + You can see that the retrieved block is number 32, and that the information + has been written to the file `mychannel.block`. + +* Using the `(block number)` option to retrieve a specific block -- in this + case, block number 16 -- and store it in the default block file. + + ``` + peercli channel fetch 16 -c mychannel + + 2018-02-25 13:46:50.296 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized + 2018-02-25 13:46:50.302 UTC [channelCmd] readBlock -> INFO 00a Received block: 16 + 2018-02-25 13:46:50.302 UTC [main] main -> INFO 00b Exiting..... + + ls -l + + -rw-r--r-- 1 root root 11982 Feb 25 13:10 mychannel.block + -rw-r--r-- 1 root root 4783 Feb 25 13:46 mychannel_16.block + + ``` + + You can see that the retrieved block is number 16, and that the information + has been written to the default file `mychannel_16.block`. + + For configuration blocks, the block file can be decoded using the + [`configtxlator` command](./configtxlator.html). See this command for an example + of decoded output. User transaction blocks can also be decoded, but a user + program must be written to do this. + +### peercli channel getinfo example + +Here's an example of the `peercli channel getinfo` command. + +* Get information about the local peer for channel `mychannel`. + + ``` + peercli channel getinfo -c mychannel + + 2018-02-25 15:15:44.135 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized + Blockchain info: {"height":5,"currentBlockHash":"JgK9lcaPUNmFb5Mp1qe1SVMsx3o/22Ct4+n5tejcXCw=","previousBlockHash":"f8lZXoAn3gF86zrFq7L1DzW2aKuabH9Ow6SIE5Y04a4="} + 2018-02-25 15:15:44.139 UTC [main] main -> INFO 006 Exiting..... + + ``` + + You can see that the latest block for channel `mychannel` is block 5. You + can also see the cryptographic hashes for the most recent blocks in the + channel's blockchain. + +### peercli channel join example + +Here's an example of the `peercli channel join` command. + +* Join a peer to the channel defined in the genesis block identified by the file + `./mychannel.genesis.block`. In this example, the channel block was + previously retrieved by the `peercli channel fetch` command. + + ``` + peercli channel join -b ./mychannel.genesis.block + + 2018-02-25 12:25:26.511 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized + 2018-02-25 12:25:26.571 UTC [channelCmd] executeJoin -> INFO 006 Successfully submitted proposal to join channel + 2018-02-25 12:25:26.571 UTC [main] main -> INFO 007 Exiting..... + + ``` + + You can see that the peer has successfully made a request to join the channel. + +### peercli channel joinbysnapshot example + +Here's an example of the `peercli channel joinbysnapshot` command. + +* Join a peer to the channel from a snapshot identified by the directory + `/snapshots/completed/testchannel/1000`. The snapshot was previously created on a different peer. + + ``` + peercli channel joinbysnapshot --snapshotpath /snapshots/completed/testchannel/1000 + + 2020-10-12 11:41:45.442 EDT [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized + 2020-10-12 11:41:45.444 EDT [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel + 2020-10-12 11:41:45.444 EDT [channelCmd] joinBySnapshot -> INFO 003 The joinbysnapshot operation is in progress. Use "peercli channel joinbysnapshotstatus" to check the status. + + ``` + + You can see that the peer has successfully made a request to join the channel from the specified snapshot. + When a `joinbysnapshot` operation is in progress, you cannot run another `peercli channel join` + or `peercli channel joinbysnapshot` simultaneously. To know whether or not a joinbysnapshot operation is in progress, + you can call the `peercli channel joinbysnapshotstatus` command. + + +### peercli channel joinbysnapshotstatus example + +Here are some examples of the `peercli channel joinbysnapshotstatus` command. + +* Query if joinbysnapshot is in progress for any channel. If yes, + it returns a message indicating a joinbysnapshot operation is in progress. + + ``` + peercli channel joinbysnapshotstatus + + 2020-10-12 11:41:45.952 EDT [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized + A joinbysnapshot operation is in progress for snapshot at /snapshots/completed/testchannel/1000 + ``` + +* If no `joinbysnapshot` operation is in progress, it returns a message indicating no joinbysnapshot operation is in progress. + + ``` + peercli channel joinbysnapshotstatus + + 2020-10-12 11:41:47.922 EDT [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized + No joinbysnapshot operation is in progress + + ``` + +### peercli channel list example + + Here's an example of the `peercli channel list` command. + + * List the channels to which a peer is joined. + + ``` + peercli channel list + + 2018-02-25 14:21:20.361 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized + Channels peers has joined: + mychannel + 2018-02-25 14:21:20.372 UTC [main] main -> INFO 006 Exiting..... + + ``` + + You can see that the peer is joined to channel `mychannel`. + +### peercli channel signconfigtx example + +Here's an example of the `peercli channel signconfigtx` command. + +* Sign the `channel update` transaction defined in the file + `./updatechannel.tx`. The example lists the configuration transaction file + before and after the command. + + ``` + ls -l + + -rw-r--r-- 1 anthonyodowd staff 284 25 Feb 18:16 updatechannel.tx + + peercli channel signconfigtx -f updatechannel.tx + + 2018-02-25 18:16:44.456 GMT [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized + 2018-02-25 18:16:44.459 GMT [main] main -> INFO 002 Exiting..... + + ls -l + + -rw-r--r-- 1 anthonyodowd staff 2180 25 Feb 18:16 updatechannel.tx + + ``` + + You can see that the peer has successfully signed the configuration + transaction by the increase in the size of the file `updatechannel.tx` from + 284 bytes to 2180 bytes. + +Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License. diff --git a/docs/source/commands/peerclicommand.md b/docs/source/commands/peerclicommand.md new file mode 100644 index 00000000000..0d23e30c40f --- /dev/null +++ b/docs/source/commands/peerclicommand.md @@ -0,0 +1,80 @@ +# peercli + +## Description + + The `peercli` command has five different subcommands, each of which allows + administrators to perform a specific set of tasks related to a peercli. For + example, you can use the `peercli channel` subcommand to join a peer to a channel, + or the `peercli chaincode` command to deploy a smart contract chaincode to a + peer. + +## Syntax + +The `peercli` command has five different subcommands within it: + +``` +peercli chaincode [option] [flags] +peercli channel [option] [flags] +peercli version [option] [flags] +``` + +Each subcommand has different options available, and these are described in +their own dedicated topic. For brevity, we often refer to a command (`peercli`), a +subcommand (`channel`), or subcommand option (`fetch`) simply as a **command**. + +If a subcommand is specified without an option, then it will return some high +level help text as described in the `--help` flag below. + +## Flags + +Each `peercli` subcommand has a specific set of flags associated with it, many of +which are designated *global* because they can be used in all subcommand +options. These flags are described with the relevant `peercli` subcommand. + +The top level `peercli` command has the following flag: + +* `--help` + + Use `--help` to get brief help text for any `peercli` command. The `--help` flag + is very useful -- it can be used to get command help, subcommand help, and + even option help. + + For example + ``` + peercli --help + peercli channel --help + peercli channel list --help + + ``` + See individual `peercli` subcommands for more detail. + +## Usage + +Here is an example using the available flag on the `peercli` command. + +* Using the `--help` flag on the `peercli channel join` command. + + ``` + peercli channel join --help + + Joins the peercli to a channel. + + Usage: + peercli channel join [flags] + + Flags: + -b, --blockpath string Path to file containing genesis block + -h, --help help for join + + Global Flags: + --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint + --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint + --clientauth Use mutual TLS when communicating with the orderer endpoint + --connTimeout duration Timeout for client to connect (default 3s) + --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint + -o, --orderer string Ordering service endpoint + --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer. + --tls Use TLS when communicating with the orderer endpoint + + ``` + This shows brief help syntax for the `peercli channel join` command. diff --git a/docs/source/commands/peerclilifecycle.md b/docs/source/commands/peerclilifecycle.md new file mode 100644 index 00000000000..4b062f834f6 --- /dev/null +++ b/docs/source/commands/peerclilifecycle.md @@ -0,0 +1,948 @@ + + +# peercli lifecycle chaincode + +The `peercli lifecycle chaincode` subcommand allows administrators to use the +Fabric chaincode lifecycle to package a chaincode, install it on your peers, +approve a chaincode definition for your organization, and then commit the +definition to a channel. The chaincode is ready to be used after the definition +has been successfully committed to the channel. For more information, visit +[Fabric chaincode lifecycle](../chaincode_lifecycle.html). + +## Syntax + +The `peercli lifecycle chaincode` command has the following subcommands: + + * package + * install + * queryinstalled + * getinstalledpackage + * calculatepackageid + * approveformyorg + * queryapproved + * checkcommitreadiness + * commit + * querycommitted + +Each peercli lifecycle chaincode subcommand is described together with its options in its own +section in this topic. + +## peercli lifecycle +``` +Perform _lifecycle operations. + +Usage: + peercli lifecycle [command] + +Available Commands: + chaincode Perform chaincode operations: package|install|queryinstalled|getinstalledpackage|calculatepackageid|approveformyorg|queryapproved|checkcommitreadiness|commit|querycommitted. + +Flags: + -h, --help help for lifecycle + +Use "peercli lifecycle [command] --help" for more information about a command. +``` + + +## peercli lifecycle chaincode +``` +Perform chaincode operations: package|install|queryinstalled|getinstalledpackage|calculatepackageid|approveformyorg|queryapproved|checkcommitreadiness|commit|querycommitted. + +Usage: + peercli lifecycle chaincode [command] + +Available Commands: + approveformyorg Approve the chaincode definition for my org. + calculatepackageid Calculate the package ID for a chaincode. + checkcommitreadiness Check whether a chaincode definition is ready to be committed on a channel. + commit Commit the chaincode definition on the channel. + getinstalledpackage Get an installed chaincode package from a peer. + install Install a chaincode. + package Package a chaincode + queryapproved Query org's approved chaincode definitions from its peer. + querycommitted Query the committed chaincode definitions by channel on a peer. + queryinstalled Query the installed chaincodes on a peer. + +Flags: + --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint + --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint + --clientauth Use mutual TLS when communicating with the orderer endpoint + --connTimeout duration Timeout for client to connect (default 3s) + -h, --help help for chaincode + --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint + -o, --orderer string Ordering service endpoint + --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer + --tls Use TLS when communicating with the orderer endpoint + --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint + +Use "peercli lifecycle chaincode [command] --help" for more information about a command. +``` + + +## peercli lifecycle chaincode package +``` +Package a chaincode and write the package to a file. + +Usage: + peercli lifecycle chaincode package [outputfile] [flags] + +Flags: + --connectionProfile string The fully qualified path to the connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information + -h, --help help for package + --label string The package label contains a human-readable description of the package + -l, --lang string Language the chaincode is written in (default "golang") + -p, --path string Path to the chaincode + --peerAddresses stringArray The addresses of the peers to connect to + --tlsRootCertFiles stringArray If TLS is enabled, the paths to the TLS root cert files of the peers to connect to. The order and number of certs specified should match the --peerAddresses flag + +Global Flags: + --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint + --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint + --clientauth Use mutual TLS when communicating with the orderer endpoint + --connTimeout duration Timeout for client to connect (default 3s) + --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint + -o, --orderer string Ordering service endpoint + --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer + --tls Use TLS when communicating with the orderer endpoint + --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint +``` + + +## peercli lifecycle chaincode install +``` +Install a chaincode on a peer. + +Usage: + peercli lifecycle chaincode install [packageFile] [flags] + +Flags: + --connectionProfile string The fully qualified path to the connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information + -h, --help help for install + --peerAddresses stringArray The addresses of the peers to connect to + --targetPeer string When using a connection profile, the name of the peer to target for this action + --tlsRootCertFiles stringArray If TLS is enabled, the paths to the TLS root cert files of the peers to connect to. The order and number of certs specified should match the --peerAddresses flag + +Global Flags: + --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint + --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint + --clientauth Use mutual TLS when communicating with the orderer endpoint + --connTimeout duration Timeout for client to connect (default 3s) + --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint + -o, --orderer string Ordering service endpoint + --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer + --tls Use TLS when communicating with the orderer endpoint + --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint +``` + + +## peercli lifecycle chaincode queryinstalled +``` +Query the installed chaincodes on a peer. + +Usage: + peercli lifecycle chaincode queryinstalled [flags] + +Flags: + --connectionProfile string The fully qualified path to the connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information + -h, --help help for queryinstalled + -O, --output string The output format for query results. Default is human-readable plain-text. json is currently the only supported format. + --peerAddresses stringArray The addresses of the peers to connect to + --targetPeer string When using a connection profile, the name of the peer to target for this action + --tlsRootCertFiles stringArray If TLS is enabled, the paths to the TLS root cert files of the peers to connect to. The order and number of certs specified should match the --peerAddresses flag + +Global Flags: + --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint + --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint + --clientauth Use mutual TLS when communicating with the orderer endpoint + --connTimeout duration Timeout for client to connect (default 3s) + --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint + -o, --orderer string Ordering service endpoint + --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer + --tls Use TLS when communicating with the orderer endpoint + --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint +``` + + +## peercli lifecycle chaincode getinstalledpackage +``` +Get an installed chaincode package from a peer. + +Usage: + peercli lifecycle chaincode getinstalledpackage [outputfile] [flags] + +Flags: + --connectionProfile string The fully qualified path to the connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information + -h, --help help for getinstalledpackage + --output-directory string The output directory to use when writing a chaincode install package to disk. Default is the current working directory. + --package-id string The identifier of the chaincode install package + --peerAddresses stringArray The addresses of the peers to connect to + --targetPeer string When using a connection profile, the name of the peer to target for this action + --tlsRootCertFiles stringArray If TLS is enabled, the paths to the TLS root cert files of the peers to connect to. The order and number of certs specified should match the --peerAddresses flag + +Global Flags: + --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint + --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint + --clientauth Use mutual TLS when communicating with the orderer endpoint + --connTimeout duration Timeout for client to connect (default 3s) + --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint + -o, --orderer string Ordering service endpoint + --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer + --tls Use TLS when communicating with the orderer endpoint + --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint +``` + + +## peercli lifecycle chaincode calculatepackageid +``` +Calculate the package ID for a packaged chaincode. + +Usage: + peercli lifecycle chaincode calculatepackageid [packageFile] [flags] + +Flags: + --connectionProfile string The fully qualified path to the connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information + -h, --help help for calculatepackageid + -O, --output string The output format for query results. Default is human-readable plain-text. json is currently the only supported format. + --peerAddresses stringArray The addresses of the peers to connect to + --tlsRootCertFiles stringArray If TLS is enabled, the paths to the TLS root cert files of the peers to connect to. The order and number of certs specified should match the --peerAddresses flag + +Global Flags: + --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint + --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint + --clientauth Use mutual TLS when communicating with the orderer endpoint + --connTimeout duration Timeout for client to connect (default 3s) + --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint + -o, --orderer string Ordering service endpoint + --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer + --tls Use TLS when communicating with the orderer endpoint + --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint +``` + + +## peercli lifecycle chaincode approveformyorg +``` +Approve the chaincode definition for my organization. + +Usage: + peercli lifecycle chaincode approveformyorg [flags] + +Flags: + --channel-config-policy string The endorsement policy associated to this chaincode specified as a channel config policy reference + -C, --channelID string The channel on which this command should be executed + --collections-config string The fully qualified path to the collection JSON file including the file name + --connectionProfile string The fully qualified path to the connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information + -E, --endorsement-plugin string The name of the endorsement plugin to be used for this chaincode + -h, --help help for approveformyorg + --init-required Whether the chaincode requires invoking 'init' + -n, --name string Name of the chaincode + --package-id string The identifier of the chaincode install package + --peerAddresses stringArray The addresses of the peers to connect to + --sequence int The sequence number of the chaincode definition for the channel + --signature-policy string The endorsement policy associated to this chaincode specified as a signature policy + --tlsRootCertFiles stringArray If TLS is enabled, the paths to the TLS root cert files of the peers to connect to. The order and number of certs specified should match the --peerAddresses flag + -V, --validation-plugin string The name of the validation plugin to be used for this chaincode + -v, --version string Version of the chaincode + --waitForEvent Whether to wait for the event from each peer's deliver filtered service signifying that the transaction has been committed successfully (default true) + --waitForEventTimeout duration Time to wait for the event from each peer's deliver filtered service signifying that the 'invoke' transaction has been committed successfully (default 30s) + +Global Flags: + --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint + --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint + --clientauth Use mutual TLS when communicating with the orderer endpoint + --connTimeout duration Timeout for client to connect (default 3s) + --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint + -o, --orderer string Ordering service endpoint + --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer + --tls Use TLS when communicating with the orderer endpoint + --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint +``` + + +## peercli lifecycle chaincode queryapproved +``` +Query organization's approved chaincode definitions from its peer. + +Usage: + peercli lifecycle chaincode queryapproved [flags] + +Flags: + -C, --channelID string The channel on which this command should be executed + --connectionProfile string The fully qualified path to the connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information + -h, --help help for queryapproved + -n, --name string Name of the chaincode + -O, --output string The output format for query results. Default is human-readable plain-text. json is currently the only supported format. + --peerAddresses stringArray The addresses of the peers to connect to + --sequence int The sequence number of the chaincode definition for the channel + --tlsRootCertFiles stringArray If TLS is enabled, the paths to the TLS root cert files of the peers to connect to. The order and number of certs specified should match the --peerAddresses flag + +Global Flags: + --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint + --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint + --clientauth Use mutual TLS when communicating with the orderer endpoint + --connTimeout duration Timeout for client to connect (default 3s) + --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint + -o, --orderer string Ordering service endpoint + --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer + --tls Use TLS when communicating with the orderer endpoint + --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint +``` + + +## peercli lifecycle chaincode checkcommitreadiness +``` +Check whether a chaincode definition is ready to be committed on a channel. + +Usage: + peercli lifecycle chaincode checkcommitreadiness [flags] + +Flags: + --channel-config-policy string The endorsement policy associated to this chaincode specified as a channel config policy reference + -C, --channelID string The channel on which this command should be executed + --collections-config string The fully qualified path to the collection JSON file including the file name + --connectionProfile string The fully qualified path to the connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information + -E, --endorsement-plugin string The name of the endorsement plugin to be used for this chaincode + -h, --help help for checkcommitreadiness + --init-required Whether the chaincode requires invoking 'init' + --inspect If inspect is enabled, output additional information to identify discrepancies when an organization's approval is false + -n, --name string Name of the chaincode + -O, --output string The output format for query results. Default is human-readable plain-text. json is currently the only supported format. + --peerAddresses stringArray The addresses of the peers to connect to + --sequence int The sequence number of the chaincode definition for the channel + --signature-policy string The endorsement policy associated to this chaincode specified as a signature policy + --tlsRootCertFiles stringArray If TLS is enabled, the paths to the TLS root cert files of the peers to connect to. The order and number of certs specified should match the --peerAddresses flag + -V, --validation-plugin string The name of the validation plugin to be used for this chaincode + -v, --version string Version of the chaincode + +Global Flags: + --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint + --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint + --clientauth Use mutual TLS when communicating with the orderer endpoint + --connTimeout duration Timeout for client to connect (default 3s) + --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint + -o, --orderer string Ordering service endpoint + --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer + --tls Use TLS when communicating with the orderer endpoint + --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint +``` + + +## peercli lifecycle chaincode commit +``` +Commit the chaincode definition on the channel. + +Usage: + peercli lifecycle chaincode commit [flags] + +Flags: + --channel-config-policy string The endorsement policy associated to this chaincode specified as a channel config policy reference + -C, --channelID string The channel on which this command should be executed + --collections-config string The fully qualified path to the collection JSON file including the file name + --connectionProfile string The fully qualified path to the connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information + -E, --endorsement-plugin string The name of the endorsement plugin to be used for this chaincode + -h, --help help for commit + --init-required Whether the chaincode requires invoking 'init' + -n, --name string Name of the chaincode + --peerAddresses stringArray The addresses of the peers to connect to + --sequence int The sequence number of the chaincode definition for the channel + --signature-policy string The endorsement policy associated to this chaincode specified as a signature policy + --tlsRootCertFiles stringArray If TLS is enabled, the paths to the TLS root cert files of the peers to connect to. The order and number of certs specified should match the --peerAddresses flag + -V, --validation-plugin string The name of the validation plugin to be used for this chaincode + -v, --version string Version of the chaincode + --waitForEvent Whether to wait for the event from each peer's deliver filtered service signifying that the transaction has been committed successfully (default true) + --waitForEventTimeout duration Time to wait for the event from each peer's deliver filtered service signifying that the 'invoke' transaction has been committed successfully (default 30s) + +Global Flags: + --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint + --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint + --clientauth Use mutual TLS when communicating with the orderer endpoint + --connTimeout duration Timeout for client to connect (default 3s) + --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint + -o, --orderer string Ordering service endpoint + --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer + --tls Use TLS when communicating with the orderer endpoint + --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint +``` + + +## peercli lifecycle chaincode querycommitted +``` +Query the committed chaincode definitions by channel on a peer. Optional: provide a chaincode name to query a specific definition. + +Usage: + peercli lifecycle chaincode querycommitted [flags] + +Flags: + -C, --channelID string The channel on which this command should be executed + --connectionProfile string The fully qualified path to the connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information + -h, --help help for querycommitted + -n, --name string Name of the chaincode + -O, --output string The output format for query results. Default is human-readable plain-text. json is currently the only supported format. + --peerAddresses stringArray The addresses of the peers to connect to + --tlsRootCertFiles stringArray If TLS is enabled, the paths to the TLS root cert files of the peers to connect to. The order and number of certs specified should match the --peerAddresses flag + +Global Flags: + --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint + --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint + --clientauth Use mutual TLS when communicating with the orderer endpoint + --connTimeout duration Timeout for client to connect (default 3s) + --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint + -o, --orderer string Ordering service endpoint + --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer + --tls Use TLS when communicating with the orderer endpoint + --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint +``` + + +## Example Usage + +### peercli lifecycle chaincode package example + +A chaincode needs to be packaged before it can be installed on your peers. +This example uses the `peercli lifecycle chaincode package` command to package +a Go chaincode. + + * Use the `--path` flag to indicate the location of the chaincode. + The path must be a fully qualified path or a path relative to your present working directory. + * Use the `--label` flag to provide a chaincode package label of `myccv1` + that your organization will use to identify the package. + + ``` + peercli lifecycle chaincode package mycc.tar.gz --path $CHAINCODE_DIR --lang golang --label myccv1 + ``` + +### peercli lifecycle chaincode install example + +After the chaincode is packaged, you can use the `peercli chaincode install` command +to install the chaincode on your peers. + + * Install the `mycc.tar.gz ` package on `peer0.org1.example.com:7051` (the + peer defined by `--peerAddresses`). + + ``` + peercli lifecycle chaincode install mycc.tar.gz --peerAddresses peer0.org1.example.com:7051 + ``` + If successful, the command will return the package identifier. The + package ID is the package label combined with a hash of the chaincode + package taken by the peer. + ``` + 2019-03-13 13:48:53.691 UTC [peercli.lifecycle.chaincode] submitInstallProposal -> INFO 001 Installed remotely: response: + 2019-03-13 13:48:53.691 UTC [peercli.lifecycle.chaincode] submitInstallProposal -> INFO 002 Chaincode code package identifier: mycc:a7ca45a7cc85f1d89c905b775920361ed089a364e12a9b6d55ba75c965ddd6a9 + ``` + +### peercli lifecycle chaincode queryinstalled example + +You need to use the chaincode package identifier to approve a chaincode +definition for your organization. You can find the package ID for the +chaincodes you have installed by using the +`peercli lifecycle chaincode queryinstalled` command: + +``` +peercli lifecycle chaincode queryinstalled --peerAddresses peer0.org1.example.com:7051 +``` + +A successful command will return the package ID associated with the +package label. + +``` +Get installed chaincodes on peer: +Package ID: myccv1:a7ca45a7cc85f1d89c905b775920361ed089a364e12a9b6d55ba75c965ddd6a9, Label: myccv1 +``` + + * You can also use the `--output` flag to have the peercli format the output as + JSON. + + ``` + peercli lifecycle chaincode queryinstalled --peerAddresses peer0.org1.example.com:7051 --output json + ``` + + If successful, the command will return the chaincodes you have installed as JSON. + + ``` + { + "installed_chaincodes": [ + { + "package_id": "mycc_1:aab9981fa5649cfe25369fce7bb5086a69672a631e4f95c4af1b5198fe9f845b", + "label": "mycc_1", + "references": { + "mychannel": { + "chaincodes": [ + { + "name": "mycc", + "version": "1" + } + ] + } + } + } + ] + } + ``` + +### peercli lifecycle chaincode getinstalledpackage example + +You can retrieve an installed chaincode package from a peer using the +`peercli lifecycle chaincode getinstalledpackage` command. Use the package +identifier returned by `queryinstalled`. + + * Use the `--package-id` flag to pass in the chaincode package identifier. Use + the `--output-directory` flag to specify where to write the chaincode package. + If the output directory is not specified, the chaincode package will be written + in the current directory. + + ``` + peercli lifecycle chaincode getinstalledpackage --package-id myccv1:a7ca45a7cc85f1d89c905b775920361ed089a364e12a9b6d55ba75c965ddd6a9 --output-directory /tmp --peerAddresses peer0.org1.example.com:7051 + ``` + +### peercli lifecycle chaincode calculatepackageid example + +You can calculate the package ID from a packaged chaincode without installing the chaincode on peers +using the `peercli lifecycle chaincode calculatepackageid` command. +This command will be useful, for example, in the following cases: + + * When multiple chaincode packages with the same label name are installed, + it is possible to identify which ID corresponds to which package later. + * To check whether a particular chaincode package is installed or not without + installing that package. + +Calculate the package ID for the `mycc.tar.gz` package: + +``` +peercli lifecycle chaincode calculatepackageid mycc.tar.gz +``` + +A successful command will return the package ID for the packaged chaincode. + +``` +myccv1:cc7bb5f50a53c207f68d37e9423c32f968083282e5ffac00d41ffc5768dc1873 +``` + + * You can also use the `--output` flag to have the peercli format the output as JSON. + + ``` + peercli lifecycle chaincode calculatepackageid mycc.tar.gz --output json + ``` + + If successful, the command will return the chaincode package ID as JSON. + + ``` + { + "package_id": "myccv1:cc7bb5f50a53c207f68d37e9423c32f968083282e5ffac00d41ffc5768dc1873" + } + ``` + +### peercli lifecycle chaincode approveformyorg example + +Once the chaincode package has been installed on your peers, you can approve +a chaincode definition for your organization. The chaincode definition includes +the important parameters of chaincode governance, including the chaincode name, +version and the endorsement policy. + +Here is an example of the `peercli lifecycle chaincode approveformyorg` command, +which approves the definition of a chaincode named `mycc` at version `1.0` on +channel `mychannel`. + + * Use the `--package-id` flag to pass in the chaincode package identifier. Use + the `--signature-policy` flag to define an endorsement policy for the chaincode. + Use the `init-required` flag to require the execution of an initialization function + before other chaincode functions can be called. + + ``` + export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem + + peercli lifecycle chaincode approveformyorg -o orderer.example.com:7050 --tls --cafile $ORDERER_CA --channelID mychannel --name mycc --version 1.0 --init-required --package-id myccv1:a7ca45a7cc85f1d89c905b775920361ed089a364e12a9b6d55ba75c965ddd6a9 --sequence 1 --signature-policy "AND ('Org1MSP.peer','Org2MSP.peer')" + + 2019-03-18 16:04:09.046 UTC [peercli.lifecycle.chaincode] InitCmdFactory -> INFO 001 Retrieved channel (mychannel) orderer endpoint: orderer.example.com:7050 + 2019-03-18 16:04:11.253 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [efba188ca77889cc1c328fc98e0bb12d3ad0abcda3f84da3714471c7c1e6c13c] committed with status (VALID) at peer0.org1.example.com:7051 + ``` + + * You can also use the `--channel-config-policy` flag use a policy inside + the channel configuration as the chaincode endorsement policy. The default + endorsement policy is `Channel/Application/Endorsement` + + ``` + export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem + + peercli lifecycle chaincode approveformyorg -o orderer.example.com:7050 --tls --cafile $ORDERER_CA --channelID mychannel --name mycc --version 1.0 --init-required --package-id myccv1:a7ca45a7cc85f1d89c905b775920361ed089a364e12a9b6d55ba75c965ddd6a9 --sequence 1 --channel-config-policy Channel/Application/Admins + + 2019-03-18 16:04:09.046 UTC [peercli.lifecycle.chaincode] InitCmdFactory -> INFO 001 Retrieved channel (mychannel) orderer endpoint: orderer.example.com:7050 + 2019-03-18 16:04:11.253 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [efba188ca77889cc1c328fc98e0bb12d3ad0abcda3f84da3714471c7c1e6c13c] committed with status (VALID) at peer0.org1.example.com:7051 + ``` + +### peercli lifecycle chaincode queryapproved example + +You can query organization's approved chaincode definitions by using the `peercli lifecycle chaincode queryapproved` command. +You can use this command to see the details (including package ID) of approved chaincode definitions. + + * Here is an example of the `peercli lifecycle chaincode queryapproved` command, + which queries the approved definition of a chaincode named `mycc` at sequence number `1` on + channel `mychannel`. + + ``` + peercli lifecycle chaincode queryapproved -C mychannel -n mycc --sequence 1 + + Approved chaincode definition for chaincode 'mycc' on channel 'mychannel': + sequence: 1, version: 1, init-required: true, package-id: mycc_1:d02f72000e7c0f715840f51cb8d72d70bc1ba230552f8445dded0ec8b6e0b830, endorsement plugin: escc, validation plugin: vscc + ``` + + If NO package is specified for the approved definition, this command will display an empty package ID. + + * You can also use this command without specifying the sequence number in order to query the latest approved definition (latest: the newer of the currently defined sequence number and the next sequence number). + + ``` + peercli lifecycle chaincode queryapproved -C mychannel -n mycc + + Approved chaincode definition for chaincode 'mycc' on channel 'mychannel': + sequence: 3, version: 3, init-required: false, package-id: mycc_1:d02f72000e7c0f715840f51cb8d72d70bc1ba230552f8445dded0ec8b6e0b830, endorsement plugin: escc, validation plugin: vscc + ``` + * You can also specify just the channel name in order to query all approved chaincode definitions on that channel. + + ``` + peercli lifecycle chaincode queryapproved -C mychannel + + Approved chaincode definitions on channel 'mychannel': + name: basic2, sequence: 2, version: 2.0.1, init-required: false, package-id: basic2_2.0.1:e916ea95517939e1fed9d9bf3b4179b5a301a9fe303d447d9d79220666ff15ff, endorsement plugin: escc, validation plugin: vscc + name: basic, sequence: 1, version: 1.0.1, init-required: false, package-id: basic_1.0.1:f4babb5fd92c0ab4bce8c6ac30ca7bbb4a55e6c37774582d11639b6036ae0273, endorsement plugin: escc, validation plugin: vscc + name: basic2, sequence: 1, version: 1.0.1, init-required: false, package-id: basic2_1.0.1.1:dae4dca432d56265e87e6416b602b40e94e7f7cdc177031abda1c81d9ed4258a, endorsement plugin: escc, validation plugin: vscc + ``` + + * You can also use the `--output` flag to have the peercli format the output as + JSON. + + - When querying an approved chaincode definition for which package is specified + + ``` + peercli lifecycle chaincode queryapproved -C mychannel -n mycc --sequence 1 --output json + ``` + + If successful, the command will return a JSON that has the approved chaincode definition for chaincode `mycc` at sequence number `1` on channel `mychannel`. + + ``` + { + "sequence": 1, + "version": "1", + "endorsement_plugin": "escc", + "validation_plugin": "vscc", + "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==", + "collections": {}, + "init_required": true, + "source": { + "Type": { + "LocalPackage": { + "package_id": "mycc_1:d02f72000e7c0f715840f51cb8d72d70bc1ba230552f8445dded0ec8b6e0b830" + } + } + } + } + ``` + + - When querying an approved chaincode definition for which package is NOT specified + + ``` + peercli lifecycle chaincode queryapproved -C mychannel -n mycc --sequence 2 --output json + ``` + + If successful, the command will return a JSON that has the approved chaincode definition for chaincode `mycc` at sequence number `2` on channel `mychannel`. + + ``` + { + "sequence": 2, + "version": "2", + "endorsement_plugin": "escc", + "validation_plugin": "vscc", + "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==", + "collections": {}, + "source": { + "Type": { + "Unavailable": {} + } + } + } + ``` + + - For querying all approved definitions on that channel + + ``` + peercli lifecycle chaincode queryapproved -C mychannel --output json + ``` + + If successful, the command will return a JSON that has approved chaincode definitions on channel 'mychannel'. + + ``` + { + "approved_chaincode_definitions": [ + { + "name": "basic2", + "sequence": 2, + "version": "2.0.1", + "endorsement_plugin": "escc", + "validation_plugin": "vscc", + "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==", + "collections": {}, + "source": { + "Type": { + "LocalPackage": { + "package_id": "basic2_2.0.1:e916ea95517939e1fed9d9bf3b4179b5a301a9fe303d447d9d79220666ff15ff" + } + } + } + }, + { + "name": "basic", + "sequence": 1, + "version": "1.0.1", + "endorsement_plugin": "escc", + "validation_plugin": "vscc", + "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==", + "collections": {}, + "source": { + "Type": { + "LocalPackage": { + "package_id": "basic_1.0.1:f4babb5fd92c0ab4bce8c6ac30ca7bbb4a55e6c37774582d11639b6036ae0273" + } + } + } + }, + { + "name": "basic2", + "sequence": 1, + "version": "1.0.1", + "endorsement_plugin": "escc", + "validation_plugin": "vscc", + "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==", + "collections": {}, + "source": { + "Type": { + "LocalPackage": { + "package_id": "basic2_1.0.1:dae4dca432d56265e87e6416b602b40e94e7f7cdc177031abda1c81d9ed4258a" + } + } + } + } + ] + } + ``` + +### peercli lifecycle chaincode checkcommitreadiness example + +You can check whether a chaincode definition is ready to be committed using the +`peercli lifecycle chaincode checkcommitreadiness` command, which will return +successfully if a subsequent commit of the definition is expected to succeed. It +also outputs which organizations have approved the chaincode definition. If an +organization has approved the chaincode definition specified in the command, the +command will return a value of true. You can use this command to learn whether enough +channel members have approved a chaincode definition to meet the +`/Channel/Application/Endorsement` policy (a majority by default) before the +definition can be committed to a channel. + + * Here is an example of the `peercli lifecycle chaincode checkcommitreadiness` command, + which checks a chaincode named `mycc` at version `1.0` on channel `mychannel`. + + ``` + peercli lifecycle chaincode checkcommitreadiness --channelID mychannel --name mycc --version 1.0 --init-required --sequence 1 + ``` + + If successful, the command will return the organizations that have approved + the chaincode definition. + + ``` + Chaincode definition for chaincode 'mycc', version '1.0', sequence '1' on channel + 'mychannel' approval status by org: + Org1MSP: true + Org2MSP: true + ``` + + * You can also use the `--output` flag to have the peercli format the output as + JSON. + + ``` + peercli lifecycle chaincode checkcommitreadiness --channelID mychannel --name mycc --version 1.0 --init-required --sequence 1 --output json + ``` + + If successful, the command will return a JSON map that shows if an organization + has approved the chaincode definition. + + ``` + { + "Approvals": { + "Org1MSP": true, + "Org2MSP": true + } + } + ``` + + * You can also use the `--inspect` flag to output additional information to identify the cause when the approval from each organization is false. This will facilitate root cause analysis and streamline inter-organizational coordination during operations. + + ``` + peercli lifecycle chaincode checkcommitreadiness --channelID mychannel --name basic --version 1.0 --sequence 1 --inspect + ``` + + If successful, the command will output additional information to identify the cause when the approval from each organization is false. + This example outputs that there is a mismatch with respect to the organization Org2MSP and Org3MSP, respectively, + compared to the chaincode definition specified in the arguments of checkcommitreadiness. + + ``` + Chaincode definition for chaincode 'basic', version '1.0', sequence '1' on channel 'mychannel' approval status by org: + Org1MSP: true + Org2MSP: false (mismatch: [EndorsementInfo, ValidationInfo, Collections]) + Org3MSP: false (mismatch: [ChaincodeParameters]) + ``` + + You can also use the `--inspect` flag and `--output` flag simultaneously. + + ``` + peercli lifecycle chaincode checkcommitreadiness --channelID mychannel --name basic --version 1.0 --sequence 1 --inspect + ``` + + If successful, the command will return a JSON format with mismatches. + + ``` + { + "approvals": { + "Org1MSP": true, + "Org2MSP": false, + "Org3MSP": false + }, + "mismatches": { + "Org2MSP": { + "items": [ + "EndorsementInfo (Check the Version, InitRequired, EndorsementPlugin)", + "ValidationInfo (Check the ValidationParameter, ValidationPlugin)", + "Collections (Check the Collections)" + ] + }, + "Org3MSP": { + "items": [ + "ChaincodeParameters (Check the Sequence, ChaincodeName)" + ] + } + } + } + ``` + + checkcommitreadiness cannot fully retrieve the approved definition information, it will support root cause analysis by providing mismatch information for the following field definitions: + - ChaincodeParameters (Check the Sequence, ChaincodeName) + - EndorsementInfo (Check the Version, InitRequired, EndorsementPlugin) + - ValidationInfo (Check the ValidationParameter, ValidationPlugin) + - Collections (Check the Collections) + +### peercli lifecycle chaincode commit example + +Once a sufficient number of organizations approve a chaincode definition for +their organizations (a majority by default), one organization can commit the +definition the channel using the `peercli lifecycle chaincode commit` command: + + * This command needs to target the peers of other organizations on the channel + to collect their organization endorsement for the definition. + + ``` + export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem + + peercli lifecycle chaincode commit -o orderer.example.com:7050 --channelID mychannel --name mycc --version 1.0 --sequence 1 --init-required --tls --cafile $ORDERER_CA --peerAddresses peer0.org1.example.com:7051 --peerAddresses peer0.org2.example.com:9051 + + 2019-03-18 16:14:27.258 UTC [chaincodeCmd] ClientWait -> INFO 001 txid [b6f657a14689b27d69a50f39590b3949906b5a426f9d7f0dcee557f775e17882] committed with status (VALID) at peer0.org2.example.com:9051 + 2019-03-18 16:14:27.321 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [b6f657a14689b27d69a50f39590b3949906b5a426f9d7f0dcee557f775e17882] committed with status (VALID) at peer0.org1.example.com:7051 + ``` + +### peercli lifecycle chaincode querycommitted example + +You can query the chaincode definitions that have been committed to a channel by +using the `peercli lifecycle chaincode querycommitted` command. You can use this +command to query the current definition sequence number before upgrading a +chaincode. + + * You need to supply the chaincode name and channel name in order to query a + specific chaincode definition and the organizations that have approved it. + + ``` + peercli lifecycle chaincode querycommitted --channelID mychannel --name mycc --peerAddresses peer0.org1.example.com:7051 + + Committed chaincode definition for chaincode 'mycc' on channel 'mychannel': + Version: 1, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc + Approvals: [Org1MSP: true, Org2MSP: true] + ``` + + * You can also specify just the channel name in order to query all chaincode + definitions on that channel. + + ``` + peercli lifecycle chaincode querycommitted --channelID mychannel --peerAddresses peer0.org1.example.com:7051 + + Committed chaincode definitions on channel 'mychannel': + Name: mycc, Version: 1, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc + Name: yourcc, Version: 2, Sequence: 3, Endorsement Plugin: escc, Validation Plugin: vscc + ``` + + * You can also use the `--output` flag to have the peercli format the output as + JSON. + + - For querying a specific chaincode definition + + ``` + peercli lifecycle chaincode querycommitted --channelID mychannel --name mycc --peerAddresses peer0.org1.example.com:7051 --output json + ``` + + If successful, the command will return a JSON that has committed chaincode definition for chaincode 'mycc' on channel 'mychannel'. + + ``` + { + "sequence": 1, + "version": "1", + "endorsement_plugin": "escc", + "validation_plugin": "vscc", + "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==", + "collections": {}, + "init_required": true, + "approvals": { + "Org1MSP": true, + "Org2MSP": true + } + } + ``` + + The `validation_parameter` is base64 encoded. An example of the command to decode it is as follows. + + ``` + echo EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA== | base64 -d + + /Channel/Application/Endorsement + ``` + + - For querying all chaincode definitions on that channel + + ``` + peercli lifecycle chaincode querycommitted --channelID mychannel --peerAddresses peer0.org1.example.com:7051 --output json + ``` + + If successful, the command will return a JSON that has committed chaincode definitions on channel 'mychannel'. + + ``` + { + "chaincode_definitions": [ + { + "name": "mycc", + "sequence": 1, + "version": "1", + "endorsement_plugin": "escc", + "validation_plugin": "vscc", + "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==", + "collections": {}, + "init_required": true + }, + { + "name": "yourcc", + "sequence": 3, + "version": "2", + "endorsement_plugin": "escc", + "validation_plugin": "vscc", + "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==", + "collections": {} + } + ] + } + ``` + + +Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License. diff --git a/docs/source/commands/peerclisnapshot.md b/docs/source/commands/peerclisnapshot.md new file mode 100644 index 00000000000..3a5a5340edd --- /dev/null +++ b/docs/source/commands/peerclisnapshot.md @@ -0,0 +1,129 @@ + + +# peercli snapshot + +The `peercli snapshot` command allows administrators to perform snapshot related +operations on a peer, such as submit a snapshot request, cancel a snapshot request +and list pending requests. Once a snapshot request is submitted for a specified +block number, the snapshot will be automatically generated when the block number is +committed on the channel. + +## Syntax + +The `peercli snapshot` command has the following subcommands: + + * cancelrequest + * listpending + * submitrequest + +## peercli snapshot cancelrequest +``` +Cancel a request for a snapshot at the specified block. + +Usage: + peercli snapshot cancelrequest [flags] + +Flags: + -b, --blockNumber uint The block number for which a snapshot will be generated + -c, --channelID string The channel on which this command should be executed + -h, --help help for cancelrequest + --peerAddress string The address of the peer to connect to + --tlsRootCertFile string The path to the TLS root cert file of the peer to connect to, required if TLS is enabled and ignored if TLS is disabled. +``` + + +## peercli snapshot listpending +``` +List pending requests for snapshots. + +Usage: + peercli snapshot listpending [flags] + +Flags: + -c, --channelID string The channel on which this command should be executed + -h, --help help for listpending + --peerAddress string The address of the peer to connect to + --tlsRootCertFile string The path to the TLS root cert file of the peer to connect to, required if TLS is enabled and ignored if TLS is disabled. +``` + + +## peercli snapshot submitrequest +``` +Submit a request for a snapshot at the specified block. When the blockNumber parameter is set to 0 or not provided, it will submit a request for the last committed block. + +Usage: + peercli snapshot submitrequest [flags] + +Flags: + -b, --blockNumber uint The block number for which a snapshot will be generated + -c, --channelID string The channel on which this command should be executed + -h, --help help for submitrequest + --peerAddress string The address of the peer to connect to + --tlsRootCertFile string The path to the TLS root cert file of the peer to connect to, required if TLS is enabled and ignored if TLS is disabled. +``` + +## Example Usage + +### peercli snapshot cancelrequest example + +Here is an example of the `peercli snapshot cancelrequest` command. + + * Cancel a snapshot request for block number 1000 on channel `mychannel` + for `peer0.org1.example.com:7051`: + + ``` + peercli snapshot cancelrequest -c mychannel -b 1000 --peerAddress peer0.org1.example.com:7051 + + Snapshot request cancelled successfully + + ``` + + A successful response indicates that the snapshot request for block number 1000 has been removed from `mychannel`. + If there is no pending snapshot request for block number 1000, the command will return an error. + + * Use the `--tlsRootCertFile` flag in a network with TLS enabled + +### peercli snapshot listpending example + +Here is an example of the `peercli snapshot listpending` command. +If a snapshot is already generated, the corresponding block number will be removed from the pending list. + + * List pending snapshot requests on channel `mychannel` + for `peer0.org1.example.com:7051`: + + ``` + peercli snapshot listpending -c mychannel --peerAddress peer0.org1.example.com:7051 + + Successfully got pending snapshot requests: [1000 5000] + + ``` + + You can see that the command returns a list of block numbers for the pending snapshot requests. + + * Use the `--tlsRootCertFile` flag in a network with TLS enabled + +### peercli snapshot submitrequest example + +Here is an example of the `peercli snapshot submitrequest` command. + + * Submit a snapshot request for block number 1000 on channel `mychannel` + for `peer0.org1.example.com:7051`: + + ``` + peercli snapshot submitrequest -c mychannel -b 1000 --peerAddress peer0.org1.example.com:7051 + + Snapshot request submitted successfully + + ``` + + You can see that the snapshot request is successfully submitted on channel `mychannel`. + A snapshot will be automatically generated after the block number 1000 is committed on the channel. + + The specified block number must be at or above the last block number on the channel. + Otherwise, the command will return an error. + + * Use the `--tlsRootCertFile` flag in a network with TLS enabled + diff --git a/docs/source/commands/peercliversion.md b/docs/source/commands/peercliversion.md new file mode 100644 index 00000000000..c78fa767780 --- /dev/null +++ b/docs/source/commands/peercliversion.md @@ -0,0 +1,39 @@ + + +# peercli version + +The `peercli version` command displays the version information of the peercli. It +displays version, Commit SHA, Go version, OS/architecture, and chaincode +information. For example: + +``` + peercli: + Version: 2.1.0 + Commit SHA: b78d79b + Go version: go1.14.1 + OS/Arch: linux/amd64 + Chaincode: + Base Docker Label: org.hyperledger.fabric + Docker Namespace: hyperledger +``` + +## Syntax + +The `peercli version` command takes no arguments. + +## peercli version +``` +Print current version of the fabric peer server. + +Usage: + peercli version [flags] + +Flags: + -h, --help help for version +``` + + +Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License. diff --git a/docs/source/commands/peerlifecycle.md b/docs/source/commands/peerlifecycle.md index 10ac50eba73..a56ffab5e1e 100644 --- a/docs/source/commands/peerlifecycle.md +++ b/docs/source/commands/peerlifecycle.md @@ -32,13 +32,13 @@ section in this topic. ## peer lifecycle ``` -Perform _lifecycle operations +[DEPRECATED] Perform _lifecycle operations. Instead of this command, use "peercli lifecycle". Usage: peer lifecycle [command] Available Commands: - chaincode Perform chaincode operations: package|install|queryinstalled|getinstalledpackage|calculatepackageid|approveformyorg|queryapproved|checkcommitreadiness|commit|querycommitted + chaincode [DEPRECATED] Perform chaincode operations: package|install|queryinstalled|getinstalledpackage|calculatepackageid|approveformyorg|queryapproved|checkcommitreadiness|commit|querycommitted (use the "peercli lifecycle chaincode"). Flags: -h, --help help for lifecycle @@ -49,22 +49,22 @@ Use "peer lifecycle [command] --help" for more information about a command. ## peer lifecycle chaincode ``` -Perform chaincode operations: package|install|queryinstalled|getinstalledpackage|calculatepackageid|approveformyorg|queryapproved|checkcommitreadiness|commit|querycommitted +[DEPRECATED] Perform chaincode operations: package|install|queryinstalled|getinstalledpackage|calculatepackageid|approveformyorg|queryapproved|checkcommitreadiness|commit|querycommitted. Instead of this command, use "peercli lifecycle chaincode". Usage: peer lifecycle chaincode [command] Available Commands: - approveformyorg Approve the chaincode definition for my org. - calculatepackageid Calculate the package ID for a chaincode. - checkcommitreadiness Check whether a chaincode definition is ready to be committed on a channel. - commit Commit the chaincode definition on the channel. - getinstalledpackage Get an installed chaincode package from a peer. - install Install a chaincode. - package Package a chaincode - queryapproved Query org's approved chaincode definitions from its peer. - querycommitted Query the committed chaincode definitions by channel on a peer. - queryinstalled Query the installed chaincodes on a peer. + approveformyorg [DEPRECATED] Approve the chaincode definition for my org (use the "peercli lifecycle chaincode approveformyorg"). + calculatepackageid [DEPRECATED] Calculate the package ID for a chaincode (use the "peercli lifecycle chaincode calculatepackageid"). + checkcommitreadiness [DEPRECATED] Check whether a chaincode definition is ready to be committed on a channel (use the "peercli lifecycle chaincode checkcommitreadiness"). + commit [DEPRECATED] Commit the chaincode definition on the channel (use the "peercli lifecycle chaincode commit"). + getinstalledpackage [DEPRECATED] Get an installed chaincode package from a peer (use the "peercli lifecycle chaincode getinstalledpackage"). + install [DEPRECATED] Install a chaincode (use the "peercli lifecycle chaincode install"). + package [DEPRECATED] Package a chaincode (use the "peercli lifecycle chaincode package"). + queryapproved [DEPRECATED] Query org's approved chaincode definitions from its peer (use the "peercli lifecycle chaincode queryapproved"). + querycommitted [DEPRECATED] Query the committed chaincode definitions by channel on a peer (use the "peercli lifecycle chaincode querycommitted"). + queryinstalled [DEPRECATED] Query the installed chaincodes on a peer (use the "peercli lifecycle chaincode queryinstalled"). Flags: --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint @@ -84,7 +84,7 @@ Use "peer lifecycle chaincode [command] --help" for more information about a com ## peer lifecycle chaincode package ``` -Package a chaincode and write the package to a file. +[DEPRECATED] Package a chaincode and write the package to a file. Instead of this command, use "peercli lifecycle chaincode package". Usage: peer lifecycle chaincode package [outputfile] [flags] @@ -113,7 +113,7 @@ Global Flags: ## peer lifecycle chaincode install ``` -Install a chaincode on a peer. +[DEPRECATED] Install a chaincode on a peer. Instead of this command, use "peercli lifecycle chaincode install". Usage: peer lifecycle chaincode install [packageFile] [flags] @@ -140,7 +140,7 @@ Global Flags: ## peer lifecycle chaincode queryinstalled ``` -Query the installed chaincodes on a peer. +[DEPRECATED] Query the installed chaincodes on a peer. Instead of this command, use "peercli lifecycle chaincode queryinstalled". Usage: peer lifecycle chaincode queryinstalled [flags] @@ -168,7 +168,7 @@ Global Flags: ## peer lifecycle chaincode getinstalledpackage ``` -Get an installed chaincode package from a peer. +[DEPRECATED] Get an installed chaincode package from a peer. Instead of this command, use "peercli lifecycle chaincode getinstalledpackage". Usage: peer lifecycle chaincode getinstalledpackage [outputfile] [flags] @@ -197,7 +197,7 @@ Global Flags: ## peer lifecycle chaincode calculatepackageid ``` -Calculate the package ID for a packaged chaincode. +[DEPRECATED] Calculate the package ID for a packaged chaincode. Instead of this command, use "peercli lifecycle chaincode calculatepackageid". Usage: peer lifecycle chaincode calculatepackageid [packageFile] [flags] @@ -224,7 +224,7 @@ Global Flags: ## peer lifecycle chaincode approveformyorg ``` -Approve the chaincode definition for my organization. +[DEPRECATED] Approve the chaincode definition for my organization. Instead of this command, use "peercli lifecycle chaincode approveformyorg". Usage: peer lifecycle chaincode approveformyorg [flags] @@ -263,7 +263,7 @@ Global Flags: ## peer lifecycle chaincode queryapproved ``` -Query organization's approved chaincode definitions from its peer. +[DEPRECATED] Query organization's approved chaincode definitions from its peer. Instead of this command, use "peercli lifecycle chaincode queryapproved". Usage: peer lifecycle chaincode queryapproved [flags] @@ -293,7 +293,7 @@ Global Flags: ## peer lifecycle chaincode checkcommitreadiness ``` -Check whether a chaincode definition is ready to be committed on a channel. +[DEPRECATED] Check whether a chaincode definition is ready to be committed on a channel. Instead of this command, use "peercli lifecycle chaincode checkcommitreadiness". Usage: peer lifecycle chaincode checkcommitreadiness [flags] @@ -331,7 +331,7 @@ Global Flags: ## peer lifecycle chaincode commit ``` -Commit the chaincode definition on the channel. +[DEPRECATED] Commit the chaincode definition on the channel. Instead of this command, use "peercli lifecycle chaincode commit". Usage: peer lifecycle chaincode commit [flags] @@ -369,7 +369,7 @@ Global Flags: ## peer lifecycle chaincode querycommitted ``` -Query the committed chaincode definitions by channel on a peer. Optional: provide a chaincode name to query a specific definition. +[DEPRECATED] Query the committed chaincode definitions by channel on a peer. Optional: provide a chaincode name to query a specific definition. Instead of this command, use "peercli lifecycle chaincode querycommitted". Usage: peer lifecycle chaincode querycommitted [flags] diff --git a/docs/source/commands/peersnapshot.md b/docs/source/commands/peersnapshot.md index 63a9d41fc78..5acdd553cec 100644 --- a/docs/source/commands/peersnapshot.md +++ b/docs/source/commands/peersnapshot.md @@ -21,7 +21,7 @@ The `peer snapshot` command has the following subcommands: ## peer snapshot cancelrequest ``` -Cancel a request for a snapshot at the specified block. +[DEPRECATED] Cancel a request for a snapshot at the specified block. Instead of this command, use "peercli snapshot cancelrequest". Usage: peer snapshot cancelrequest [flags] @@ -37,7 +37,7 @@ Flags: ## peer snapshot listpending ``` -List pending requests for snapshots. +[DEPRECATED] List pending requests for snapshots. Instead of this command, use "peercli snapshot listpending". Usage: peer snapshot listpending [flags] @@ -52,7 +52,7 @@ Flags: ## peer snapshot submitrequest ``` -Submit a request for a snapshot at the specified block. When the blockNumber parameter is set to 0 or not provided, it will submit a request for the last committed block. +[DEPRECATED] Submit a request for a snapshot at the specified block. When the blockNumber parameter is set to 0 or not provided, it will submit a request for the last committed block. Instead of this command, use "peercli snapshot submitrequest". Usage: peer snapshot submitrequest [flags] diff --git a/docs/wrappers/peercli_chaincode_postscript.md b/docs/wrappers/peercli_chaincode_postscript.md new file mode 100644 index 00000000000..7ab3c525861 --- /dev/null +++ b/docs/wrappers/peercli_chaincode_postscript.md @@ -0,0 +1,67 @@ +## Example Usage + +### peercli chaincode invoke example + +Here is an example of the `peercli chaincode invoke` command: + + * Invoke the chaincode named `mycc` at version `1.0` on channel `mychannel` + on `peer0.org1.example.com:7051` and `peer0.org2.example.com:9051` (the + peers defined by `--peerAddresses`), requesting to move 10 units from + variable `a` to variable `b`: + + ``` + peercli chaincode invoke -o orderer.example.com:7050 -C mychannel -n mycc --peerAddresses peer0.org1.example.com:7051 --peerAddresses peer0.org2.example.com:9051 -c '{"Args":["invoke","a","b","10"]}' + + 2018-02-22 16:34:27.069 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc + 2018-02-22 16:34:27.069 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc + . + . + . + 2018-02-22 16:34:27.106 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> DEBU 00a ESCC invoke result: version:1 response: payload:"\n \237mM\376? [\214\002 \332\204\035\275q\227\2132A\n\204&\2106\037W|\346#\3413\274\022Y\nE\022\024\n\004lscc\022\014\n\n\n\004mycc\022\002\010\003\022-\n\004mycc\022%\n\007\n\001a\022\002\010\003\n\007\n\001b\022\002\010\003\032\007\n\001a\032\00290\032\010\n\001b\032\003210\032\003\010\310\001\"\013\022\004mycc\032\0031.0" endorsement: + 2018-02-22 16:34:27.107 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 00b Chaincode invoke successful. result: status:200 + 2018-02-22 16:34:27.107 UTC [main] main -> INFO 00c Exiting..... + + ``` + + Here you can see that the invoke was submitted successfully based on the log + message: + + ``` + 2018-02-22 16:34:27.107 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 00b Chaincode invoke successful. result: status:200 + + ``` + + A successful response indicates that the transaction was submitted for ordering + successfully. The transaction will then be added to a block and, finally, validated + or invalidated by each peer on the channel. + +Here is an example of how to format the `peercli chaincode invoke` command when the chaincode package includes multiple smart contracts. + + * If you are using the [contract-api](https://www.npmjs.com/package/fabric-contract-api), the name you pass to `super("MyContract")` can be used as a prefix. + + ``` + peercli chaincode invoke -C $CHANNEL_NAME -n $CHAINCODE_NAME -c '{ "Args": ["MyContract:methodName", "{}"] }' + + peercli chaincode invoke -C $CHANNEL_NAME -n $CHAINCODE_NAME -c '{ "Args": ["MyOtherContract:methodName", "{}"] }' + + ``` + +### peercli chaincode query example + +Here is an example of the `peercli chaincode query` command, which queries the +peer ledger for the chaincode named `mycc` at version `1.0` for the value of +variable `a`: + + * You can see from the output that variable `a` had a value of 90 at the time of + the query. + + ``` + peercli chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}' + + 2018-02-22 16:34:30.816 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc + 2018-02-22 16:34:30.816 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc + Query Result: 90 + + ``` + +Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License. diff --git a/docs/wrappers/peercli_chaincode_preamble.md b/docs/wrappers/peercli_chaincode_preamble.md new file mode 100644 index 00000000000..cf109f84185 --- /dev/null +++ b/docs/wrappers/peercli_chaincode_preamble.md @@ -0,0 +1,71 @@ +# peercli chaincode + +The `peercli chaincode` command allows users to invoke and query chaincode. + +## Syntax + +The `peercli chaincode` command has the following subcommands: + + * invoke + * query + +The subcommands take a constructor flag (`-c` or `--ctor`) to pass arguments to a chaincode. +The value must be a JSON string that has either key 'Args' or 'Function' and 'Args'. +These keys are case-insensitive. + +If the constructor JSON string only has the Args key, the key value is an array, where the +first array element is the target function to call, and the subsequent elements +are arguments of the function. If the JSON string has both 'Function' and +'Args', the value of Function is the target function to call, and the value of +Args is an array of arguments of the function. For instance, +`{"Args":["GetAllAssets"]}` is equivalent to +`{"Function":"GetAllAssets", "Args":[]}`. + +Each peercli chaincode subcommand is described together with its options in its own +section in this topic. + +## Flags + +Each `peercli chaincode` subcommand has both a set of flags specific to an +individual subcommand, as well as a set of global flags that relate to all +`peercli chaincode` subcommands. Not all subcommands would use these flags. +For instance, the `query` subcommand does not need the `--orderer` flag. + +The individual flags are described with the relevant subcommand. The global +flags are + +* `--cafile ` + + Path to file containing PEM-encoded trusted certificate(s) for the ordering + endpoint + +* `--certfile ` + + Path to file containing PEM-encoded X509 public key to use for mutual TLS + communication with the orderer endpoint + +* `--keyfile ` + + Path to file containing PEM-encoded private key to use for mutual TLS + communication with the orderer endpoint + +* `-o` or `--orderer ` + + Ordering service endpoint specified as `:` + +* `--ordererTLSHostnameOverride ` + + The hostname override to use when validating the TLS connection to the orderer + +* `--tls` + + Use TLS when communicating with the orderer endpoint + +* `--transient ` + + Transient map of arguments in JSON encoding + +Flags of type stringArray are to be repeated rather than concatenating their +values. For example, you will use `--peerAddresses localhost:9051 +--peerAddresses localhost:7051` rather than `--peerAddresses "localhost:9051 +localhost:7051"`. diff --git a/docs/wrappers/peercli_channel_postscript.md b/docs/wrappers/peercli_channel_postscript.md new file mode 100644 index 00000000000..e4d1758c859 --- /dev/null +++ b/docs/wrappers/peercli_channel_postscript.md @@ -0,0 +1,181 @@ +## Example Usage + +### peercli channel fetch example + +Here's some examples of the `peercli channel fetch` command. + +* Using the `newest` option to retrieve the most recent channel block, and + store it in the file `mychannel.block`. + + ``` + peercli channel fetch newest mychannel.block -c mychannel + + 2018-02-25 13:10:16.137 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized + 2018-02-25 13:10:16.144 UTC [channelCmd] readBlock -> INFO 00a Received block: 32 + 2018-02-25 13:10:16.145 UTC [main] main -> INFO 00b Exiting..... + + ls -l + + -rw-r--r-- 1 root root 11982 Feb 25 13:10 mychannel.block + + ``` + + You can see that the retrieved block is number 32, and that the information + has been written to the file `mychannel.block`. + +* Using the `(block number)` option to retrieve a specific block -- in this + case, block number 16 -- and store it in the default block file. + + ``` + peercli channel fetch 16 -c mychannel + + 2018-02-25 13:46:50.296 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized + 2018-02-25 13:46:50.302 UTC [channelCmd] readBlock -> INFO 00a Received block: 16 + 2018-02-25 13:46:50.302 UTC [main] main -> INFO 00b Exiting..... + + ls -l + + -rw-r--r-- 1 root root 11982 Feb 25 13:10 mychannel.block + -rw-r--r-- 1 root root 4783 Feb 25 13:46 mychannel_16.block + + ``` + + You can see that the retrieved block is number 16, and that the information + has been written to the default file `mychannel_16.block`. + + For configuration blocks, the block file can be decoded using the + [`configtxlator` command](./configtxlator.html). See this command for an example + of decoded output. User transaction blocks can also be decoded, but a user + program must be written to do this. + +### peercli channel getinfo example + +Here's an example of the `peercli channel getinfo` command. + +* Get information about the local peer for channel `mychannel`. + + ``` + peercli channel getinfo -c mychannel + + 2018-02-25 15:15:44.135 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized + Blockchain info: {"height":5,"currentBlockHash":"JgK9lcaPUNmFb5Mp1qe1SVMsx3o/22Ct4+n5tejcXCw=","previousBlockHash":"f8lZXoAn3gF86zrFq7L1DzW2aKuabH9Ow6SIE5Y04a4="} + 2018-02-25 15:15:44.139 UTC [main] main -> INFO 006 Exiting..... + + ``` + + You can see that the latest block for channel `mychannel` is block 5. You + can also see the cryptographic hashes for the most recent blocks in the + channel's blockchain. + +### peercli channel join example + +Here's an example of the `peercli channel join` command. + +* Join a peer to the channel defined in the genesis block identified by the file + `./mychannel.genesis.block`. In this example, the channel block was + previously retrieved by the `peercli channel fetch` command. + + ``` + peercli channel join -b ./mychannel.genesis.block + + 2018-02-25 12:25:26.511 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized + 2018-02-25 12:25:26.571 UTC [channelCmd] executeJoin -> INFO 006 Successfully submitted proposal to join channel + 2018-02-25 12:25:26.571 UTC [main] main -> INFO 007 Exiting..... + + ``` + + You can see that the peer has successfully made a request to join the channel. + +### peercli channel joinbysnapshot example + +Here's an example of the `peercli channel joinbysnapshot` command. + +* Join a peer to the channel from a snapshot identified by the directory + `/snapshots/completed/testchannel/1000`. The snapshot was previously created on a different peer. + + ``` + peercli channel joinbysnapshot --snapshotpath /snapshots/completed/testchannel/1000 + + 2020-10-12 11:41:45.442 EDT [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized + 2020-10-12 11:41:45.444 EDT [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel + 2020-10-12 11:41:45.444 EDT [channelCmd] joinBySnapshot -> INFO 003 The joinbysnapshot operation is in progress. Use "peercli channel joinbysnapshotstatus" to check the status. + + ``` + + You can see that the peer has successfully made a request to join the channel from the specified snapshot. + When a `joinbysnapshot` operation is in progress, you cannot run another `peercli channel join` + or `peercli channel joinbysnapshot` simultaneously. To know whether or not a joinbysnapshot operation is in progress, + you can call the `peercli channel joinbysnapshotstatus` command. + + +### peercli channel joinbysnapshotstatus example + +Here are some examples of the `peercli channel joinbysnapshotstatus` command. + +* Query if joinbysnapshot is in progress for any channel. If yes, + it returns a message indicating a joinbysnapshot operation is in progress. + + ``` + peercli channel joinbysnapshotstatus + + 2020-10-12 11:41:45.952 EDT [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized + A joinbysnapshot operation is in progress for snapshot at /snapshots/completed/testchannel/1000 + ``` + +* If no `joinbysnapshot` operation is in progress, it returns a message indicating no joinbysnapshot operation is in progress. + + ``` + peercli channel joinbysnapshotstatus + + 2020-10-12 11:41:47.922 EDT [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized + No joinbysnapshot operation is in progress + + ``` + +### peercli channel list example + + Here's an example of the `peercli channel list` command. + + * List the channels to which a peer is joined. + + ``` + peercli channel list + + 2018-02-25 14:21:20.361 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized + Channels peers has joined: + mychannel + 2018-02-25 14:21:20.372 UTC [main] main -> INFO 006 Exiting..... + + ``` + + You can see that the peer is joined to channel `mychannel`. + +### peercli channel signconfigtx example + +Here's an example of the `peercli channel signconfigtx` command. + +* Sign the `channel update` transaction defined in the file + `./updatechannel.tx`. The example lists the configuration transaction file + before and after the command. + + ``` + ls -l + + -rw-r--r-- 1 anthonyodowd staff 284 25 Feb 18:16 updatechannel.tx + + peercli channel signconfigtx -f updatechannel.tx + + 2018-02-25 18:16:44.456 GMT [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized + 2018-02-25 18:16:44.459 GMT [main] main -> INFO 002 Exiting..... + + ls -l + + -rw-r--r-- 1 anthonyodowd staff 2180 25 Feb 18:16 updatechannel.tx + + ``` + + You can see that the peer has successfully signed the configuration + transaction by the increase in the size of the file `updatechannel.tx` from + 284 bytes to 2180 bytes. + +Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License. diff --git a/docs/wrappers/peercli_channel_preamble.md b/docs/wrappers/peercli_channel_preamble.md new file mode 100644 index 00000000000..6f8b6aacf58 --- /dev/null +++ b/docs/wrappers/peercli_channel_preamble.md @@ -0,0 +1,17 @@ +# peercli channel + +The `peercli channel` command allows administrators to perform channel related +operations on a peer, such as joining a channel or listing the channels to which +a peer is joined. + +## Syntax + +The `peercli channel` command has the following subcommands: + + * fetch + * getinfo + * join + * joinbysnapshot + * joinbysnapshotstatus + * list + * signconfigtx diff --git a/docs/wrappers/peercli_lifecycle_chaincode_postscript.md b/docs/wrappers/peercli_lifecycle_chaincode_postscript.md new file mode 100644 index 00000000000..c3d890685b0 --- /dev/null +++ b/docs/wrappers/peercli_lifecycle_chaincode_postscript.md @@ -0,0 +1,551 @@ + +## Example Usage + +### peercli lifecycle chaincode package example + +A chaincode needs to be packaged before it can be installed on your peers. +This example uses the `peercli lifecycle chaincode package` command to package +a Go chaincode. + + * Use the `--path` flag to indicate the location of the chaincode. + The path must be a fully qualified path or a path relative to your present working directory. + * Use the `--label` flag to provide a chaincode package label of `myccv1` + that your organization will use to identify the package. + + ``` + peercli lifecycle chaincode package mycc.tar.gz --path $CHAINCODE_DIR --lang golang --label myccv1 + ``` + +### peercli lifecycle chaincode install example + +After the chaincode is packaged, you can use the `peercli chaincode install` command +to install the chaincode on your peers. + + * Install the `mycc.tar.gz ` package on `peer0.org1.example.com:7051` (the + peer defined by `--peerAddresses`). + + ``` + peercli lifecycle chaincode install mycc.tar.gz --peerAddresses peer0.org1.example.com:7051 + ``` + If successful, the command will return the package identifier. The + package ID is the package label combined with a hash of the chaincode + package taken by the peer. + ``` + 2019-03-13 13:48:53.691 UTC [peercli.lifecycle.chaincode] submitInstallProposal -> INFO 001 Installed remotely: response: + 2019-03-13 13:48:53.691 UTC [peercli.lifecycle.chaincode] submitInstallProposal -> INFO 002 Chaincode code package identifier: mycc:a7ca45a7cc85f1d89c905b775920361ed089a364e12a9b6d55ba75c965ddd6a9 + ``` + +### peercli lifecycle chaincode queryinstalled example + +You need to use the chaincode package identifier to approve a chaincode +definition for your organization. You can find the package ID for the +chaincodes you have installed by using the +`peercli lifecycle chaincode queryinstalled` command: + +``` +peercli lifecycle chaincode queryinstalled --peerAddresses peer0.org1.example.com:7051 +``` + +A successful command will return the package ID associated with the +package label. + +``` +Get installed chaincodes on peer: +Package ID: myccv1:a7ca45a7cc85f1d89c905b775920361ed089a364e12a9b6d55ba75c965ddd6a9, Label: myccv1 +``` + + * You can also use the `--output` flag to have the peercli format the output as + JSON. + + ``` + peercli lifecycle chaincode queryinstalled --peerAddresses peer0.org1.example.com:7051 --output json + ``` + + If successful, the command will return the chaincodes you have installed as JSON. + + ``` + { + "installed_chaincodes": [ + { + "package_id": "mycc_1:aab9981fa5649cfe25369fce7bb5086a69672a631e4f95c4af1b5198fe9f845b", + "label": "mycc_1", + "references": { + "mychannel": { + "chaincodes": [ + { + "name": "mycc", + "version": "1" + } + ] + } + } + } + ] + } + ``` + +### peercli lifecycle chaincode getinstalledpackage example + +You can retrieve an installed chaincode package from a peer using the +`peercli lifecycle chaincode getinstalledpackage` command. Use the package +identifier returned by `queryinstalled`. + + * Use the `--package-id` flag to pass in the chaincode package identifier. Use + the `--output-directory` flag to specify where to write the chaincode package. + If the output directory is not specified, the chaincode package will be written + in the current directory. + + ``` + peercli lifecycle chaincode getinstalledpackage --package-id myccv1:a7ca45a7cc85f1d89c905b775920361ed089a364e12a9b6d55ba75c965ddd6a9 --output-directory /tmp --peerAddresses peer0.org1.example.com:7051 + ``` + +### peercli lifecycle chaincode calculatepackageid example + +You can calculate the package ID from a packaged chaincode without installing the chaincode on peers +using the `peercli lifecycle chaincode calculatepackageid` command. +This command will be useful, for example, in the following cases: + + * When multiple chaincode packages with the same label name are installed, + it is possible to identify which ID corresponds to which package later. + * To check whether a particular chaincode package is installed or not without + installing that package. + +Calculate the package ID for the `mycc.tar.gz` package: + +``` +peercli lifecycle chaincode calculatepackageid mycc.tar.gz +``` + +A successful command will return the package ID for the packaged chaincode. + +``` +myccv1:cc7bb5f50a53c207f68d37e9423c32f968083282e5ffac00d41ffc5768dc1873 +``` + + * You can also use the `--output` flag to have the peercli format the output as JSON. + + ``` + peercli lifecycle chaincode calculatepackageid mycc.tar.gz --output json + ``` + + If successful, the command will return the chaincode package ID as JSON. + + ``` + { + "package_id": "myccv1:cc7bb5f50a53c207f68d37e9423c32f968083282e5ffac00d41ffc5768dc1873" + } + ``` + +### peercli lifecycle chaincode approveformyorg example + +Once the chaincode package has been installed on your peers, you can approve +a chaincode definition for your organization. The chaincode definition includes +the important parameters of chaincode governance, including the chaincode name, +version and the endorsement policy. + +Here is an example of the `peercli lifecycle chaincode approveformyorg` command, +which approves the definition of a chaincode named `mycc` at version `1.0` on +channel `mychannel`. + + * Use the `--package-id` flag to pass in the chaincode package identifier. Use + the `--signature-policy` flag to define an endorsement policy for the chaincode. + Use the `init-required` flag to require the execution of an initialization function + before other chaincode functions can be called. + + ``` + export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem + + peercli lifecycle chaincode approveformyorg -o orderer.example.com:7050 --tls --cafile $ORDERER_CA --channelID mychannel --name mycc --version 1.0 --init-required --package-id myccv1:a7ca45a7cc85f1d89c905b775920361ed089a364e12a9b6d55ba75c965ddd6a9 --sequence 1 --signature-policy "AND ('Org1MSP.peer','Org2MSP.peer')" + + 2019-03-18 16:04:09.046 UTC [peercli.lifecycle.chaincode] InitCmdFactory -> INFO 001 Retrieved channel (mychannel) orderer endpoint: orderer.example.com:7050 + 2019-03-18 16:04:11.253 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [efba188ca77889cc1c328fc98e0bb12d3ad0abcda3f84da3714471c7c1e6c13c] committed with status (VALID) at peer0.org1.example.com:7051 + ``` + + * You can also use the `--channel-config-policy` flag use a policy inside + the channel configuration as the chaincode endorsement policy. The default + endorsement policy is `Channel/Application/Endorsement` + + ``` + export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem + + peercli lifecycle chaincode approveformyorg -o orderer.example.com:7050 --tls --cafile $ORDERER_CA --channelID mychannel --name mycc --version 1.0 --init-required --package-id myccv1:a7ca45a7cc85f1d89c905b775920361ed089a364e12a9b6d55ba75c965ddd6a9 --sequence 1 --channel-config-policy Channel/Application/Admins + + 2019-03-18 16:04:09.046 UTC [peercli.lifecycle.chaincode] InitCmdFactory -> INFO 001 Retrieved channel (mychannel) orderer endpoint: orderer.example.com:7050 + 2019-03-18 16:04:11.253 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [efba188ca77889cc1c328fc98e0bb12d3ad0abcda3f84da3714471c7c1e6c13c] committed with status (VALID) at peer0.org1.example.com:7051 + ``` + +### peercli lifecycle chaincode queryapproved example + +You can query organization's approved chaincode definitions by using the `peercli lifecycle chaincode queryapproved` command. +You can use this command to see the details (including package ID) of approved chaincode definitions. + + * Here is an example of the `peercli lifecycle chaincode queryapproved` command, + which queries the approved definition of a chaincode named `mycc` at sequence number `1` on + channel `mychannel`. + + ``` + peercli lifecycle chaincode queryapproved -C mychannel -n mycc --sequence 1 + + Approved chaincode definition for chaincode 'mycc' on channel 'mychannel': + sequence: 1, version: 1, init-required: true, package-id: mycc_1:d02f72000e7c0f715840f51cb8d72d70bc1ba230552f8445dded0ec8b6e0b830, endorsement plugin: escc, validation plugin: vscc + ``` + + If NO package is specified for the approved definition, this command will display an empty package ID. + + * You can also use this command without specifying the sequence number in order to query the latest approved definition (latest: the newer of the currently defined sequence number and the next sequence number). + + ``` + peercli lifecycle chaincode queryapproved -C mychannel -n mycc + + Approved chaincode definition for chaincode 'mycc' on channel 'mychannel': + sequence: 3, version: 3, init-required: false, package-id: mycc_1:d02f72000e7c0f715840f51cb8d72d70bc1ba230552f8445dded0ec8b6e0b830, endorsement plugin: escc, validation plugin: vscc + ``` + * You can also specify just the channel name in order to query all approved chaincode definitions on that channel. + + ``` + peercli lifecycle chaincode queryapproved -C mychannel + + Approved chaincode definitions on channel 'mychannel': + name: basic2, sequence: 2, version: 2.0.1, init-required: false, package-id: basic2_2.0.1:e916ea95517939e1fed9d9bf3b4179b5a301a9fe303d447d9d79220666ff15ff, endorsement plugin: escc, validation plugin: vscc + name: basic, sequence: 1, version: 1.0.1, init-required: false, package-id: basic_1.0.1:f4babb5fd92c0ab4bce8c6ac30ca7bbb4a55e6c37774582d11639b6036ae0273, endorsement plugin: escc, validation plugin: vscc + name: basic2, sequence: 1, version: 1.0.1, init-required: false, package-id: basic2_1.0.1.1:dae4dca432d56265e87e6416b602b40e94e7f7cdc177031abda1c81d9ed4258a, endorsement plugin: escc, validation plugin: vscc + ``` + + * You can also use the `--output` flag to have the peercli format the output as + JSON. + + - When querying an approved chaincode definition for which package is specified + + ``` + peercli lifecycle chaincode queryapproved -C mychannel -n mycc --sequence 1 --output json + ``` + + If successful, the command will return a JSON that has the approved chaincode definition for chaincode `mycc` at sequence number `1` on channel `mychannel`. + + ``` + { + "sequence": 1, + "version": "1", + "endorsement_plugin": "escc", + "validation_plugin": "vscc", + "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==", + "collections": {}, + "init_required": true, + "source": { + "Type": { + "LocalPackage": { + "package_id": "mycc_1:d02f72000e7c0f715840f51cb8d72d70bc1ba230552f8445dded0ec8b6e0b830" + } + } + } + } + ``` + + - When querying an approved chaincode definition for which package is NOT specified + + ``` + peercli lifecycle chaincode queryapproved -C mychannel -n mycc --sequence 2 --output json + ``` + + If successful, the command will return a JSON that has the approved chaincode definition for chaincode `mycc` at sequence number `2` on channel `mychannel`. + + ``` + { + "sequence": 2, + "version": "2", + "endorsement_plugin": "escc", + "validation_plugin": "vscc", + "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==", + "collections": {}, + "source": { + "Type": { + "Unavailable": {} + } + } + } + ``` + + - For querying all approved definitions on that channel + + ``` + peercli lifecycle chaincode queryapproved -C mychannel --output json + ``` + + If successful, the command will return a JSON that has approved chaincode definitions on channel 'mychannel'. + + ``` + { + "approved_chaincode_definitions": [ + { + "name": "basic2", + "sequence": 2, + "version": "2.0.1", + "endorsement_plugin": "escc", + "validation_plugin": "vscc", + "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==", + "collections": {}, + "source": { + "Type": { + "LocalPackage": { + "package_id": "basic2_2.0.1:e916ea95517939e1fed9d9bf3b4179b5a301a9fe303d447d9d79220666ff15ff" + } + } + } + }, + { + "name": "basic", + "sequence": 1, + "version": "1.0.1", + "endorsement_plugin": "escc", + "validation_plugin": "vscc", + "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==", + "collections": {}, + "source": { + "Type": { + "LocalPackage": { + "package_id": "basic_1.0.1:f4babb5fd92c0ab4bce8c6ac30ca7bbb4a55e6c37774582d11639b6036ae0273" + } + } + } + }, + { + "name": "basic2", + "sequence": 1, + "version": "1.0.1", + "endorsement_plugin": "escc", + "validation_plugin": "vscc", + "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==", + "collections": {}, + "source": { + "Type": { + "LocalPackage": { + "package_id": "basic2_1.0.1:dae4dca432d56265e87e6416b602b40e94e7f7cdc177031abda1c81d9ed4258a" + } + } + } + } + ] + } + ``` + +### peercli lifecycle chaincode checkcommitreadiness example + +You can check whether a chaincode definition is ready to be committed using the +`peercli lifecycle chaincode checkcommitreadiness` command, which will return +successfully if a subsequent commit of the definition is expected to succeed. It +also outputs which organizations have approved the chaincode definition. If an +organization has approved the chaincode definition specified in the command, the +command will return a value of true. You can use this command to learn whether enough +channel members have approved a chaincode definition to meet the +`/Channel/Application/Endorsement` policy (a majority by default) before the +definition can be committed to a channel. + + * Here is an example of the `peercli lifecycle chaincode checkcommitreadiness` command, + which checks a chaincode named `mycc` at version `1.0` on channel `mychannel`. + + ``` + peercli lifecycle chaincode checkcommitreadiness --channelID mychannel --name mycc --version 1.0 --init-required --sequence 1 + ``` + + If successful, the command will return the organizations that have approved + the chaincode definition. + + ``` + Chaincode definition for chaincode 'mycc', version '1.0', sequence '1' on channel + 'mychannel' approval status by org: + Org1MSP: true + Org2MSP: true + ``` + + * You can also use the `--output` flag to have the peercli format the output as + JSON. + + ``` + peercli lifecycle chaincode checkcommitreadiness --channelID mychannel --name mycc --version 1.0 --init-required --sequence 1 --output json + ``` + + If successful, the command will return a JSON map that shows if an organization + has approved the chaincode definition. + + ``` + { + "Approvals": { + "Org1MSP": true, + "Org2MSP": true + } + } + ``` + + * You can also use the `--inspect` flag to output additional information to identify the cause when the approval from each organization is false. This will facilitate root cause analysis and streamline inter-organizational coordination during operations. + + ``` + peercli lifecycle chaincode checkcommitreadiness --channelID mychannel --name basic --version 1.0 --sequence 1 --inspect + ``` + + If successful, the command will output additional information to identify the cause when the approval from each organization is false. + This example outputs that there is a mismatch with respect to the organization Org2MSP and Org3MSP, respectively, + compared to the chaincode definition specified in the arguments of checkcommitreadiness. + + ``` + Chaincode definition for chaincode 'basic', version '1.0', sequence '1' on channel 'mychannel' approval status by org: + Org1MSP: true + Org2MSP: false (mismatch: [EndorsementInfo, ValidationInfo, Collections]) + Org3MSP: false (mismatch: [ChaincodeParameters]) + ``` + + You can also use the `--inspect` flag and `--output` flag simultaneously. + + ``` + peercli lifecycle chaincode checkcommitreadiness --channelID mychannel --name basic --version 1.0 --sequence 1 --inspect + ``` + + If successful, the command will return a JSON format with mismatches. + + ``` + { + "approvals": { + "Org1MSP": true, + "Org2MSP": false, + "Org3MSP": false + }, + "mismatches": { + "Org2MSP": { + "items": [ + "EndorsementInfo (Check the Version, InitRequired, EndorsementPlugin)", + "ValidationInfo (Check the ValidationParameter, ValidationPlugin)", + "Collections (Check the Collections)" + ] + }, + "Org3MSP": { + "items": [ + "ChaincodeParameters (Check the Sequence, ChaincodeName)" + ] + } + } + } + ``` + + checkcommitreadiness cannot fully retrieve the approved definition information, it will support root cause analysis by providing mismatch information for the following field definitions: + - ChaincodeParameters (Check the Sequence, ChaincodeName) + - EndorsementInfo (Check the Version, InitRequired, EndorsementPlugin) + - ValidationInfo (Check the ValidationParameter, ValidationPlugin) + - Collections (Check the Collections) + +### peercli lifecycle chaincode commit example + +Once a sufficient number of organizations approve a chaincode definition for +their organizations (a majority by default), one organization can commit the +definition the channel using the `peercli lifecycle chaincode commit` command: + + * This command needs to target the peers of other organizations on the channel + to collect their organization endorsement for the definition. + + ``` + export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem + + peercli lifecycle chaincode commit -o orderer.example.com:7050 --channelID mychannel --name mycc --version 1.0 --sequence 1 --init-required --tls --cafile $ORDERER_CA --peerAddresses peer0.org1.example.com:7051 --peerAddresses peer0.org2.example.com:9051 + + 2019-03-18 16:14:27.258 UTC [chaincodeCmd] ClientWait -> INFO 001 txid [b6f657a14689b27d69a50f39590b3949906b5a426f9d7f0dcee557f775e17882] committed with status (VALID) at peer0.org2.example.com:9051 + 2019-03-18 16:14:27.321 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [b6f657a14689b27d69a50f39590b3949906b5a426f9d7f0dcee557f775e17882] committed with status (VALID) at peer0.org1.example.com:7051 + ``` + +### peercli lifecycle chaincode querycommitted example + +You can query the chaincode definitions that have been committed to a channel by +using the `peercli lifecycle chaincode querycommitted` command. You can use this +command to query the current definition sequence number before upgrading a +chaincode. + + * You need to supply the chaincode name and channel name in order to query a + specific chaincode definition and the organizations that have approved it. + + ``` + peercli lifecycle chaincode querycommitted --channelID mychannel --name mycc --peerAddresses peer0.org1.example.com:7051 + + Committed chaincode definition for chaincode 'mycc' on channel 'mychannel': + Version: 1, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc + Approvals: [Org1MSP: true, Org2MSP: true] + ``` + + * You can also specify just the channel name in order to query all chaincode + definitions on that channel. + + ``` + peercli lifecycle chaincode querycommitted --channelID mychannel --peerAddresses peer0.org1.example.com:7051 + + Committed chaincode definitions on channel 'mychannel': + Name: mycc, Version: 1, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc + Name: yourcc, Version: 2, Sequence: 3, Endorsement Plugin: escc, Validation Plugin: vscc + ``` + + * You can also use the `--output` flag to have the peercli format the output as + JSON. + + - For querying a specific chaincode definition + + ``` + peercli lifecycle chaincode querycommitted --channelID mychannel --name mycc --peerAddresses peer0.org1.example.com:7051 --output json + ``` + + If successful, the command will return a JSON that has committed chaincode definition for chaincode 'mycc' on channel 'mychannel'. + + ``` + { + "sequence": 1, + "version": "1", + "endorsement_plugin": "escc", + "validation_plugin": "vscc", + "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==", + "collections": {}, + "init_required": true, + "approvals": { + "Org1MSP": true, + "Org2MSP": true + } + } + ``` + + The `validation_parameter` is base64 encoded. An example of the command to decode it is as follows. + + ``` + echo EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA== | base64 -d + + /Channel/Application/Endorsement + ``` + + - For querying all chaincode definitions on that channel + + ``` + peercli lifecycle chaincode querycommitted --channelID mychannel --peerAddresses peer0.org1.example.com:7051 --output json + ``` + + If successful, the command will return a JSON that has committed chaincode definitions on channel 'mychannel'. + + ``` + { + "chaincode_definitions": [ + { + "name": "mycc", + "sequence": 1, + "version": "1", + "endorsement_plugin": "escc", + "validation_plugin": "vscc", + "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==", + "collections": {}, + "init_required": true + }, + { + "name": "yourcc", + "sequence": 3, + "version": "2", + "endorsement_plugin": "escc", + "validation_plugin": "vscc", + "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==", + "collections": {} + } + ] + } + ``` + + +Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License. diff --git a/docs/wrappers/peercli_lifecycle_chaincode_preamble.md b/docs/wrappers/peercli_lifecycle_chaincode_preamble.md new file mode 100644 index 00000000000..8bc272e6cbd --- /dev/null +++ b/docs/wrappers/peercli_lifecycle_chaincode_preamble.md @@ -0,0 +1,26 @@ +# peercli lifecycle chaincode + +The `peercli lifecycle chaincode` subcommand allows administrators to use the +Fabric chaincode lifecycle to package a chaincode, install it on your peers, +approve a chaincode definition for your organization, and then commit the +definition to a channel. The chaincode is ready to be used after the definition +has been successfully committed to the channel. For more information, visit +[Fabric chaincode lifecycle](../chaincode_lifecycle.html). + +## Syntax + +The `peercli lifecycle chaincode` command has the following subcommands: + + * package + * install + * queryinstalled + * getinstalledpackage + * calculatepackageid + * approveformyorg + * queryapproved + * checkcommitreadiness + * commit + * querycommitted + +Each peercli lifecycle chaincode subcommand is described together with its options in its own +section in this topic. diff --git a/docs/wrappers/peercli_snapshot_postscript.md b/docs/wrappers/peercli_snapshot_postscript.md new file mode 100644 index 00000000000..62b73515102 --- /dev/null +++ b/docs/wrappers/peercli_snapshot_postscript.md @@ -0,0 +1,62 @@ +## Example Usage + +### peercli snapshot cancelrequest example + +Here is an example of the `peercli snapshot cancelrequest` command. + + * Cancel a snapshot request for block number 1000 on channel `mychannel` + for `peer0.org1.example.com:7051`: + + ``` + peercli snapshot cancelrequest -c mychannel -b 1000 --peerAddress peer0.org1.example.com:7051 + + Snapshot request cancelled successfully + + ``` + + A successful response indicates that the snapshot request for block number 1000 has been removed from `mychannel`. + If there is no pending snapshot request for block number 1000, the command will return an error. + + * Use the `--tlsRootCertFile` flag in a network with TLS enabled + +### peercli snapshot listpending example + +Here is an example of the `peercli snapshot listpending` command. +If a snapshot is already generated, the corresponding block number will be removed from the pending list. + + * List pending snapshot requests on channel `mychannel` + for `peer0.org1.example.com:7051`: + + ``` + peercli snapshot listpending -c mychannel --peerAddress peer0.org1.example.com:7051 + + Successfully got pending snapshot requests: [1000 5000] + + ``` + + You can see that the command returns a list of block numbers for the pending snapshot requests. + + * Use the `--tlsRootCertFile` flag in a network with TLS enabled + +### peercli snapshot submitrequest example + +Here is an example of the `peercli snapshot submitrequest` command. + + * Submit a snapshot request for block number 1000 on channel `mychannel` + for `peer0.org1.example.com:7051`: + + ``` + peercli snapshot submitrequest -c mychannel -b 1000 --peerAddress peer0.org1.example.com:7051 + + Snapshot request submitted successfully + + ``` + + You can see that the snapshot request is successfully submitted on channel `mychannel`. + A snapshot will be automatically generated after the block number 1000 is committed on the channel. + + The specified block number must be at or above the last block number on the channel. + Otherwise, the command will return an error. + + * Use the `--tlsRootCertFile` flag in a network with TLS enabled + diff --git a/docs/wrappers/peercli_snapshot_preamble.md b/docs/wrappers/peercli_snapshot_preamble.md new file mode 100644 index 00000000000..ce3f8eb005a --- /dev/null +++ b/docs/wrappers/peercli_snapshot_preamble.md @@ -0,0 +1,15 @@ +# peercli snapshot + +The `peercli snapshot` command allows administrators to perform snapshot related +operations on a peer, such as submit a snapshot request, cancel a snapshot request +and list pending requests. Once a snapshot request is submitted for a specified +block number, the snapshot will be automatically generated when the block number is +committed on the channel. + +## Syntax + +The `peercli snapshot` command has the following subcommands: + + * cancelrequest + * listpending + * submitrequest diff --git a/docs/wrappers/peercli_version_preamble.md b/docs/wrappers/peercli_version_preamble.md new file mode 100644 index 00000000000..66e410308f8 --- /dev/null +++ b/docs/wrappers/peercli_version_preamble.md @@ -0,0 +1,20 @@ +# peercli version + +The `peercli version` command displays the version information of the peercli. It +displays version, Commit SHA, Go version, OS/architecture, and chaincode +information. For example: + +``` + peercli: + Version: 2.1.0 + Commit SHA: b78d79b + Go version: go1.14.1 + OS/Arch: linux/amd64 + Chaincode: + Base Docker Label: org.hyperledger.fabric + Docker Namespace: hyperledger +``` + +## Syntax + +The `peercli version` command takes no arguments. diff --git a/integration/chaincode/marbles/marbles_chaincode.go b/integration/chaincode/marbles/marbles_chaincode.go index 35138064017..6bfa741c142 100644 --- a/integration/chaincode/marbles/marbles_chaincode.go +++ b/integration/chaincode/marbles/marbles_chaincode.go @@ -6,24 +6,24 @@ // ====CHAINCODE EXECUTION SAMPLES (CLI) ================== // ==== Invoke marbles ==== -// peer chaincode invoke -C myc1 -n marbles -c '{"Args":["initMarble","marble1","blue","35","tom"]}' -// peer chaincode invoke -C myc1 -n marbles -c '{"Args":["initMarble","marble2","red","50","tom"]}' -// peer chaincode invoke -C myc1 -n marbles -c '{"Args":["initMarble","marble3","blue","70","tom"]}' -// peer chaincode invoke -C myc1 -n marbles -c '{"Args":["transferMarble","marble2","jerry"]}' -// peer chaincode invoke -C myc1 -n marbles -c '{"Args":["transferMarblesBasedOnColor","blue","jerry"]}' -// peer chaincode invoke -C myc1 -n marbles -c '{"Args":["delete","marble1"]}' +// peercli chaincode invoke -C myc1 -n marbles -c '{"Args":["initMarble","marble1","blue","35","tom"]}' +// peercli chaincode invoke -C myc1 -n marbles -c '{"Args":["initMarble","marble2","red","50","tom"]}' +// peercli chaincode invoke -C myc1 -n marbles -c '{"Args":["initMarble","marble3","blue","70","tom"]}' +// peercli chaincode invoke -C myc1 -n marbles -c '{"Args":["transferMarble","marble2","jerry"]}' +// peercli chaincode invoke -C myc1 -n marbles -c '{"Args":["transferMarblesBasedOnColor","blue","jerry"]}' +// peercli chaincode invoke -C myc1 -n marbles -c '{"Args":["delete","marble1"]}' // ==== Query marbles ==== -// peer chaincode query -C myc1 -n marbles -c '{"Args":["readMarble","marble1"]}' -// peer chaincode query -C myc1 -n marbles -c '{"Args":["getMarblesByRange","marble1","marble3"]}' -// peer chaincode query -C myc1 -n marbles -c '{"Args":["getHistoryForMarble","marble1"]}' +// peercli chaincode query -C myc1 -n marbles -c '{"Args":["readMarble","marble1"]}' +// peercli chaincode query -C myc1 -n marbles -c '{"Args":["getMarblesByRange","marble1","marble3"]}' +// peercli chaincode query -C myc1 -n marbles -c '{"Args":["getHistoryForMarble","marble1"]}' // Rich Query (Only supported if CouchDB is used as state database): -// peer chaincode query -C myc1 -n marbles -c '{"Args":["queryMarblesByOwner","tom"]}' -// peer chaincode query -C myc1 -n marbles -c '{"Args":["queryMarbles","{\"selector\":{\"owner\":\"tom\"}}"]}' +// peercli chaincode query -C myc1 -n marbles -c '{"Args":["queryMarblesByOwner","tom"]}' +// peercli chaincode query -C myc1 -n marbles -c '{"Args":["queryMarbles","{\"selector\":{\"owner\":\"tom\"}}"]}' // Rich Query with Pagination (Only supported if CouchDB is used as state database): -// peer chaincode query -C myc1 -n marbles -c '{"Args":["queryMarblesWithPagination","{\"selector\":{\"owner\":\"tom\"}}","3",""]}' +// peercli chaincode query -C myc1 -n marbles -c '{"Args":["queryMarblesWithPagination","{\"selector\":{\"owner\":\"tom\"}}","3",""]}' // INDEXES TO SUPPORT COUCHDB RICH QUERIES // @@ -72,10 +72,10 @@ // curl -i -X POST -H "Content-Type: application/json" -d "{\"index\":{\"fields\":[{\"size\":\"desc\"},{\"docType\":\"desc\"},{\"owner\":\"desc\"}]},\"ddoc\":\"indexSizeSortDoc\", \"name\":\"indexSizeSortDesc\",\"type\":\"json\"}" http://hostname:port/myc1_marbles/_index // Rich Query with index design doc and index name specified (Only supported if CouchDB is used as state database): -// peer chaincode query -C myc1 -n marbles -c '{"Args":["queryMarbles","{\"selector\":{\"docType\":\"marble\",\"owner\":\"tom\"}, \"use_index\":[\"_design/indexOwnerDoc\", \"indexOwner\"]}"]}' +// peercli chaincode query -C myc1 -n marbles -c '{"Args":["queryMarbles","{\"selector\":{\"docType\":\"marble\",\"owner\":\"tom\"}, \"use_index\":[\"_design/indexOwnerDoc\", \"indexOwner\"]}"]}' // Rich Query with index design doc specified only (Only supported if CouchDB is used as state database): -// peer chaincode query -C myc1 -n marbles -c '{"Args":["queryMarbles","{\"selector\":{\"docType\":{\"$eq\":\"marble\"},\"owner\":{\"$eq\":\"tom\"},\"size\":{\"$gt\":0}},\"fields\":[\"docType\",\"owner\",\"size\"],\"sort\":[{\"size\":\"desc\"}],\"use_index\":\"_design/indexSizeSortDoc\"}"]}' +// peercli chaincode query -C myc1 -n marbles -c '{"Args":["queryMarbles","{\"selector\":{\"docType\":{\"$eq\":\"marble\"},\"owner\":{\"$eq\":\"tom\"},\"size\":{\"$gt\":0}},\"fields\":[\"docType\",\"owner\",\"size\"],\"sort\":[{\"size\":\"desc\"}],\"use_index\":\"_design/indexSizeSortDoc\"}"]}' package marbles diff --git a/integration/devmode/devmode_test.go b/integration/devmode/devmode_test.go index 788eeb7f469..6bc00d90b93 100644 --- a/integration/devmode/devmode_test.go +++ b/integration/devmode/devmode_test.go @@ -144,7 +144,7 @@ var _ = Describe("Devmode", func() { Eventually(chaincodeProcess.Wait(), network.EventuallyTimeout).Should(Receive()) By("invoking chaincode after it has been killed, expecting it to fail") - sess, err := network.PeerUserSession(org1peer0, "User1", commands.ChaincodeInvoke{ + sess, err := network.PeerCliUserSession(org1peer0, "User1", commands.ChaincodeInvoke{ ChannelID: channelName, Orderer: network.OrdererAddress(orderer, nwo.ListenPort), Name: "mycc", @@ -177,7 +177,7 @@ var _ = Describe("Devmode", func() { func RunQueryInvokeQuery(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer, channel string, queryValue int) { By("querying the chaincode") - sess, err := n.PeerUserSession(peer, "User1", commands.ChaincodeQuery{ + sess, err := n.PeerCliUserSession(peer, "User1", commands.ChaincodeQuery{ ChannelID: channel, Name: "mycc", Ctor: `{"Args":["query","a"]}`, @@ -187,7 +187,7 @@ func RunQueryInvokeQuery(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer, c Expect(sess).To(gbytes.Say(strconv.Itoa(queryValue))) By("invoking the chaincode") - sess, err = n.PeerUserSession(peer, "User1", commands.ChaincodeInvoke{ + sess, err = n.PeerCliUserSession(peer, "User1", commands.ChaincodeInvoke{ ChannelID: channel, Orderer: n.OrdererAddress(orderer, nwo.ListenPort), Name: "mycc", @@ -202,7 +202,7 @@ func RunQueryInvokeQuery(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer, c Expect(sess.Err).To(gbytes.Say("Chaincode invoke successful. result: status:200")) By("querying the chaincode again") - sess, err = n.PeerUserSession(peer, "User1", commands.ChaincodeQuery{ + sess, err = n.PeerCliUserSession(peer, "User1", commands.ChaincodeQuery{ ChannelID: channel, Name: "mycc", Ctor: `{"Args":["query","a"]}`, @@ -218,7 +218,7 @@ func ApproveChaincodeForMyOrg(n *nwo.Network, channel string, orderer *nwo.Order approvedOrgs := map[string]bool{} for _, p := range peers { if _, ok := approvedOrgs[p.Organization]; !ok { - sess, err := n.PeerAdminSession(p, commands.ChaincodeApproveForMyOrg{ + sess, err := n.PeerCliAdminSession(p, commands.ChaincodeApproveForMyOrg{ ChannelID: channel, Orderer: n.OrdererAddress(orderer, nwo.ListenPort), Name: chaincode.Name, diff --git a/integration/discovery/discovery_test.go b/integration/discovery/discovery_test.go index da85656a750..66f1d057c16 100644 --- a/integration/discovery/discovery_test.go +++ b/integration/discovery/discovery_test.go @@ -618,7 +618,7 @@ func discoverConfiguration(n *nwo.Network, peer *nwo.Peer) *discovery.ConfigResu } func submitSnapshotRequest(n *nwo.Network, channel string, blockNum int, peer *nwo.Peer, expectedMsg string) { - sess, err := n.PeerAdminSession(peer, commands.SnapshotSubmitRequest{ + sess, err := n.PeerCliAdminSession(peer, commands.SnapshotSubmitRequest{ ChannelID: channel, BlockNumber: strconv.Itoa(blockNum), ClientAuth: n.ClientAuthRequired, @@ -636,7 +636,7 @@ func verifyNoPendingSnapshotRequest(n *nwo.Network, peer *nwo.Peer, channelID st PeerAddress: n.PeerAddress(peer, nwo.ListenPort), } checkPending := func() string { - sess, err := n.PeerAdminSession(peer, cmd) + sess, err := n.PeerCliAdminSession(peer, cmd) Expect(err).NotTo(HaveOccurred()) Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0)) return string(sess.Buffer().Contents()) diff --git a/integration/e2e/acl_test.go b/integration/e2e/acl_test.go index 7e704b6e9f7..11591d1ec63 100644 --- a/integration/e2e/acl_test.go +++ b/integration/e2e/acl_test.go @@ -110,7 +110,7 @@ var _ = Describe("EndToEndACL", func() { // when the ACL policy for _lifecycle/InstallChaincode is not satisfied // By("installing the chaincode to an org1 peer as an org2 admin") - sess, err := network.PeerAdminSession(org2Peer0, commands.ChaincodeInstall{ + sess, err := network.PeerCliAdminSession(org2Peer0, commands.ChaincodeInstall{ PackageFile: chaincode.PackageFile, PeerAddresses: []string{network.PeerAddress(org1Peer0, nwo.ListenPort)}, }) @@ -119,7 +119,7 @@ var _ = Describe("EndToEndACL", func() { Expect(sess.Err).To(gbytes.Say(`access denied: channel \[\] creator org unknown, creator is malformed`)) By("installing the chaincode to an org1 peer as a non-admin org1 identity") - sess, err = network.PeerUserSession(org1Peer0, "User1", commands.ChaincodeInstall{ + sess, err = network.PeerCliUserSession(org1Peer0, "User1", commands.ChaincodeInstall{ PackageFile: chaincode.PackageFile, }) Expect(err).NotTo(HaveOccurred()) @@ -135,7 +135,7 @@ var _ = Describe("EndToEndACL", func() { // when the V2_0 application capabilities flag has not yet been enabled // By("approving a chaincode definition on a channel without V2_0 capabilities enabled") - sess, err = network.PeerAdminSession(org1Peer0, commands.ChaincodeApproveForMyOrg{ + sess, err = network.PeerCliAdminSession(org1Peer0, commands.ChaincodeApproveForMyOrg{ ChannelID: "testchannel", Orderer: network.OrdererAddress(orderer, nwo.ListenPort), Name: chaincode.Name, @@ -154,7 +154,7 @@ var _ = Describe("EndToEndACL", func() { Expect(sess.Err).To(gbytes.Say("Error: proposal failed with status: 500 - cannot use new lifecycle for channel 'testchannel' as it does not have the required capabilities enabled")) By("committing a chaincode definition on a channel without V2_0 capabilities enabled") - sess, err = network.PeerAdminSession(org1Peer0, commands.ChaincodeCommit{ + sess, err = network.PeerCliAdminSession(org1Peer0, commands.ChaincodeCommit{ ChannelID: "testchannel", Orderer: network.OrdererAddress(orderer, nwo.ListenPort), Name: chaincode.Name, @@ -180,7 +180,7 @@ var _ = Describe("EndToEndACL", func() { // when the ACL policy for _lifecycle/ApproveChaincodeDefinitionForOrg is not satisfied // By("approving a chaincode definition for org1 as an org2 admin") - sess, err = network.PeerAdminSession(org2Peer0, commands.ChaincodeApproveForMyOrg{ + sess, err = network.PeerCliAdminSession(org2Peer0, commands.ChaincodeApproveForMyOrg{ ChannelID: "testchannel", Orderer: network.OrdererAddress(orderer, nwo.ListenPort), Name: chaincode.Name, @@ -209,7 +209,7 @@ var _ = Describe("EndToEndACL", func() { // when the ACL policy for _lifecycle/QueryApprovedChaincodeDefinition is not satisfied // By("querying the approved chaincode definition for org1 as an org2 admin") - sess, err = network.PeerAdminSession(org2Peer0, commands.ChaincodeQueryApproved{ + sess, err = network.PeerCliAdminSession(org2Peer0, commands.ChaincodeQueryApproved{ ChannelID: "testchannel", Name: chaincode.Name, Sequence: chaincode.Sequence, @@ -234,7 +234,7 @@ var _ = Describe("EndToEndACL", func() { SetACLPolicy(network, "testchannel", policyName, policy, "orderer") By("simulating the commit of a chaincode dwefinition as a forbidden Org2 Admin identity") - sess, err = network.PeerAdminSession(org2Peer0, commands.ChaincodeCheckCommitReadiness{ + sess, err = network.PeerCliAdminSession(org2Peer0, commands.ChaincodeCheckCommitReadiness{ ChannelID: "testchannel", Name: chaincode.Name, Version: chaincode.Version, @@ -268,7 +268,7 @@ var _ = Describe("EndToEndACL", func() { network.PeerAddress(org1Peer0, nwo.ListenPort), network.PeerAddress(org2Peer0, nwo.ListenPort), } - sess, err = network.PeerAdminSession(org2Peer0, commands.ChaincodeCommit{ + sess, err = network.PeerCliAdminSession(org2Peer0, commands.ChaincodeCommit{ ChannelID: "testchannel", Orderer: network.OrdererAddress(orderer, nwo.ListenPort), Name: chaincode.Name, @@ -304,7 +304,7 @@ var _ = Describe("EndToEndACL", func() { nwo.EnsureChaincodeCommitted(network, "testchannel", "mycc", "0.0", "1", []*nwo.Organization{network.Organization("Org1"), network.Organization("Org2")}, org1Peer0) By("querying the chaincode definition as a forbidden Org2 Admin identity") - sess, err = network.PeerAdminSession(org2Peer0, commands.ChaincodeListCommitted{ + sess, err = network.PeerCliAdminSession(org2Peer0, commands.ChaincodeListCommitted{ ChannelID: "testchannel", Name: "mycc", }) @@ -382,7 +382,7 @@ var _ = Describe("EndToEndACL", func() { SetACLPolicy(network, "testchannel", policyName, policy, "orderer") By("fetching the latest block from the peer as a permitted Org1 Admin identity") - sess, err = network.PeerAdminSession(org1Peer0, fetchNewest) + sess, err = network.PeerCliAdminSession(org1Peer0, fetchNewest) Expect(err).NotTo(HaveOccurred()) Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit(0)) Expect(sess.Err).To(gbytes.Say("Received block: ")) @@ -391,13 +391,13 @@ var _ = Describe("EndToEndACL", func() { // when the ACL policy for Deliver is not satisfied // By("fetching the latest block from the peer as a forbidden org2 Admin identity") - sess, err = network.PeerAdminSession(org2Peer0, fetchNewest) + sess, err = network.PeerCliAdminSession(org2Peer0, fetchNewest) Expect(err).NotTo(HaveOccurred()) Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit()) Expect(sess.Err).To(gbytes.Say("can't read the block: &{FORBIDDEN}")) // getting a transaction id from a block in the ledger - sess, err = network.PeerAdminSession(org1Peer0, fetchNewest) + sess, err = network.PeerCliAdminSession(org1Peer0, fetchNewest) Expect(err).NotTo(HaveOccurred()) Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit(0)) Expect(sess.Err).To(gbytes.Say("Received block: ")) @@ -417,12 +417,12 @@ var _ = Describe("EndToEndACL", func() { } By("evaluating " + policyName + " for a permitted subject") - sess, err := network.PeerAdminSession(org1Peer0, chaincodeQuery) + sess, err := network.PeerCliAdminSession(org1Peer0, chaincodeQuery) Expect(err).NotTo(HaveOccurred()) Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit(0)) By("evaluating " + policyName + " for a forbidden subject") - sess, err = network.PeerAdminSession(org2Peer0, chaincodeQuery) + sess, err = network.PeerCliAdminSession(org2Peer0, chaincodeQuery) Expect(err).NotTo(HaveOccurred()) Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit()) Expect(sess.Err).To(gbytes.Say(fmt.Sprintf(`access denied for \[%s\]\[%s\](.*)signature set did not satisfy policy`, operation, "testchannel"))) @@ -493,7 +493,7 @@ func ToCLIChaincodeArgs(args ...string) string { } func verifyCommandErr(network *nwo.Network, peer *nwo.Peer, user string, cmd nwo.Command, expectedMsg string) { - sess, err := network.PeerUserSession(peer, user, cmd) + sess, err := network.PeerCliUserSession(peer, user, cmd) Expect(err).NotTo(HaveOccurred()) Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit()) Expect(sess.Err).To(gbytes.Say(expectedMsg)) diff --git a/integration/e2e/e2e_test.go b/integration/e2e/e2e_test.go index 40b89c34036..fb4a754a975 100644 --- a/integration/e2e/e2e_test.go +++ b/integration/e2e/e2e_test.go @@ -184,7 +184,7 @@ var _ = Describe("EndToEnd", func() { badCC.PackageFile = filepath.Join(testDir, "unsupported-type.tar.gz") nwo.PackageChaincodeBinary(badCC) badCC.SetPackageIDFromPackageFile() - sess, err := network.PeerAdminSession( + sess, err := network.PeerCliAdminSession( network.Peer("Org1", "peer0"), commands.ChaincodeInstall{ PackageFile: badCC.PackageFile, @@ -349,7 +349,7 @@ var _ = Describe("EndToEnd", func() { RunQueryInvokeQuery(network, orderer, network.Peer("Org1", "peer0"), "testchannel") By("retrieving the local mspid of the peer via simple chaincode") - sess, err := network.PeerUserSession(network.Peer("Org2", "peer0"), "User1", commands.ChaincodeQuery{ + sess, err := network.PeerCliUserSession(network.Peer("Org2", "peer0"), "User1", commands.ChaincodeQuery{ ChannelID: "testchannel", Name: "mycc", Ctor: `{"Args":["mspid"]}`, @@ -560,7 +560,7 @@ var _ = Describe("EndToEnd", func() { By("invoking chaincode against all peers in test channel") for _, peer := range network.Peers { - sess, err := network.PeerUserSession(peer, "User1", commands.ChaincodeInvoke{ + sess, err := network.PeerCliUserSession(peer, "User1", commands.ChaincodeInvoke{ ChannelID: "testchannel", Orderer: network.OrdererAddress(orderer, nwo.ListenPort), Name: "mycc", @@ -645,7 +645,7 @@ var _ = Describe("EndToEnd", func() { } By("attempting to approve chaincode definition after commit") - sess, err := network.PeerAdminSession(peers[0], commands.ChaincodeApproveForMyOrg{ + sess, err := network.PeerCliAdminSession(peers[0], commands.ChaincodeApproveForMyOrg{ ChannelID: "testchannel", Orderer: network.OrdererAddress(orderer, nwo.ListenPort), Name: chaincode.Name, @@ -669,7 +669,7 @@ var _ = Describe("EndToEnd", func() { func RunQueryInvokeQuery(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer, channel string) { By("querying the chaincode") - sess, err := n.PeerUserSession(peer, "User1", commands.ChaincodeQuery{ + sess, err := n.PeerCliUserSession(peer, "User1", commands.ChaincodeQuery{ ChannelID: channel, Name: "mycc", Ctor: `{"Args":["query","a"]}`, @@ -678,7 +678,7 @@ func RunQueryInvokeQuery(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer, c Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0)) Expect(sess).To(gbytes.Say("100")) - sess, err = n.PeerUserSession(peer, "User1", commands.ChaincodeInvoke{ + sess, err = n.PeerCliUserSession(peer, "User1", commands.ChaincodeInvoke{ ChannelID: channel, Orderer: n.OrdererAddress(orderer, nwo.ListenPort), Name: "mycc", @@ -693,7 +693,7 @@ func RunQueryInvokeQuery(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer, c Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0)) Expect(sess.Err).To(gbytes.Say("Chaincode invoke successful. result: status:200")) - sess, err = n.PeerUserSession(peer, "User1", commands.ChaincodeQuery{ + sess, err = n.PeerCliUserSession(peer, "User1", commands.ChaincodeQuery{ ChannelID: channel, Name: "mycc", Ctor: `{"Args":["query","a"]}`, @@ -705,7 +705,7 @@ func RunQueryInvokeQuery(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer, c func RunRespondWith(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer, channel string) { By("responding with a 300") - sess, err := n.PeerUserSession(peer, "User1", commands.ChaincodeInvoke{ + sess, err := n.PeerCliUserSession(peer, "User1", commands.ChaincodeInvoke{ ChannelID: channel, Orderer: n.OrdererAddress(orderer, nwo.ListenPort), Name: "mycc", @@ -721,7 +721,7 @@ func RunRespondWith(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer, channe Expect(sess.Err).To(gbytes.Say("Chaincode invoke successful. result: status:300")) By("responding with a 400") - sess, err = n.PeerUserSession(peer, "User1", commands.ChaincodeInvoke{ + sess, err = n.PeerCliUserSession(peer, "User1", commands.ChaincodeInvoke{ ChannelID: channel, Orderer: n.OrdererAddress(orderer, nwo.ListenPort), Name: "mycc", diff --git a/integration/e2e/write_batch_test.go b/integration/e2e/write_batch_test.go index 0ccc5324e9b..411b64ab272 100644 --- a/integration/e2e/write_batch_test.go +++ b/integration/e2e/write_batch_test.go @@ -282,7 +282,7 @@ var _ = Describe("Network", func() { }) func RunInvoke(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer, fn string, startWriteBatch bool, numberCallsPut int, exitCode int, expectedError []string) { - sess, err := n.PeerUserSession(peer, "User1", commands.ChaincodeInvoke{ + sess, err := n.PeerCliUserSession(peer, "User1", commands.ChaincodeInvoke{ ChannelID: "testchannel", Orderer: n.OrdererAddress(orderer, nwo.ListenPort), Name: "mycc", @@ -306,7 +306,7 @@ func RunInvoke(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer, fn string, } func RunGetState(n *nwo.Network, peer *nwo.Peer, keyUniq string) { - sess, err := n.PeerUserSession(peer, "User1", commands.ChaincodeQuery{ + sess, err := n.PeerCliUserSession(peer, "User1", commands.ChaincodeQuery{ ChannelID: "testchannel", Name: "mycc", Ctor: `{"Args":["get-key","` + keyUniq + `"]}`, @@ -317,7 +317,7 @@ func RunGetState(n *nwo.Network, peer *nwo.Peer, keyUniq string) { } func RunGetStateMultipleKeys(n *nwo.Network, peer *nwo.Peer, countKeys int) { - sess, err := n.PeerUserSession(peer, "User1", commands.ChaincodeQuery{ + sess, err := n.PeerCliUserSession(peer, "User1", commands.ChaincodeQuery{ ChannelID: "testchannel", Name: "mycc", Ctor: `{"Args":["get-multiple-keys","` + fmt.Sprint(countKeys) + `"]}`, diff --git a/integration/gossip/gossip_test.go b/integration/gossip/gossip_test.go index f6b9f162b2e..dcae787d3b4 100644 --- a/integration/gossip/gossip_test.go +++ b/integration/gossip/gossip_test.go @@ -450,7 +450,7 @@ func forceLowS(priv *ecdsa.PrivateKey, hash []byte) (r, s *big.Int, err error) { func runTransactions(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer, chaincodeName string, channelID string) { for range 5 { - sess, err := n.PeerUserSession(peer, "User1", commands.ChaincodeInvoke{ + sess, err := n.PeerCliUserSession(peer, "User1", commands.ChaincodeInvoke{ ChannelID: channelID, Orderer: n.OrdererAddress(orderer, nwo.ListenPort), Name: chaincodeName, diff --git a/integration/idemix/idemix_test.go b/integration/idemix/idemix_test.go index 7006a9f2474..85aaae7e7c7 100644 --- a/integration/idemix/idemix_test.go +++ b/integration/idemix/idemix_test.go @@ -110,7 +110,7 @@ var _ = Describe("EndToEnd", func() { func Query(n *nwo.Network, peer *nwo.Peer, channel string, expectedOutput string) { By("querying the chaincode") - sess, err := n.PeerUserSession(peer, "User1", commands.ChaincodeQuery{ + sess, err := n.PeerCliUserSession(peer, "User1", commands.ChaincodeQuery{ ChannelID: channel, Name: "mycc", Ctor: `{"Args":["query","a"]}`, @@ -133,7 +133,7 @@ func QueryWithIdemix(n *nwo.Network, peer *nwo.Peer, idemixOrg *nwo.Organization } func Invoke(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer, channel string) { - sess, err := n.PeerUserSession(peer, "User1", commands.ChaincodeInvoke{ + sess, err := n.PeerCliUserSession(peer, "User1", commands.ChaincodeInvoke{ ChannelID: channel, Orderer: n.OrdererAddress(orderer, nwo.ListenPort), Name: "mycc", diff --git a/integration/ledger/couchdb_indexes_test.go b/integration/ledger/couchdb_indexes_test.go index 7283dfe5cdf..cb9f4175fd8 100644 --- a/integration/ledger/couchdb_indexes_test.go +++ b/integration/ledger/couchdb_indexes_test.go @@ -175,7 +175,7 @@ var _ = Describe("CouchDB indexes", func() { func initMarble(n *nwo.Network, channel string, orderer *nwo.Orderer, peer *nwo.Peer, ccName, marbleName string) { By("invoking initMarble function of the chaincode") - sess, err := n.PeerUserSession(peer, "User1", commands.ChaincodeInvoke{ + sess, err := n.PeerCliUserSession(peer, "User1", commands.ChaincodeInvoke{ ChannelID: channel, Orderer: n.OrdererAddress(orderer, nwo.ListenPort), Name: ccName, @@ -256,7 +256,7 @@ func verifyColorIndexPresence(n *nwo.Network, channel string, orderer *nwo.Order func verifyIndexPresence(n *nwo.Network, channel string, orderer *nwo.Orderer, peer *nwo.Peer, ccName string, expectIndexPresent bool, indexQuery string) { By("invoking queryMarbles function with a user constructed query that requires an index due to a sort") - sess, err := n.PeerUserSession(peer, "User1", commands.ChaincodeInvoke{ + sess, err := n.PeerCliUserSession(peer, "User1", commands.ChaincodeInvoke{ ChannelID: channel, Name: ccName, Ctor: prepareChaincodeInvokeArgs("queryMarbles", indexQuery), diff --git a/integration/ledger/marbles_test.go b/integration/ledger/marbles_test.go index 029384634df..fffcfa84c05 100644 --- a/integration/ledger/marbles_test.go +++ b/integration/ledger/marbles_test.go @@ -280,7 +280,7 @@ func (th *marblesTestHelper) assertMarbleExists(chaincodeName string, peer *nwo. Name: chaincodeName, Ctor: fmt.Sprintf(`{"Args":["readMarble","%s"]}`, marbleName), } - sess, err := th.PeerUserSession(peer, "User1", command) + sess, err := th.PeerCliUserSession(peer, "User1", command) Expect(err).NotTo(HaveOccurred()) Eventually(sess, th.EventuallyTimeout).Should(gexec.Exit(0)) result := &marble{} @@ -307,7 +307,7 @@ func (th *marblesTestHelper) assertQueryMarbles(chaincodeName string, peer *nwo. Name: chaincodeName, Ctor: prepareChaincodeInvokeArgs(funcAndArgs...), } - sess, err := th.PeerUserSession(peer, "User1", command) + sess, err := th.PeerCliUserSession(peer, "User1", command) Expect(err).NotTo(HaveOccurred()) Eventually(sess, th.EventuallyTimeout).Should(gexec.Exit(0)) results := make([]*marbleQueryResult, 0) @@ -324,7 +324,7 @@ func (th *marblesTestHelper) assertQueryMarblesWithPagination(chaincodeName stri Name: chaincodeName, Ctor: prepareChaincodeInvokeArgs(funcAndArgs...), } - sess, err := th.PeerUserSession(peer, "User1", command) + sess, err := th.PeerCliUserSession(peer, "User1", command) Expect(err).NotTo(HaveOccurred()) Eventually(sess, th.EventuallyTimeout).Should(gexec.Exit(0)) @@ -354,7 +354,7 @@ func (th *marblesTestHelper) assertGetHistoryForMarble(chaincodeName string, pee Name: chaincodeName, Ctor: fmt.Sprintf(`{"Args":["getHistoryForMarble","%s"]}`, marbleName), } - sess, err := th.PeerUserSession(peer, "User1", command) + sess, err := th.PeerCliUserSession(peer, "User1", command) Expect(err).NotTo(HaveOccurred()) Eventually(sess, th.EventuallyTimeout).Should(gexec.Exit(0)) diff --git a/integration/ledger/reset_rollback_test.go b/integration/ledger/reset_rollback_test.go index cc7b0e50331..9735c582c37 100644 --- a/integration/ledger/reset_rollback_test.go +++ b/integration/ledger/reset_rollback_test.go @@ -434,7 +434,7 @@ func (nh *networkHelper) waitUntilPeerEqualLedgerHeight(peer *nwo.Peer, height i } func (nh *networkHelper) getLedgerHeight(peer *nwo.Peer) int { - sess, err := nh.PeerUserSession(peer, "User1", commands.ChannelInfo{ + sess, err := nh.PeerCliUserSession(peer, "User1", commands.ChannelInfo{ ChannelID: nh.channelID, }) Expect(err).NotTo(HaveOccurred()) @@ -448,7 +448,7 @@ func (nh *networkHelper) getLedgerHeight(peer *nwo.Peer) int { } func (nh *networkHelper) queryChaincode(peer *nwo.Peer, command commands.ChaincodeQuery, expectedMessage string, expectSuccess bool) { - sess, err := nh.PeerUserSession(peer, "User1", command) + sess, err := nh.PeerCliUserSession(peer, "User1", command) Expect(err).NotTo(HaveOccurred()) if expectSuccess { Eventually(sess, nh.EventuallyTimeout).Should(gexec.Exit(0)) @@ -460,7 +460,7 @@ func (nh *networkHelper) queryChaincode(peer *nwo.Peer, command commands.Chainco } func (nh *networkHelper) invokeChaincode(peer *nwo.Peer, command commands.ChaincodeInvoke) { - sess, err := nh.PeerUserSession(peer, "User1", command) + sess, err := nh.PeerCliUserSession(peer, "User1", command) Expect(err).NotTo(HaveOccurred()) Eventually(sess, nh.EventuallyTimeout).Should(gexec.Exit(0)) Expect(sess.Err).To(gbytes.Say("Chaincode invoke successful.")) @@ -528,7 +528,7 @@ func (nh *networkHelper) unjoin(peer *nwo.Peer, expectedErrMessage string, expec func (nh *networkHelper) waitUntilEndorserEnabled(peer *nwo.Peer) { Eventually(func() *gbytes.Buffer { - sess, err := nh.PeerUserSession(peer, "User1", commands.ChannelInfo{ + sess, err := nh.PeerCliUserSession(peer, "User1", commands.ChannelInfo{ ChannelID: nh.channelID, }) Expect(err).NotTo(HaveOccurred()) @@ -611,7 +611,7 @@ func (th *testHelper) assertDisabledEndorser(chaincodeName string, peer *nwo.Pee } func (th *testHelper) assertPausedChannel(peer *nwo.Peer) { - sess, err := th.PeerUserSession(peer, "User1", commands.ChannelInfo{ + sess, err := th.PeerCliUserSession(peer, "User1", commands.ChannelInfo{ ChannelID: th.channelID, }) Expect(err).NotTo(HaveOccurred()) @@ -620,7 +620,7 @@ func (th *testHelper) assertPausedChannel(peer *nwo.Peer) { } func (th *testHelper) assertUnjoinedChannel(peer *nwo.Peer) { - sess, err := th.PeerUserSession(peer, "User1", commands.ChannelInfo{ + sess, err := th.PeerCliUserSession(peer, "User1", commands.ChannelInfo{ ChannelID: th.channelID, }) Expect(err).NotTo(HaveOccurred()) diff --git a/integration/ledger/snapshot_test.go b/integration/ledger/snapshot_test.go index 09e03faf27b..b1ff51d7f26 100644 --- a/integration/ledger/snapshot_test.go +++ b/integration/ledger/snapshot_test.go @@ -698,7 +698,7 @@ func verifyNoPendingSnapshotRequest(n *nwo.Network, peer *nwo.Peer, channelID st } func submitSnapshotRequest(n *nwo.Network, channel string, blockNum int, peer *nwo.Peer, expectedError bool, expectedMsg string) { - sess, err := n.PeerAdminSession(peer, commands.SnapshotSubmitRequest{ + sess, err := n.PeerCliAdminSession(peer, commands.SnapshotSubmitRequest{ ChannelID: channel, BlockNumber: strconv.Itoa(blockNum), ClientAuth: n.ClientAuthRequired, @@ -715,7 +715,7 @@ func submitSnapshotRequest(n *nwo.Network, channel string, blockNum int, peer *n } func cancelSnapshotRequest(n *nwo.Network, channel string, blockNum int, peer *nwo.Peer, peerAddress string, expectedError bool, expectedMsg string) { - sess, err := n.PeerAdminSession(peer, commands.SnapshotCancelRequest{ + sess, err := n.PeerCliAdminSession(peer, commands.SnapshotCancelRequest{ ChannelID: channel, BlockNumber: strconv.Itoa(blockNum), ClientAuth: n.ClientAuthRequired, @@ -732,7 +732,7 @@ func cancelSnapshotRequest(n *nwo.Network, channel string, blockNum int, peer *n } func listPendingSnapshotRequests(n *nwo.Network, channel string, peer *nwo.Peer, peerAddress string, expectedError bool) []byte { - sess, err := n.PeerAdminSession(peer, commands.SnapshotListPending{ + sess, err := n.PeerCliAdminSession(peer, commands.SnapshotListPending{ ChannelID: channel, ClientAuth: n.ClientAuthRequired, PeerAddress: peerAddress, @@ -802,7 +802,7 @@ func joinBySnapshot(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer, channe nwo.WaitUntilEqualLedgerHeight(n, channelID, channelHeight, peer) By("verifying blockchain info on peer " + peer.ID()) - sess, err := n.PeerUserSession(peer, "Admin", commands.ChannelInfo{ + sess, err := n.PeerCliUserSession(peer, "Admin", commands.ChannelInfo{ ChannelID: channelID, }) Expect(err).NotTo(HaveOccurred()) @@ -861,7 +861,7 @@ func getTxFromLastBlock(n *nwo.Network, peer *nwo.Peer) (*cb.Envelope, string) { Block: "newest", OutputFile: blockfile, } - sess, err := n.PeerAdminSession(peer, fetchNewest) + sess, err := n.PeerCliAdminSession(peer, fetchNewest) Expect(err).NotTo(HaveOccurred()) Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0)) Expect(sess.Err).To(gbytes.Say("Received block: ")) @@ -916,14 +916,14 @@ func invokeAndQueryKVExecutorChaincode(n *nwo.Network, orderer *nwo.Orderer, cha } func invokeChaincode(n *nwo.Network, peer *nwo.Peer, command commands.ChaincodeInvoke) { - sess, err := n.PeerUserSession(peer, "User1", command) + sess, err := n.PeerCliUserSession(peer, "User1", command) Expect(err).NotTo(HaveOccurred()) Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0)) Expect(sess.Err).To(gbytes.Say("Chaincode invoke successful.")) } func queryChaincode(n *nwo.Network, peer *nwo.Peer, command commands.ChaincodeQuery, expectedMessage string, expectSuccess bool) { - sess, err := n.PeerUserSession(peer, "User1", command) + sess, err := n.PeerCliUserSession(peer, "User1", command) Expect(err).NotTo(HaveOccurred()) if expectSuccess { Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0)) @@ -942,7 +942,7 @@ func callQSCC(n *nwo.Network, peer *nwo.Peer, scc, operation string, retCode int Ctor: toCLIChaincodeArgs(args...), } - sess, err := n.PeerAdminSession(peer, chaincodeQuery) + sess, err := n.PeerCliAdminSession(peer, chaincodeQuery) Expect(err).NotTo(HaveOccurred()) Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(retCode)) if retCode != 0 { @@ -972,7 +972,7 @@ func waitForMarblePvtdataReconciliation(n *nwo.Network, peer *nwo.Peer, channelI Ctor: query, } queryData := func() int { - sess, err := n.PeerUserSession(peer, "User1", command) + sess, err := n.PeerCliUserSession(peer, "User1", command) Expect(err).NotTo(HaveOccurred()) return sess.Wait(n.EventuallyTimeout).ExitCode() } diff --git a/integration/lifecycle/install_test.go b/integration/lifecycle/install_test.go index f401c07e726..69fb9d72e81 100644 --- a/integration/lifecycle/install_test.go +++ b/integration/lifecycle/install_test.go @@ -111,7 +111,7 @@ var _ = Describe("chaincode install", func() { nwo.PackageChaincode(network, chaincode, org1Peer) By("installing the chaincode using _lifecycle") - sess, err := network.PeerAdminSession(org1Peer, commands.ChaincodeInstall{ + sess, err := network.PeerCliAdminSession(org1Peer, commands.ChaincodeInstall{ PackageFile: chaincode.PackageFile, ClientAuth: network.ClientAuthRequired, }) diff --git a/integration/lifecycle/interop_test.go b/integration/lifecycle/interop_test.go index 12671ec0987..303c4dd52cc 100644 --- a/integration/lifecycle/interop_test.go +++ b/integration/lifecycle/interop_test.go @@ -115,7 +115,7 @@ var _ = Describe("Release interoperability", func() { RunQueryInvokeQuery(network, orderer, "mycc", 80, endorsers...) By("attempting to invoke the chaincode without sufficient endorsements") - sess, err := network.PeerUserSession(endorsers[0], "User1", commands.ChaincodeInvoke{ + sess, err := network.PeerCliUserSession(endorsers[0], "User1", commands.ChaincodeInvoke{ ChannelID: "testchannel", Orderer: network.OrdererAddress(orderer, nwo.ListenPort), Name: "mycc", @@ -300,7 +300,7 @@ var _ = Describe("Release interoperability", func() { Expect(err).NotTo(HaveOccurred()) By("querying the caller chaincode") - sess, err := network.PeerUserSession(endorsers[0], "User1", commands.ChaincodeQuery{ + sess, err := network.PeerCliUserSession(endorsers[0], "User1", commands.ChaincodeQuery{ ChannelID: "testchannel", Name: "caller", Ctor: `{"Args":["QUERY"]}`, @@ -310,7 +310,7 @@ var _ = Describe("Release interoperability", func() { Expect(sess).To(gbytes.Say("caller:bar")) By("querying the callee chaincode") - sess, err = network.PeerUserSession(endorsers[0], "User1", commands.ChaincodeQuery{ + sess, err = network.PeerCliUserSession(endorsers[0], "User1", commands.ChaincodeQuery{ ChannelID: "testchannel", Name: "callee", Ctor: `{"Args":["QUERY"]}`, @@ -327,7 +327,7 @@ var _ = Describe("Release interoperability", func() { nwo.DeployChaincode(network, "testchannel2", orderer, calleeDefNew) By("invoking the chaincode on callee on channel2") - sess, err = network.PeerUserSession(endorsers[0], "User1", commands.ChaincodeInvoke{ + sess, err = network.PeerCliUserSession(endorsers[0], "User1", commands.ChaincodeInvoke{ ChannelID: "testchannel2", Orderer: network.OrdererAddress(orderer, nwo.ListenPort), Name: "callee", @@ -339,7 +339,7 @@ var _ = Describe("Release interoperability", func() { Expect(sess.Err).To(gbytes.Say("Chaincode invoke successful. result: status:200")) By("querying the callee chaincode on channel2") - sess, err = network.PeerUserSession(endorsers[0], "User1", commands.ChaincodeQuery{ + sess, err = network.PeerCliUserSession(endorsers[0], "User1", commands.ChaincodeQuery{ ChannelID: "testchannel2", Name: "callee", Ctor: `{"Args":["QUERY"]}`, @@ -349,7 +349,7 @@ var _ = Describe("Release interoperability", func() { Expect(sess).To(gbytes.Say("callee:bar")) By("querying (QUERYCALLEE) the callee chaincode on channel2 from caller on channel") - sess, err = network.PeerUserSession(endorsers[0], "User1", commands.ChaincodeQuery{ + sess, err = network.PeerCliUserSession(endorsers[0], "User1", commands.ChaincodeQuery{ ChannelID: "testchannel", Name: "caller", Ctor: `{"Args":["QUERYCALLEE", "callee", "testchannel2"]}`, @@ -359,7 +359,7 @@ var _ = Describe("Release interoperability", func() { Expect(sess).To(gbytes.Say("callee:bar")) By("querying (QUERYCALLEE) the callee chaincode from caller on non-existing channel and expecting the invocation to fail") - sess, err = network.PeerUserSession(endorsers[0], "User1", commands.ChaincodeQuery{ + sess, err = network.PeerCliUserSession(endorsers[0], "User1", commands.ChaincodeQuery{ ChannelID: "testchannel", Name: "caller", Ctor: `{"Args":["QUERYCALLEE", "callee", "nonExistingChannel2"]}`, @@ -403,7 +403,7 @@ var _ = Describe("Release interoperability", func() { Expect(err).NotTo(HaveOccurred()) By("querying the caller chaincode") - sess, err := network.PeerUserSession(endorsers[0], "User1", commands.ChaincodeQuery{ + sess, err := network.PeerCliUserSession(endorsers[0], "User1", commands.ChaincodeQuery{ ChannelID: "testchannel", Name: "caller", Ctor: `{"Args":["QUERY"]}`, @@ -413,7 +413,7 @@ var _ = Describe("Release interoperability", func() { Expect(sess).To(gbytes.Say("caller:bar")) By("querying the callee chaincode") - sess, err = network.PeerUserSession(endorsers[0], "User1", commands.ChaincodeQuery{ + sess, err = network.PeerCliUserSession(endorsers[0], "User1", commands.ChaincodeQuery{ ChannelID: "testchannel", Name: "callee", Ctor: `{"Args":["QUERY"]}`, @@ -450,7 +450,7 @@ var _ = Describe("Release interoperability", func() { Expect(err).To(MatchError(ContainSubstring("transaction invalidated with status (MVCC_READ_CONFLICT)"))) By("querying the caller chaincode") - sess, err := network.PeerUserSession(endorsers[0], "User1", commands.ChaincodeQuery{ + sess, err := network.PeerCliUserSession(endorsers[0], "User1", commands.ChaincodeQuery{ ChannelID: "testchannel", Name: "caller", Ctor: `{"Args":["QUERY"]}`, @@ -460,7 +460,7 @@ var _ = Describe("Release interoperability", func() { Expect(sess).To(gbytes.Say("caller:foo")) By("querying the callee chaincode") - sess, err = network.PeerUserSession(endorsers[0], "User1", commands.ChaincodeQuery{ + sess, err = network.PeerCliUserSession(endorsers[0], "User1", commands.ChaincodeQuery{ ChannelID: "testchannel", Name: "callee", Ctor: `{"Args":["QUERY"]}`, @@ -497,7 +497,7 @@ var _ = Describe("Release interoperability", func() { Expect(err).To(MatchError(ContainSubstring("transaction invalidated with status (MVCC_READ_CONFLICT)"))) By("querying the caller chaincode") - sess, err := network.PeerUserSession(endorsers[0], "User1", commands.ChaincodeQuery{ + sess, err := network.PeerCliUserSession(endorsers[0], "User1", commands.ChaincodeQuery{ ChannelID: "testchannel", Name: "caller", Ctor: `{"Args":["QUERY"]}`, @@ -507,7 +507,7 @@ var _ = Describe("Release interoperability", func() { Expect(sess).To(gbytes.Say("caller:foo")) By("querying the callee chaincode") - sess, err = network.PeerUserSession(endorsers[0], "User1", commands.ChaincodeQuery{ + sess, err = network.PeerCliUserSession(endorsers[0], "User1", commands.ChaincodeQuery{ ChannelID: "testchannel", Name: "callee", Ctor: `{"Args":["QUERY"]}`, diff --git a/integration/lifecycle/lifecycle_suite_test.go b/integration/lifecycle/lifecycle_suite_test.go index c5af5701b1f..57fb4103786 100644 --- a/integration/lifecycle/lifecycle_suite_test.go +++ b/integration/lifecycle/lifecycle_suite_test.go @@ -65,7 +65,7 @@ func StartPort() int { } func QueryChaincode(n *nwo.Network, chaincodeName string, peer *nwo.Peer, initialQueryResult int) { - sess, err := n.PeerUserSession(peer, "User1", commands.ChaincodeQuery{ + sess, err := n.PeerCliUserSession(peer, "User1", commands.ChaincodeQuery{ ChannelID: "testchannel", Name: chaincodeName, Ctor: `{"Args":["query","a"]}`, @@ -89,7 +89,7 @@ func RunQueryInvokeQuery(n *nwo.Network, orderer *nwo.Orderer, chaincodeName str QueryChaincode(n, chaincodeName, peers[0], initialQueryResult) By("invoking the chaincode") - sess, err := n.PeerUserSession(peers[0], "User1", commands.ChaincodeInvoke{ + sess, err := n.PeerCliUserSession(peers[0], "User1", commands.ChaincodeInvoke{ ChannelID: "testchannel", Orderer: n.OrdererAddress(orderer, nwo.ListenPort), Name: chaincodeName, @@ -116,7 +116,7 @@ func RunInvokeAndExpectFailure(n *nwo.Network, orderer *nwo.Orderer, chaincodeNa } By("invoking the chaincode") - sess, err := n.PeerUserSession(peers[1], "User1", commands.ChaincodeInvoke{ + sess, err := n.PeerCliUserSession(peers[1], "User1", commands.ChaincodeInvoke{ ChannelID: "testchannel", Orderer: n.OrdererAddress(orderer, nwo.ListenPort), Name: chaincodeName, diff --git a/integration/lifecycle/lifecycle_test.go b/integration/lifecycle/lifecycle_test.go index 9d3fd6239b2..a42d744d409 100644 --- a/integration/lifecycle/lifecycle_test.go +++ b/integration/lifecycle/lifecycle_test.go @@ -149,7 +149,7 @@ var _ = Describe("Lifecycle", func() { nwo.InstallChaincode(network, chaincode, testPeers...) By("verifying the installed chaincode package matches the one that was submitted") - sess, err := network.PeerAdminSession(testPeers[0], commands.ChaincodeGetInstalledPackage{ + sess, err := network.PeerCliAdminSession(testPeers[0], commands.ChaincodeGetInstalledPackage{ PackageID: chaincode.PackageID, OutputDirectory: testDir, }) @@ -183,7 +183,7 @@ var _ = Describe("Lifecycle", func() { nwo.ApproveChaincodeForMyOrg(network, "testchannel", orderer, chaincode, org1peer0) By("querying the chaincode and expecting the invocation to fail") - sess, err = network.PeerUserSession(org1peer0, "User1", commands.ChaincodeQuery{ + sess, err = network.PeerCliUserSession(org1peer0, "User1", commands.ChaincodeQuery{ ChannelID: "testchannel", Name: "My_1st-Chaincode", Ctor: `{"Args":["query","a"]}`, @@ -199,7 +199,7 @@ var _ = Describe("Lifecycle", func() { nwo.ApproveChaincodeForMyOrg(network, "testchannel", orderer, chaincode, org1peer0) By("querying the chaincode and expecting the invocation to succeed") - sess, err = network.PeerUserSession(org1peer0, "User1", commands.ChaincodeQuery{ + sess, err = network.PeerCliUserSession(org1peer0, "User1", commands.ChaincodeQuery{ ChannelID: "testchannel", Name: "My_1st-Chaincode", Ctor: `{"Args":["query","a"]}`, @@ -323,7 +323,7 @@ var _ = Describe("Lifecycle", func() { nwo.WaitUntilEqualLedgerHeight(network, "testchannel", maxLedgerHeight, testPeers...) By("querying definitions by org3 before performing any chaincode actions") - sess, err = network.PeerAdminSession(network.Peer("Org2", "peer0"), commands.ChaincodeListCommitted{ + sess, err = network.PeerCliAdminSession(network.Peer("Org2", "peer0"), commands.ChaincodeListCommitted{ ChannelID: "testchannel", }) Expect(err).NotTo(HaveOccurred()) @@ -338,7 +338,7 @@ var _ = Describe("Lifecycle", func() { network.PeerAddress(org1peer0, nwo.ListenPort), } - sess, err = network.PeerUserSession(org3peer0, "User1", commands.ChaincodeInvoke{ + sess, err = network.PeerCliUserSession(org3peer0, "User1", commands.ChaincodeInvoke{ ChannelID: "testchannel", Orderer: network.OrdererAddress(orderer, nwo.ListenPort), Name: "My_1st-Chaincode", @@ -377,7 +377,7 @@ var _ = Describe("Lifecycle", func() { nwo.DeployChaincode(network, "testchannel", orderer, chaincode) By("attempting to invoke the chaincode without a majority") - sess, err = network.PeerUserSession(org3peer0, "User1", commands.ChaincodeInvoke{ + sess, err = network.PeerCliUserSession(org3peer0, "User1", commands.ChaincodeInvoke{ ChannelID: "testchannel", Orderer: network.OrdererAddress(orderer, nwo.ListenPort), Name: "defaultpolicycc", @@ -389,7 +389,7 @@ var _ = Describe("Lifecycle", func() { Expect(sess.Err).To(gbytes.Say(`\QError: transaction invalidated with status (ENDORSEMENT_POLICY_FAILURE)\E`)) By("attempting to invoke the chaincode with a majority") - sess, err = network.PeerUserSession(org3peer0, "User1", commands.ChaincodeInvoke{ + sess, err = network.PeerCliUserSession(org3peer0, "User1", commands.ChaincodeInvoke{ ChannelID: "testchannel", Orderer: network.OrdererAddress(orderer, nwo.ListenPort), Name: "defaultpolicycc", diff --git a/integration/msp/msp_test.go b/integration/msp/msp_test.go index fc8aeb40ff1..f743ff0b5d5 100644 --- a/integration/msp/msp_test.go +++ b/integration/msp/msp_test.go @@ -106,7 +106,7 @@ var _ = Describe("MSP identity test on a network with mutual TLS required", func RunQueryInvokeQuery(network, orderer, org1Peer0, 100) By("querying the chaincode with org2 peer") - sess, err := network.PeerUserSession(org2Peer0, "User1", commands.ChaincodeQuery{ + sess, err := network.PeerCliUserSession(org2Peer0, "User1", commands.ChaincodeQuery{ ChannelID: "testchannel", Name: "mycc", Ctor: `{"Args":["query","a"]}`, @@ -118,7 +118,7 @@ var _ = Describe("MSP identity test on a network with mutual TLS required", func // Testing scenario one: chaincode endorsement policy not satisfied due to peer's MSP does not define // the peer node OU. By("attempting to invoke chaincode on a peer that does not have a valid endorser identity (endorsing peer has member identity)") - sess, err = network.PeerUserSession(org2Peer0, "User1", commands.ChaincodeInvoke{ + sess, err = network.PeerCliUserSession(org2Peer0, "User1", commands.ChaincodeInvoke{ ChannelID: "testchannel", Orderer: network.OrdererAddress(orderer, nwo.ListenPort), Name: "mycc", @@ -134,7 +134,7 @@ var _ = Describe("MSP identity test on a network with mutual TLS required", func Expect(sess.Err).To(gbytes.Say(`(ENDORSEMENT_POLICY_FAILURE)`)) By("reverifying the channel was not affected by the unauthorized endorsement") - sess, err = network.PeerUserSession(org2Peer0, "User1", commands.ChaincodeQuery{ + sess, err = network.PeerCliUserSession(org2Peer0, "User1", commands.ChaincodeQuery{ ChannelID: "testchannel", Name: "mycc", Ctor: `{"Args":["query","a"]}`, @@ -160,7 +160,7 @@ var _ = Describe("MSP identity test on a network with mutual TLS required", func ordererRunner, ordererProcess, peerProcess = nwo.RestartSingleOrdererNetwork(ordererProcess, peerProcess, network) By("attempting to invoke chaincode on a peer that does not have a valid endorser identity (endorsing peer has client identity)") - sess, err = network.PeerUserSession(org1Peer0, "User1", commands.ChaincodeInvoke{ + sess, err = network.PeerCliUserSession(org1Peer0, "User1", commands.ChaincodeInvoke{ ChannelID: "testchannel", Orderer: network.OrdererAddress(orderer, nwo.ListenPort), Name: "mycc", @@ -176,7 +176,7 @@ var _ = Describe("MSP identity test on a network with mutual TLS required", func Expect(sess.Err).To(gbytes.Say(`(ENDORSEMENT_POLICY_FAILURE)`)) By("reverifying the channel was not affected by the unauthorized endorsement") - sess, err = network.PeerUserSession(org1Peer0, "User1", commands.ChaincodeQuery{ + sess, err = network.PeerCliUserSession(org1Peer0, "User1", commands.ChaincodeQuery{ ChannelID: "testchannel", Name: "mycc", Ctor: `{"Args":["query","a"]}`, @@ -190,7 +190,7 @@ var _ = Describe("MSP identity test on a network with mutual TLS required", func }) func RunQueryInvokeQuery(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer, initialQueryResult int) { - sess, err := n.PeerUserSession(peer, "User1", commands.ChaincodeQuery{ + sess, err := n.PeerCliUserSession(peer, "User1", commands.ChaincodeQuery{ ChannelID: "testchannel", Name: "mycc", Ctor: `{"Args":["query","a"]}`, @@ -199,7 +199,7 @@ func RunQueryInvokeQuery(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer, i Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0)) Expect(sess).To(gbytes.Say(fmt.Sprint(initialQueryResult))) - sess, err = n.PeerUserSession(peer, "User1", commands.ChaincodeInvoke{ + sess, err = n.PeerCliUserSession(peer, "User1", commands.ChaincodeInvoke{ ChannelID: "testchannel", Orderer: n.OrdererAddress(orderer, nwo.ListenPort), Name: "mycc", @@ -215,7 +215,7 @@ func RunQueryInvokeQuery(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer, i Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0)) Expect(sess.Err).To(gbytes.Say("Chaincode invoke successful. result: status:200")) - sess, err = n.PeerUserSession(peer, "User1", commands.ChaincodeQuery{ + sess, err = n.PeerCliUserSession(peer, "User1", commands.ChaincodeQuery{ ChannelID: "testchannel", Name: "mycc", Ctor: `{"Args":["query","a"]}`, diff --git a/integration/nwo/components.go b/integration/nwo/components.go index 30434fd19a4..b2f19d175bc 100644 --- a/integration/nwo/components.go +++ b/integration/nwo/components.go @@ -50,6 +50,10 @@ func (c *Components) Peer() string { return c.Build("github.com/hyperledger/fabric/cmd/peer") } +func (c *Components) PeerCli() string { + return c.Build("github.com/hyperledger/fabric/cmd/peercli") +} + func (c *Components) Cleanup() {} func (c *Components) Build(path string) string { diff --git a/integration/nwo/configblock.go b/integration/nwo/configblock.go index fe28628c8a2..c25de65d20a 100644 --- a/integration/nwo/configblock.go +++ b/integration/nwo/configblock.go @@ -105,7 +105,7 @@ func UpdateConfig(n *Network, orderer *Orderer, channel string, current, updated Expect(err).NotTo(HaveOccurred()) for _, signer := range additionalSigners { - sess, err := n.PeerAdminSession(signer, commands.SignConfigTx{ + sess, err := n.PeerCliAdminSession(signer, commands.SignConfigTx{ File: updateFile, ClientAuth: n.ClientAuthRequired, }) @@ -122,7 +122,7 @@ func UpdateConfig(n *Network, orderer *Orderer, channel string, current, updated Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0)) } - sess, err := n.PeerAdminSession(submitter, commands.SignConfigTx{ + sess, err := n.PeerCliAdminSession(submitter, commands.SignConfigTx{ File: updateFile, ClientAuth: n.ClientAuthRequired, }) @@ -188,7 +188,7 @@ func CurrentConfigBlockNumber(n *Network, peer *Peer, orderer *Orderer, channel // CurrentConfigBlockNumberFromPeer retrieves the block number from the header // of the peer's current config block. func CurrentConfigBlockNumberFromPeer(n *Network, peer *Peer, channel, output string) uint64 { - sess, err := n.PeerAdminSession(peer, commands.ChannelFetch{ + sess, err := n.PeerCliAdminSession(peer, commands.ChannelFetch{ ChannelID: channel, Block: "config", OutputFile: output, diff --git a/integration/nwo/deploy.go b/integration/nwo/deploy.go index 218e392346a..85de7f49efa 100644 --- a/integration/nwo/deploy.go +++ b/integration/nwo/deploy.go @@ -116,7 +116,7 @@ func PackageAndInstallChaincode(n *Network, chaincode Chaincode, peers ...*Peer) } func PackageChaincode(n *Network, chaincode Chaincode, peer *Peer) { - sess, err := n.PeerAdminSession(peer, commands.ChaincodePackage{ + sess, err := n.PeerCliAdminSession(peer, commands.ChaincodePackage{ Path: chaincode.Path, Lang: chaincode.Lang, Label: chaincode.Label, @@ -128,7 +128,7 @@ func PackageChaincode(n *Network, chaincode Chaincode, peer *Peer) { } func CheckPackageID(n *Network, packageFile string, packageID string, peer *Peer) { - sess, err := n.PeerAdminSession(peer, commands.ChaincodeCalculatePackageID{ + sess, err := n.PeerCliAdminSession(peer, commands.ChaincodeCalculatePackageID{ PackageFile: packageFile, ClientAuth: n.ClientAuthRequired, }) @@ -147,7 +147,7 @@ func InstallChaincode(n *Network, chaincode Chaincode, peers ...*Peer) { } for _, p := range peers { - sess, err := n.PeerAdminSession(p, commands.ChaincodeInstall{ + sess, err := n.PeerCliAdminSession(p, commands.ChaincodeInstall{ PackageFile: chaincode.PackageFile, ClientAuth: n.ClientAuthRequired, }) @@ -168,7 +168,7 @@ func ApproveChaincodeForMyOrg(n *Network, channel string, orderer *Orderer, chai approvedOrgs := map[string]bool{} for _, p := range peers { if _, ok := approvedOrgs[p.Organization]; !ok { - sess, err := n.PeerAdminSession(p, commands.ChaincodeApproveForMyOrg{ + sess, err := n.PeerCliAdminSession(p, commands.ChaincodeApproveForMyOrg{ ChannelID: channel, Orderer: n.OrdererAddress(orderer, ListenPort), Name: chaincode.Name, @@ -225,7 +225,7 @@ func CommitChaincode(n *Network, channel string, orderer *Orderer, chaincode Cha } } - sess, err := n.PeerAdminSession(peer, commands.ChaincodeCommit{ + sess, err := n.PeerCliAdminSession(peer, commands.ChaincodeCommit{ ChannelID: channel, Orderer: n.OrdererAddress(orderer, ListenPort), Name: chaincode.Name, @@ -284,7 +284,7 @@ func InitChaincode(n *Network, channel string, orderer *Orderer, chaincode Chain } } - sess, err := n.PeerUserSession(peers[0], "User1", commands.ChaincodeInvoke{ + sess, err := n.PeerCliUserSession(peers[0], "User1", commands.ChaincodeInvoke{ ChannelID: channel, Orderer: n.OrdererAddress(orderer, ListenPort), Name: chaincode.Name, @@ -345,7 +345,7 @@ type queryInstalledOutput struct { func QueryInstalled(n *Network, peer *Peer) func() []lifecycle.QueryInstalledChaincodesResult_InstalledChaincode { return func() []lifecycle.QueryInstalledChaincodesResult_InstalledChaincode { - sess, err := n.PeerAdminSession(peer, commands.ChaincodeQueryInstalled{ + sess, err := n.PeerCliAdminSession(peer, commands.ChaincodeQueryInstalled{ ClientAuth: n.ClientAuthRequired, }) Expect(err).NotTo(HaveOccurred()) @@ -363,7 +363,7 @@ type checkCommitReadinessOutput struct { func checkCommitReadiness(n *Network, peer *Peer, channel string, chaincode Chaincode) func() map[string]bool { return func() map[string]bool { - sess, err := n.PeerAdminSession(peer, commands.ChaincodeCheckCommitReadiness{ + sess, err := n.PeerCliAdminSession(peer, commands.ChaincodeCheckCommitReadiness{ ChannelID: channel, Name: chaincode.Name, Version: chaincode.Version, @@ -389,7 +389,7 @@ func checkCommitReadiness(n *Network, peer *Peer, channel string, chaincode Chai // command with inspection enabled. This is to verify that the network can detect differences in chaincode definitions, // particularly when comparing with mismatched parameters from the approved definitions by each organizations. func InspectChaincodeDiscrepancies(n *Network, channel string, chaincode Chaincode, checkOrgs []*Organization, peers ...*Peer) { - sess, err := n.PeerAdminSession(peers[0], commands.ChaincodeCheckCommitReadiness{ + sess, err := n.PeerCliAdminSession(peers[0], commands.ChaincodeCheckCommitReadiness{ ChannelID: channel, Name: chaincode.Name, Version: "mismatched-version", // Intentionally set mismatched version @@ -427,7 +427,7 @@ type queryApprovedOutput struct { // If the command fails for any reason, it will return an empty output object. func queryApproved(n *Network, peer *Peer, channel, name, sequence string) func() queryApprovedOutput { return func() queryApprovedOutput { - sess, err := n.PeerAdminSession(peer, commands.ChaincodeQueryApproved{ + sess, err := n.PeerCliAdminSession(peer, commands.ChaincodeQueryApproved{ ChannelID: channel, Name: name, Sequence: sequence, @@ -458,7 +458,7 @@ type queryCommittedOutput struct { // or a database access issue), it will return an empty output object. func listCommitted(n *Network, peer *Peer, channel, name string) func() queryCommittedOutput { return func() queryCommittedOutput { - sess, err := n.PeerAdminSession(peer, commands.ChaincodeListCommitted{ + sess, err := n.PeerCliAdminSession(peer, commands.ChaincodeListCommitted{ ChannelID: channel, Name: name, ClientAuth: n.ClientAuthRequired, @@ -537,7 +537,7 @@ func WaitUntilEqualLedgerHeight(n *Network, channel string, height int, peers .. // GetLedgerHeight returns the current ledger height for a peer on // a channel func GetLedgerHeight(n *Network, peer *Peer, channel string) int { - sess, err := n.PeerUserSession(peer, "User1", commands.ChannelInfo{ + sess, err := n.PeerCliUserSession(peer, "User1", commands.ChannelInfo{ ChannelID: channel, ClientAuth: n.ClientAuthRequired, }) diff --git a/integration/nwo/network.go b/integration/nwo/network.go index 29ad5919d4d..33391d201b9 100644 --- a/integration/nwo/network.go +++ b/integration/nwo/network.go @@ -910,7 +910,7 @@ func (n *Network) bootstrapIdemix() { } // ConcatenateTLSCACertificates concatenates all TLS CA certificates into a -// single file to be used by peer CLI. +// single file to be used by peercli. func (n *Network) ConcatenateTLSCACertificates() { bundle := &bytes.Buffer{} for _, tlsCertPath := range n.listTLSCACertificates() { @@ -1080,7 +1080,7 @@ func (n *Network) CreateChannel(channelName string, o *Orderer, p *Peer, additio n.signConfigTransaction(channelCreateTxPath, p, additionalSigners...) createChannel := func() int { - sess, err := n.PeerAdminSession(p, commands.ChannelCreate{ + sess, err := n.PeerCliAdminSession(p, commands.ChannelCreate{ ChannelID: channelName, Orderer: n.OrdererAddress(o, ListenPort), File: channelCreateTxPath, @@ -1104,7 +1104,7 @@ func (n *Network) CreateChannelExitCode(channelName string, o *Orderer, p *Peer, channelCreateTxPath := n.CreateChannelTxPath(channelName) n.signConfigTransaction(channelCreateTxPath, p, additionalSigners...) - sess, err := n.PeerAdminSession(p, commands.ChannelCreate{ + sess, err := n.PeerCliAdminSession(p, commands.ChannelCreate{ ChannelID: channelName, Orderer: n.OrdererAddress(o, ListenPort), File: channelCreateTxPath, @@ -1119,7 +1119,7 @@ func (n *Network) signConfigTransaction(channelTxPath string, submittingPeer *Pe for _, signer := range signers { switch signer := signer.(type) { case *Peer: - sess, err := n.PeerAdminSession(signer, commands.SignConfigTx{ + sess, err := n.PeerCliAdminSession(signer, commands.SignConfigTx{ File: channelTxPath, ClientAuth: n.ClientAuthRequired, }) @@ -1177,7 +1177,7 @@ func (n *Network) JoinChannel(name string, o *Orderer, peers ...*Peer) { }, n.EventuallyTimeout, time.Second).Should(BeEmpty()) for _, p := range peers { - sess, err := n.PeerAdminSession(p, commands.ChannelJoin{ + sess, err := n.PeerCliAdminSession(p, commands.ChannelJoin{ BlockPath: tempFile.Name(), ClientAuth: n.ClientAuthRequired, }) @@ -1192,7 +1192,7 @@ func (n *Network) JoinChannelBySnapshot(snapshotDir string, peers ...*Peer) { } for _, p := range peers { - sess, err := n.PeerAdminSession(p, commands.ChannelJoinBySnapshot{ + sess, err := n.PeerCliAdminSession(p, commands.ChannelJoinBySnapshot{ SnapshotPath: snapshotDir, ClientAuth: n.ClientAuthRequired, }) @@ -1202,7 +1202,7 @@ func (n *Network) JoinChannelBySnapshot(snapshotDir string, peers ...*Peer) { } func (n *Network) JoinBySnapshotStatus(p *Peer) string { - sess, err := n.PeerAdminSession(p, commands.ChannelJoinBySnapshotStatus{ + sess, err := n.PeerCliAdminSession(p, commands.ChannelJoinBySnapshotStatus{ ClientAuth: n.ClientAuthRequired, }) Expect(err).NotTo(HaveOccurred()) @@ -1331,9 +1331,45 @@ func (n *Network) peerCommand(command Command, tlsDir string, env ...string) *ex } // In case we have a peer invoke with multiple certificates, we need to mimic - // the correct peer CLI usage, so we count the number of --peerAddresses + // the correct peer usage, so we count the number of --peerAddresses // usages we have, and add the same (concatenated TLS CA certificates file) - // the same number of times to bypass the peer CLI sanity checks + // the same number of times to bypass the peer sanity checks + requiredPeerAddresses := flagCount("--peerAddresses", cmd.Args) + for i := 0; i < requiredPeerAddresses; i++ { + cmd.Args = append(cmd.Args, "--tlsRootCertFiles") + cmd.Args = append(cmd.Args, n.CACertsBundlePath()) + } + + // If there is --peerAddress, add --tlsRootCertFile parameter + requiredPeerAddress := flagCount("--peerAddress", cmd.Args) + if requiredPeerAddress > 0 { + cmd.Args = append(cmd.Args, "--tlsRootCertFile") + cmd.Args = append(cmd.Args, n.CACertsBundlePath()) + } + return cmd +} + +func (n *Network) peerCliCommand(command Command, tlsDir string, env ...string) *exec.Cmd { + cmd := NewCommand(n.Components.PeerCli(), command) + cmd.Env = append(cmd.Env, env...) + + if connectsToOrderer(command) && n.TLSEnabled { + cmd.Args = append(cmd.Args, "--tls") + cmd.Args = append(cmd.Args, "--cafile", n.CACertsBundlePath()) + } + + if clientAuthEnabled(command) { + certfilePath := filepath.Join(tlsDir, "client.crt") + keyfilePath := filepath.Join(tlsDir, "client.key") + + cmd.Args = append(cmd.Args, "--certfile", certfilePath) + cmd.Args = append(cmd.Args, "--keyfile", keyfilePath) + } + + // In case we have a peer invoke with multiple certificates, we need to mimic + // the correct peercli usage, so we count the number of --peerAddresses + // usages we have, and add the same (concatenated TLS CA certificates file) + // the same number of times to bypass the peercli sanity checks requiredPeerAddresses := flagCount("--peerAddresses", cmd.Args) for range requiredPeerAddresses { cmd.Args = append(cmd.Args, "--tlsRootCertFiles") @@ -1367,15 +1403,29 @@ func flagCount(flag string, args []string) int { return c } -// PeerAdminSession starts a gexec.Session as a peer admin for the provided -// peer command. This is intended to be used by short running peer cli commands +// PeerCliAdminSession starts a gexec.Session as a peer admin for the provided +// peer command. This is intended to be used by short running peercli commands // that execute in the context of a peer configuration. -func (n *Network) PeerAdminSession(p *Peer, command Command) (*gexec.Session, error) { - return n.PeerUserSession(p, "Admin", command) +func (n *Network) PeerCliAdminSession(p *Peer, command Command) (*gexec.Session, error) { + return n.PeerCliUserSession(p, "Admin", command) +} + +// PeerCliUserSession starts a gexec.Session as a peer user for the provided peer +// command. This is intended to be used by short running peercli commands that +// execute in the context of a peer configuration. +func (n *Network) PeerCliUserSession(p *Peer, user string, command Command) (*gexec.Session, error) { + cmd := n.peerCliCommand( + command, + n.PeerUserTLSDir(p, user), + fmt.Sprintf("FABRIC_CFG_PATH=%s", n.PeerDir(p)), + fmt.Sprintf("CORE_PEER_MSPCONFIGPATH=%s", n.PeerUserMSPDir(p, user)), + fabricLoggingSpec, + ) + return n.StartSession(cmd, command.SessionName()) } // PeerUserSession starts a gexec.Session as a peer user for the provided peer -// command. This is intended to be used by short running peer cli commands that +// command. This is intended to be used by short running peer commands that // execute in the context of a peer configuration. func (n *Network) PeerUserSession(p *Peer, user string, command Command) (*gexec.Session, error) { cmd := n.peerCommand( @@ -1456,10 +1506,10 @@ func (n *Network) NewClientConn(address, caCertPath string, clientCertPath strin } // IdemixUserSession starts a gexec.Session as a idemix user for the provided peer -// command. This is intended to be used by short running peer cli commands that +// command. This is intended to be used by short running peercli commands that // execute in the context of a peer configuration. func (n *Network) IdemixUserSession(p *Peer, idemixOrg *Organization, user string, command Command) (*gexec.Session, error) { - cmd := n.peerCommand( + cmd := n.peerCliCommand( command, n.PeerUserTLSDir(p, user), fmt.Sprintf("FABRIC_CFG_PATH=%s", n.PeerDir(p)), @@ -1474,7 +1524,7 @@ func (n *Network) IdemixUserSession(p *Peer, idemixOrg *Organization, user strin // OrdererAdminSession starts a gexec.Session as an orderer admin user. This // is used primarily to generate orderer configuration updates. func (n *Network) OrdererAdminSession(o *Orderer, p *Peer, command Command) (*gexec.Session, error) { - cmd := n.peerCommand( + cmd := n.peerCliCommand( command, n.ordererUserCryptoDir(o, "Admin", "tls"), fmt.Sprintf("CORE_PEER_LOCALMSPID=%s", n.Organization(o.Organization).MSPID), diff --git a/integration/nwo/network_test.go b/integration/nwo/network_test.go index 3511b990e0d..dc9453df130 100644 --- a/integration/nwo/network_test.go +++ b/integration/nwo/network_test.go @@ -108,7 +108,7 @@ var _ = Describe("Network", func() { func RunQueryInvokeQuery(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer, initialQueryResult int) { By("querying the chaincode") - sess, err := n.PeerUserSession(peer, "User1", commands.ChaincodeQuery{ + sess, err := n.PeerCliUserSession(peer, "User1", commands.ChaincodeQuery{ ChannelID: "testchannel", Name: "mycc", Ctor: `{"Args":["query","a"]}`, @@ -117,7 +117,7 @@ func RunQueryInvokeQuery(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer, i Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0)) Expect(sess).To(gbytes.Say(fmt.Sprint(initialQueryResult))) - sess, err = n.PeerUserSession(peer, "User1", commands.ChaincodeInvoke{ + sess, err = n.PeerCliUserSession(peer, "User1", commands.ChaincodeInvoke{ ChannelID: "testchannel", Orderer: n.OrdererAddress(orderer, nwo.ListenPort), Name: "mycc", @@ -132,7 +132,7 @@ func RunQueryInvokeQuery(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer, i Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0)) Expect(sess.Err).To(gbytes.Say("Chaincode invoke successful. result: status:200")) - sess, err = n.PeerUserSession(peer, "User1", commands.ChaincodeQuery{ + sess, err = n.PeerCliUserSession(peer, "User1", commands.ChaincodeQuery{ ChannelID: "testchannel", Name: "mycc", Ctor: `{"Args":["query","a"]}`, diff --git a/integration/pkcs11/pkcs11_suite_test.go b/integration/pkcs11/pkcs11_suite_test.go index 3e887eca826..e69f045ad09 100644 --- a/integration/pkcs11/pkcs11_suite_test.go +++ b/integration/pkcs11/pkcs11_suite_test.go @@ -60,7 +60,7 @@ func StartPort() int { func runQueryInvokeQuery(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer, channel string) { By("querying the chaincode") - sess, err := n.PeerUserSession(peer, "User1", commands.ChaincodeQuery{ + sess, err := n.PeerCliUserSession(peer, "User1", commands.ChaincodeQuery{ ChannelID: channel, Name: "mycc", Ctor: `{"Args":["query","a"]}`, @@ -69,7 +69,7 @@ func runQueryInvokeQuery(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer, c Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0)) Expect(sess).To(gbytes.Say("100")) - sess, err = n.PeerUserSession(peer, "User1", commands.ChaincodeInvoke{ + sess, err = n.PeerCliUserSession(peer, "User1", commands.ChaincodeInvoke{ ChannelID: channel, Orderer: n.OrdererAddress(orderer, nwo.ListenPort), Name: "mycc", @@ -84,7 +84,7 @@ func runQueryInvokeQuery(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer, c Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0)) Expect(sess.Err).To(gbytes.Say("Chaincode invoke successful. result: status:200")) - sess, err = n.PeerUserSession(peer, "User1", commands.ChaincodeQuery{ + sess, err = n.PeerCliUserSession(peer, "User1", commands.ChaincodeQuery{ ChannelID: channel, Name: "mycc", Ctor: `{"Args":["query","a"]}`, diff --git a/integration/pluggable/pluggable_test.go b/integration/pluggable/pluggable_test.go index eb6e7341ff9..385d50ba6d8 100644 --- a/integration/pluggable/pluggable_test.go +++ b/integration/pluggable/pluggable_test.go @@ -169,7 +169,7 @@ func configurePlugins(network *nwo.Network, endorsement, validation string) { func RunQueryInvokeQuery(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer) { By("querying the chaincode") - sess, err := n.PeerUserSession(peer, "User1", commands.ChaincodeQuery{ + sess, err := n.PeerCliUserSession(peer, "User1", commands.ChaincodeQuery{ ChannelID: "testchannel", Name: "mycc", Ctor: `{"Args":["query","a"]}`, @@ -178,7 +178,7 @@ func RunQueryInvokeQuery(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer) { Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0)) Expect(sess).To(gbytes.Say("100")) - sess, err = n.PeerUserSession(peer, "User1", commands.ChaincodeInvoke{ + sess, err = n.PeerCliUserSession(peer, "User1", commands.ChaincodeInvoke{ ChannelID: "testchannel", Orderer: n.OrdererAddress(orderer, nwo.ListenPort), Name: "mycc", @@ -193,7 +193,7 @@ func RunQueryInvokeQuery(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer) { Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0)) Expect(sess.Err).To(gbytes.Say("Chaincode invoke successful. result: status:200")) - sess, err = n.PeerUserSession(peer, "User1", commands.ChaincodeQuery{ + sess, err = n.PeerCliUserSession(peer, "User1", commands.ChaincodeQuery{ ChannelID: "testchannel", Name: "mycc", Ctor: `{"Args":["query","a"]}`, diff --git a/integration/pvtdata/implicit_coll_test.go b/integration/pvtdata/implicit_coll_test.go index f3c460e9bb3..454f77b8c40 100644 --- a/integration/pvtdata/implicit_coll_test.go +++ b/integration/pvtdata/implicit_coll_test.go @@ -173,14 +173,14 @@ func readImplicitCollection(n *nwo.Network, peer *nwo.Peer, chaincodeName string } func invokeChaincode(n *nwo.Network, peer *nwo.Peer, command commands.ChaincodeInvoke) { - sess, err := n.PeerUserSession(peer, "User1", command) + sess, err := n.PeerCliUserSession(peer, "User1", command) Expect(err).NotTo(HaveOccurred()) Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0)) Expect(sess.Err).To(gbytes.Say("Chaincode invoke successful.")) } func queryChaincode(n *nwo.Network, peer *nwo.Peer, command commands.ChaincodeQuery, expectedMessage string, expectSuccess bool) { - sess, err := n.PeerUserSession(peer, "User1", command) + sess, err := n.PeerCliUserSession(peer, "User1", command) Expect(err).NotTo(HaveOccurred()) if expectSuccess { Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0)) diff --git a/integration/pvtdata/marblechaincodeutil/testutil.go b/integration/pvtdata/marblechaincodeutil/testutil.go index 5968a80fbff..5b4ddc3862f 100644 --- a/integration/pvtdata/marblechaincodeutil/testutil.go +++ b/integration/pvtdata/marblechaincodeutil/testutil.go @@ -13,7 +13,6 @@ import ( "github.com/hyperledger/fabric/integration/nwo" "github.com/hyperledger/fabric/integration/nwo/commands" - . "github.com/onsi/gomega" "github.com/onsi/gomega/gbytes" "github.com/onsi/gomega/gexec" @@ -148,7 +147,7 @@ func CheckPresentInCollectionM(n *nwo.Network, channelID, chaincodeName, marbleN } present := 0 for _, peer := range peerList { - sess, err := n.PeerUserSession(peer, "User1", command) + sess, err := n.PeerCliUserSession(peer, "User1", command) Expect(err).NotTo(HaveOccurred()) Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit()) if bytes.Contains(sess.Buffer().Contents(), []byte(expectedMsg)) { @@ -170,7 +169,7 @@ func CheckPresentInCollectionMPD(n *nwo.Network, channelID, chaincodeName, marbl } present := 0 for _, peer := range peerList { - sess, err := n.PeerUserSession(peer, "User1", command) + sess, err := n.PeerCliUserSession(peer, "User1", command) Expect(err).NotTo(HaveOccurred()) Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit()) if bytes.Contains(sess.Buffer().Contents(), []byte(expectedMsg)) { @@ -253,21 +252,21 @@ func AssertMarblesPrivateDetailsHashMPD(n *nwo.Network, channelID, chaincodeName // AssertInvokeChaincodeFails asserts that a chaincode invoke fails with a specified error message func AssertInvokeChaincodeFails(n *nwo.Network, peer *nwo.Peer, command commands.ChaincodeInvoke, expectedMessage string) { - sess, err := n.PeerUserSession(peer, "User1", command) + sess, err := n.PeerCliUserSession(peer, "User1", command) Expect(err).NotTo(HaveOccurred()) Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit()) Expect(sess.Err).To(gbytes.Say(expectedMessage)) } func invokeChaincode(n *nwo.Network, peer *nwo.Peer, command commands.ChaincodeInvoke) { - sess, err := n.PeerUserSession(peer, "User1", command) + sess, err := n.PeerCliUserSession(peer, "User1", command) Expect(err).NotTo(HaveOccurred()) Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0)) Expect(sess.Err).To(gbytes.Say("Chaincode invoke successful.")) } func queryChaincode(n *nwo.Network, peer *nwo.Peer, command commands.ChaincodeQuery, expectedMessage string, expectSuccess bool) { - sess, err := n.PeerUserSession(peer, "User1", command) + sess, err := n.PeerCliUserSession(peer, "User1", command) Expect(err).NotTo(HaveOccurred()) if expectSuccess { Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0)) @@ -288,7 +287,7 @@ func verifyPvtdataHash(n *nwo.Network, query, channelID, chaincodeName string, p } for _, peer := range peers { - sess, err := n.PeerUserSession(peer, "User1", command) + sess, err := n.PeerCliUserSession(peer, "User1", command) Expect(err).NotTo(HaveOccurred()) Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0)) actual := sess.Buffer().Contents() diff --git a/integration/pvtdata/pvtdata_test.go b/integration/pvtdata/pvtdata_test.go index 28cfe53a09b..9cdae79c5b4 100644 --- a/integration/pvtdata/pvtdata_test.go +++ b/integration/pvtdata/pvtdata_test.go @@ -284,7 +284,7 @@ var _ = Describe("PrivateData", func() { err = os.WriteFile(tempFile.Name(), b, 0o644) Expect(err).NotTo(HaveOccurred()) - sess, err := network.PeerUserSession(org2Peer1, "Admin2", commands.ChannelJoin{ + sess, err := network.PeerCliUserSession(org2Peer1, "Admin2", commands.ChannelJoin{ BlockPath: tempFile.Name(), }) Expect(err).NotTo(HaveOccurred()) @@ -314,7 +314,7 @@ var _ = Describe("PrivateData", func() { Sequence: "1", } - sess, err = network.PeerUserSession(org2Peer1, "Admin2", commands.ChaincodeInstall{ + sess, err = network.PeerCliUserSession(org2Peer1, "Admin2", commands.ChaincodeInstall{ PackageFile: chaincode.PackageFile, ClientAuth: network.ClientAuthRequired, }) @@ -337,7 +337,7 @@ var _ = Describe("PrivateData", func() { ) if peer.ID() == "Org2.peer1" { // use Admin2 user for peer1.org2 - sess, err = network.PeerUserSession(peer, "Admin2", commands.ChannelInfo{ + sess, err = network.PeerCliUserSession(peer, "Admin2", commands.ChannelInfo{ ChannelID: channelID, }) Expect(err).NotTo(HaveOccurred()) @@ -371,7 +371,7 @@ var _ = Describe("PrivateData", func() { By("verifying peer1.org2 got the private data that was created historically") Eventually(func() bool { - sess, err = network.PeerUserSession(org2Peer1, "Admin2", commands.ChaincodeQuery{ + sess, err = network.PeerCliUserSession(org2Peer1, "Admin2", commands.ChaincodeQuery{ ChannelID: channelID, Name: "marblesp", Ctor: `{"Args":["readMarble","marble1"]}`, @@ -386,7 +386,7 @@ var _ = Describe("PrivateData", func() { return true }, network.EventuallyTimeout).Should(BeTrue()) - sess, err = network.PeerUserSession(org2Peer1, "Admin2", commands.ChaincodeQuery{ + sess, err = network.PeerCliUserSession(org2Peer1, "Admin2", commands.ChaincodeQuery{ ChannelID: channelID, Name: "marblesp", Ctor: `{"Args":["readMarblePrivateDetails","marble1"]}`, @@ -605,7 +605,7 @@ var _ = Describe("PrivateData", func() { WaitForEvent: true, } - sess, err := network.PeerUserSession(peer, "User1", command) + sess, err := network.PeerCliUserSession(peer, "User1", command) Expect(err).NotTo(HaveOccurred()) Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit()) Expect(sess.Err).To(gbytes.Say("ENDORSEMENT_POLICY_FAILURE")) @@ -678,7 +678,7 @@ var _ = Describe("PrivateData", func() { WaitForEvent: true, } - sess, err := network.PeerUserSession(peer, "User1", command) + sess, err := network.PeerCliUserSession(peer, "User1", command) Expect(err).NotTo(HaveOccurred()) Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit()) Expect(sess.Err).To(gbytes.Say("ENDORSEMENT_POLICY_FAILURE")) @@ -976,7 +976,7 @@ func installChaincode(n *nwo.Network, chaincode nwo.Chaincode, peer *nwo.Peer) { } func invokeChaincodeExpectErr(n *nwo.Network, peer *nwo.Peer, command commands.ChaincodeInvoke, expectedErrMsgs []string) { - sess, err := n.PeerUserSession(peer, "User1", command) + sess, err := n.PeerCliUserSession(peer, "User1", command) Expect(err).NotTo(HaveOccurred()) Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(1)) for _, msg := range expectedErrMsgs { @@ -989,7 +989,7 @@ func approveChaincodeForMyOrgExpectErr(n *nwo.Network, orderer *nwo.Orderer, cha approvedOrgs := map[string]bool{} for _, p := range peers { if _, ok := approvedOrgs[p.Organization]; !ok { - sess, err := n.PeerAdminSession(p, commands.ChaincodeApproveForMyOrg{ + sess, err := n.PeerCliAdminSession(p, commands.ChaincodeApproveForMyOrg{ ChannelID: channelID, Orderer: n.OrdererAddress(orderer, nwo.ListenPort), Name: chaincode.Name, @@ -1275,7 +1275,7 @@ func getValueForCollectionMarblePrivateDetails(marbleName string, price int) []b // It skips the orderer and returns the session's Err buffer for parsing. func fetchBlocksForPeer(n *nwo.Network, peer *nwo.Peer, user string) func() *gbytes.Buffer { return func() *gbytes.Buffer { - sess, err := n.PeerUserSession(peer, user, commands.ChannelFetch{ + sess, err := n.PeerCliUserSession(peer, user, commands.ChannelFetch{ Block: "newest", ChannelID: channelID, OutputFile: filepath.Join(n.RootDir, "newest_block.pb"), diff --git a/integration/raft/config_test.go b/integration/raft/config_test.go index 768119f34e9..b25e3113fc9 100644 --- a/integration/raft/config_test.go +++ b/integration/raft/config_test.go @@ -104,23 +104,20 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { orderer1 := network.Orderer("orderer1") orderer2 := network.Orderer("orderer2") orderer3 := network.Orderer("orderer3") - peer := network.Peer("Org1", "peer0") blockFile1 := filepath.Join(testDir, "newest_orderer1_block.pb") blockFile2 := filepath.Join(testDir, "newest_orderer2_block.pb") blockFile3 := filepath.Join(testDir, "newest_orderer3_block.pb") fetchLatestBlock := func(targetOrderer *nwo.Orderer, blockFile string) { - c := commands.ChannelFetch{ - ChannelID: "testchannel", - Block: "newest", - OutputFile: blockFile, - } - if targetOrderer != nil { - c.Orderer = network.OrdererAddress(targetOrderer, nwo.ListenPort) - } - sess, err := network.PeerAdminSession(peer, c) + block, err := nwo.Fetch(network, targetOrderer, "testchannel", "newest") + Expect(err).NotTo(HaveOccurred()) + Expect(block).NotTo(BeNil()) + + b, err := proto.Marshal(block) + Expect(err).NotTo(HaveOccurred()) + + err = os.WriteFile(blockFile, b, 0o644) Expect(err).NotTo(HaveOccurred()) - Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit(0)) } By("Creating a new channel, joining all orderers") @@ -716,17 +713,9 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { } By("Getting the last config block from testchannel and using it as a template for testchannel2 and testchannel3 genesis block") - blockFile := filepath.Join(testDir, "testchannel_last_config_block.pb") - c := commands.ChannelFetch{ - ChannelID: "testchannel", - Block: "newest", - OutputFile: blockFile, - } - c.Orderer = network.OrdererAddress(o1, nwo.ListenPort) - sess, err := network.PeerAdminSession(peer, c) + lastConfigBlock, err := nwo.Fetch(network, o1, "testchannel", "newest") Expect(err).NotTo(HaveOccurred()) - Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit(0)) - lastConfigBlock := nwo.UnmarshalBlockFromFile(blockFile) + Expect(lastConfigBlock).NotTo(BeNil()) genesisBlock2 := configToGenesisBlock(lastConfigBlock, "testchannel2") genesisBytes2, err := protoutil.Marshal(genesisBlock2) diff --git a/integration/raft/migration_test.go b/integration/raft/migration_test.go index 1516538d3d9..d29eb5e25fb 100644 --- a/integration/raft/migration_test.go +++ b/integration/raft/migration_test.go @@ -661,7 +661,7 @@ func updateOrdererEndpointsConfigFails(n *nwo.Network, orderer *nwo.Orderer, cha Expect(err).NotTo(HaveOccurred()) for _, signer := range additionalSigners { - sess, err := n.PeerAdminSession(signer, commands.SignConfigTx{ + sess, err := n.PeerCliAdminSession(signer, commands.SignConfigTx{ File: updateFile, ClientAuth: n.ClientAuthRequired, }) @@ -979,7 +979,7 @@ func updateOrdererOrgEndpointsConfigSucceeds(n *nwo.Network, orderer *nwo.Ordere Expect(err).NotTo(HaveOccurred()) for _, signer := range additionalSigners { - sess, err := n.PeerAdminSession(signer, commands.SignConfigTx{ + sess, err := n.PeerCliAdminSession(signer, commands.SignConfigTx{ File: updateFile, ClientAuth: n.ClientAuthRequired, }) diff --git a/integration/sbe/sbe_test.go b/integration/sbe/sbe_test.go index f669bac5c72..008cea66920 100644 --- a/integration/sbe/sbe_test.go +++ b/integration/sbe/sbe_test.go @@ -120,7 +120,7 @@ func RunSBE(n *nwo.Network, orderer *nwo.Orderer, mode string) { peerOrg2 := n.Peer("Org2", "peer0") By("org1 initializes the key") - sess, err := n.PeerUserSession(peerOrg1, "User1", commands.ChaincodeInvoke{ + sess, err := n.PeerCliUserSession(peerOrg1, "User1", commands.ChaincodeInvoke{ ChannelID: "testchannel", Orderer: n.OrdererAddress(orderer, nwo.ListenPort), Name: "mycc", @@ -136,7 +136,7 @@ func RunSBE(n *nwo.Network, orderer *nwo.Orderer, mode string) { syncLedgerHeights(n, peerOrg1, peerOrg2) By("org2 checks that setting the value was successful by reading it") - sess, err = n.PeerUserSession(peerOrg2, "User1", commands.ChaincodeQuery{ + sess, err = n.PeerCliUserSession(peerOrg2, "User1", commands.ChaincodeQuery{ ChannelID: "testchannel", Name: "mycc", Ctor: `{"Args":["getval", "` + mode + `"]}`, @@ -146,7 +146,7 @@ func RunSBE(n *nwo.Network, orderer *nwo.Orderer, mode string) { Expect(sess).To(gbytes.Say("foo")) By("org1 adds org1 to the state-based ep of a key") - sess, err = n.PeerUserSession(peerOrg1, "User1", commands.ChaincodeInvoke{ + sess, err = n.PeerCliUserSession(peerOrg1, "User1", commands.ChaincodeInvoke{ ChannelID: "testchannel", Orderer: n.OrdererAddress(orderer, nwo.ListenPort), Name: "mycc", @@ -160,7 +160,7 @@ func RunSBE(n *nwo.Network, orderer *nwo.Orderer, mode string) { Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0)) By("checking that the modification succeeded through listing the orgs in the ep") - sess, err = n.PeerUserSession(peerOrg1, "User1", commands.ChaincodeQuery{ + sess, err = n.PeerCliUserSession(peerOrg1, "User1", commands.ChaincodeQuery{ ChannelID: "testchannel", Name: "mycc", Ctor: `{"Args":["listorgs", "` + mode + `"]}`, @@ -170,7 +170,7 @@ func RunSBE(n *nwo.Network, orderer *nwo.Orderer, mode string) { Expect(sess).To(gbytes.Say("Org1MSP")) By("org1 sets the value of the key") - sess, err = n.PeerUserSession(peerOrg1, "User1", commands.ChaincodeInvoke{ + sess, err = n.PeerCliUserSession(peerOrg1, "User1", commands.ChaincodeInvoke{ ChannelID: "testchannel", Orderer: n.OrdererAddress(orderer, nwo.ListenPort), Name: "mycc", @@ -186,7 +186,7 @@ func RunSBE(n *nwo.Network, orderer *nwo.Orderer, mode string) { syncLedgerHeights(n, peerOrg1, peerOrg2) By("org2 checks that setting the value was successful by reading it") - sess, err = n.PeerUserSession(peerOrg2, "User1", commands.ChaincodeQuery{ + sess, err = n.PeerCliUserSession(peerOrg2, "User1", commands.ChaincodeQuery{ ChannelID: "testchannel", Name: "mycc", Ctor: `{"Args":["getval", "` + mode + `"]}`, @@ -196,7 +196,7 @@ func RunSBE(n *nwo.Network, orderer *nwo.Orderer, mode string) { Expect(sess).To(gbytes.Say("val1")) By("org2 sets the value of the key") - sess, err = n.PeerUserSession(peerOrg2, "User1", commands.ChaincodeInvoke{ + sess, err = n.PeerCliUserSession(peerOrg2, "User1", commands.ChaincodeInvoke{ ChannelID: "testchannel", Orderer: n.OrdererAddress(orderer, nwo.ListenPort), Name: "mycc", @@ -211,7 +211,7 @@ func RunSBE(n *nwo.Network, orderer *nwo.Orderer, mode string) { Expect(sess.Err).To(gbytes.Say(`\Qcommitted with status (ENDORSEMENT_POLICY_FAILURE)\E`)) By("org2 checks that setting the value was not successful by reading it") - sess, err = n.PeerUserSession(peerOrg2, "User1", commands.ChaincodeQuery{ + sess, err = n.PeerCliUserSession(peerOrg2, "User1", commands.ChaincodeQuery{ ChannelID: "testchannel", Name: "mycc", Ctor: `{"Args":["getval", "` + mode + `"]}`, @@ -223,7 +223,7 @@ func RunSBE(n *nwo.Network, orderer *nwo.Orderer, mode string) { syncLedgerHeights(n, peerOrg2, peerOrg1) By("org1 adds org2 to the ep of the key") - sess, err = n.PeerUserSession(peerOrg1, "User1", commands.ChaincodeInvoke{ + sess, err = n.PeerCliUserSession(peerOrg1, "User1", commands.ChaincodeInvoke{ ChannelID: "testchannel", Orderer: n.OrdererAddress(orderer, nwo.ListenPort), Name: "mycc", @@ -237,7 +237,7 @@ func RunSBE(n *nwo.Network, orderer *nwo.Orderer, mode string) { Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0)) By("org1 lists the orgs of the ep to check that both org1 and org2 are there") - sess, err = n.PeerUserSession(peerOrg1, "User1", commands.ChaincodeQuery{ + sess, err = n.PeerCliUserSession(peerOrg1, "User1", commands.ChaincodeQuery{ ChannelID: "testchannel", Name: "mycc", Ctor: `{"Args":["listorgs", "` + mode + `"]}`, @@ -252,7 +252,7 @@ func RunSBE(n *nwo.Network, orderer *nwo.Orderer, mode string) { syncLedgerHeights(n, peerOrg1, peerOrg2) By("org2 sets the value of the key") - sess, err = n.PeerUserSession(peerOrg2, "User1", commands.ChaincodeInvoke{ + sess, err = n.PeerCliUserSession(peerOrg2, "User1", commands.ChaincodeInvoke{ ChannelID: "testchannel", Orderer: n.OrdererAddress(orderer, nwo.ListenPort), Name: "mycc", @@ -267,7 +267,7 @@ func RunSBE(n *nwo.Network, orderer *nwo.Orderer, mode string) { Expect(sess.Err).To(gbytes.Say(`\Qcommitted with status (ENDORSEMENT_POLICY_FAILURE)\E`)) By("org2 checks that setting the value was not successful by reading it") - sess, err = n.PeerUserSession(peerOrg2, "User1", commands.ChaincodeQuery{ + sess, err = n.PeerCliUserSession(peerOrg2, "User1", commands.ChaincodeQuery{ ChannelID: "testchannel", Name: "mycc", Ctor: `{"Args":["getval", "` + mode + `"]}`, @@ -279,7 +279,7 @@ func RunSBE(n *nwo.Network, orderer *nwo.Orderer, mode string) { syncLedgerHeights(n, peerOrg2, peerOrg1) By("org1 and org2 set the value of the key") - sess, err = n.PeerUserSession(peerOrg1, "User1", commands.ChaincodeInvoke{ + sess, err = n.PeerCliUserSession(peerOrg1, "User1", commands.ChaincodeInvoke{ ChannelID: "testchannel", Orderer: n.OrdererAddress(orderer, nwo.ListenPort), Name: "mycc", @@ -294,7 +294,7 @@ func RunSBE(n *nwo.Network, orderer *nwo.Orderer, mode string) { Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0)) By("org1 checks that setting the value was successful by reading it") - sess, err = n.PeerUserSession(peerOrg1, "User1", commands.ChaincodeQuery{ + sess, err = n.PeerCliUserSession(peerOrg1, "User1", commands.ChaincodeQuery{ ChannelID: "testchannel", Name: "mycc", Ctor: `{"Args":["getval", "` + mode + `"]}`, @@ -306,7 +306,7 @@ func RunSBE(n *nwo.Network, orderer *nwo.Orderer, mode string) { syncLedgerHeights(n, peerOrg1, peerOrg2) By("org2 deletes org1 from the ep of the key") - sess, err = n.PeerUserSession(peerOrg2, "User1", commands.ChaincodeInvoke{ + sess, err = n.PeerCliUserSession(peerOrg2, "User1", commands.ChaincodeInvoke{ ChannelID: "testchannel", Orderer: n.OrdererAddress(orderer, nwo.ListenPort), Name: "mycc", @@ -321,7 +321,7 @@ func RunSBE(n *nwo.Network, orderer *nwo.Orderer, mode string) { Expect(sess.Err).To(gbytes.Say(`\Qcommitted with status (ENDORSEMENT_POLICY_FAILURE)\E`)) By("org2 lists the orgs of the key to check that deleting org1 did not succeed") - sess, err = n.PeerUserSession(peerOrg2, "User1", commands.ChaincodeQuery{ + sess, err = n.PeerCliUserSession(peerOrg2, "User1", commands.ChaincodeQuery{ ChannelID: "testchannel", Name: "mycc", Ctor: `{"Args":["listorgs", "` + mode + `"]}`, @@ -333,7 +333,7 @@ func RunSBE(n *nwo.Network, orderer *nwo.Orderer, mode string) { syncLedgerHeights(n, peerOrg2, peerOrg1) By("org1 and org2 delete org1 from the ep of the key") - sess, err = n.PeerUserSession(peerOrg2, "User1", commands.ChaincodeInvoke{ + sess, err = n.PeerCliUserSession(peerOrg2, "User1", commands.ChaincodeInvoke{ ChannelID: "testchannel", Orderer: n.OrdererAddress(orderer, nwo.ListenPort), Name: "mycc", @@ -348,7 +348,7 @@ func RunSBE(n *nwo.Network, orderer *nwo.Orderer, mode string) { Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0)) By("org2 lists the orgs of the key's ep to check that removing org1 from the ep was successful") - sess, err = n.PeerUserSession(peerOrg2, "User1", commands.ChaincodeQuery{ + sess, err = n.PeerCliUserSession(peerOrg2, "User1", commands.ChaincodeQuery{ ChannelID: "testchannel", Name: "mycc", Ctor: `{"Args":["listorgs", "` + mode + `"]}`, @@ -358,7 +358,7 @@ func RunSBE(n *nwo.Network, orderer *nwo.Orderer, mode string) { Expect(sess).To(gbytes.Say("Org2MSP")) By("org2 uses cc2cc invocation to set the value of the key") - sess, err = n.PeerUserSession(peerOrg2, "User1", commands.ChaincodeInvoke{ + sess, err = n.PeerCliUserSession(peerOrg2, "User1", commands.ChaincodeInvoke{ ChannelID: "testchannel", Orderer: n.OrdererAddress(orderer, nwo.ListenPort), Name: "mycc2", @@ -372,7 +372,7 @@ func RunSBE(n *nwo.Network, orderer *nwo.Orderer, mode string) { Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0)) By("org2 reads the value of the key to check that setting it was successful") - sess, err = n.PeerUserSession(peerOrg2, "User1", commands.ChaincodeQuery{ + sess, err = n.PeerCliUserSession(peerOrg2, "User1", commands.ChaincodeQuery{ ChannelID: "testchannel", Name: "mycc", Ctor: `{"Args":["getval", "` + mode + `"]}`, @@ -384,7 +384,7 @@ func RunSBE(n *nwo.Network, orderer *nwo.Orderer, mode string) { syncLedgerHeights(n, peerOrg2, peerOrg1) By("org1 uses cc2cc to set the value of the key") - sess, err = n.PeerUserSession(peerOrg1, "User1", commands.ChaincodeInvoke{ + sess, err = n.PeerCliUserSession(peerOrg1, "User1", commands.ChaincodeInvoke{ ChannelID: "testchannel", Orderer: n.OrdererAddress(orderer, nwo.ListenPort), Name: "mycc2", @@ -399,7 +399,7 @@ func RunSBE(n *nwo.Network, orderer *nwo.Orderer, mode string) { Expect(sess.Err).To(gbytes.Say(`\Qcommitted with status (ENDORSEMENT_POLICY_FAILURE)\E`)) By("org1 reads the value of the key to check that setting it was not successful") - sess, err = n.PeerUserSession(peerOrg1, "User1", commands.ChaincodeQuery{ + sess, err = n.PeerCliUserSession(peerOrg1, "User1", commands.ChaincodeQuery{ ChannelID: "testchannel", Name: "mycc", Ctor: `{"Args":["getval", "` + mode + `"]}`, @@ -410,7 +410,7 @@ func RunSBE(n *nwo.Network, orderer *nwo.Orderer, mode string) { } func getLedgerHeight(n *nwo.Network, peer *nwo.Peer, channelName string) int { - sess, err := n.PeerUserSession(peer, "User1", commands.ChannelInfo{ + sess, err := n.PeerCliUserSession(peer, "User1", commands.ChannelInfo{ ChannelID: channelName, }) Expect(err).NotTo(HaveOccurred()) diff --git a/integration/smartbft/smartbft_block_deliverer_test.go b/integration/smartbft/smartbft_block_deliverer_test.go index 9ee206e84e1..ad3933f0b29 100644 --- a/integration/smartbft/smartbft_block_deliverer_test.go +++ b/integration/smartbft/smartbft_block_deliverer_test.go @@ -202,7 +202,7 @@ var _ = Describe("Smart BFT Block Deliverer", func() { peerProcesses = ifrit.Invoke(peerRunner) Eventually(peerProcesses.Ready(), network.EventuallyTimeout).Should(BeClosed()) - _, err = network.PeerAdminSession(p0, commands.ChannelJoin{ + _, err = network.PeerCliAdminSession(p0, commands.ChannelJoin{ BlockPath: network.OutputBlockPath(channel), ClientAuth: network.ClientAuthRequired, }) @@ -257,7 +257,7 @@ var _ = Describe("Smart BFT Block Deliverer", func() { peerProcesses = ifrit.Invoke(peerRunner) Eventually(peerProcesses.Ready(), network.EventuallyTimeout).Should(BeClosed()) - _, err = network.PeerAdminSession(p0, commands.ChannelJoin{ + _, err = network.PeerCliAdminSession(p0, commands.ChannelJoin{ BlockPath: network.OutputBlockPath(channel), ClientAuth: network.ClientAuthRequired, }) diff --git a/integration/smartbft/smartbft_test.go b/integration/smartbft/smartbft_test.go index cb07e542a94..55edc68b5df 100644 --- a/integration/smartbft/smartbft_test.go +++ b/integration/smartbft/smartbft_test.go @@ -129,7 +129,7 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { deployChaincode(network, channel, testDir) By("querying the chaincode") - sess, err := network.PeerUserSession(peer, "User1", commands.ChaincodeQuery{ + sess, err := network.PeerCliUserSession(peer, "User1", commands.ChaincodeQuery{ ChannelID: channel, Name: "mycc", Ctor: `{"Args":["query","a"]}`, @@ -1026,7 +1026,7 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { network.OrdererAddress(network.Orderers[2], nwo.ListenPort), network.OrdererAddress(network.Orderers[3], nwo.ListenPort)) - sess, err := network.PeerUserSession(peer, "User1", commands.ChaincodeInvoke{ + sess, err := network.PeerCliUserSession(peer, "User1", commands.ChaincodeInvoke{ ChannelID: channel, Orderer: endpoints, Name: "mycc", @@ -1813,7 +1813,7 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { deployChaincode(network, channel, testDir) By("querying the chaincode") - sess, err := network.PeerUserSession(peer, "User1", commands.ChaincodeQuery{ + sess, err := network.PeerCliUserSession(peer, "User1", commands.ChaincodeQuery{ ChannelID: channel, Name: "mycc", Ctor: `{"Args":["query","a"]}`, @@ -1917,7 +1917,7 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { // used to ensure we only approve once per org // the transaction must fail - sess, err := network.PeerAdminSession(peers[0], commands.ChaincodeApproveForMyOrg{ + sess, err := network.PeerCliAdminSession(peers[0], commands.ChaincodeApproveForMyOrg{ ChannelID: channel, Orderer: network.OrdererAddress(network.Orderers[0], "Listen"), Name: chaincode.Name, @@ -1964,7 +1964,7 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { } // let's continue deploying chaincode - sess, err = network.PeerAdminSession(peers[1], commands.ChaincodeApproveForMyOrg{ + sess, err = network.PeerCliAdminSession(peers[1], commands.ChaincodeApproveForMyOrg{ ChannelID: channel, Orderer: network.OrdererAddress(network.Orderers[0], "Listen"), Name: chaincode.Name, @@ -1994,7 +1994,7 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { } By("querying the chaincode") - sess, err = network.PeerUserSession(peer, "User1", commands.ChaincodeQuery{ + sess, err = network.PeerCliUserSession(peer, "User1", commands.ChaincodeQuery{ ChannelID: channel, Name: "mycc", Ctor: `{"Args":["query","a"]}`, @@ -2051,7 +2051,7 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { deployChaincode(network, channel, testDir) By("querying the chaincode") - sess, err := network.PeerUserSession(peer, "User1", commands.ChaincodeQuery{ + sess, err := network.PeerCliUserSession(peer, "User1", commands.ChaincodeQuery{ ChannelID: channel, Name: "mycc", Ctor: `{"Args":["query","a"]}`, @@ -2397,7 +2397,7 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { }) func invokeQuery(network *nwo.Network, peer *nwo.Peer, orderer *nwo.Orderer, channel string, expectedBalance int) { - sess, err := network.PeerUserSession(peer, "User1", commands.ChaincodeInvoke{ + sess, err := network.PeerCliUserSession(peer, "User1", commands.ChaincodeInvoke{ ChannelID: channel, Orderer: network.OrdererAddress(orderer, nwo.ListenPort), Name: "mycc", @@ -2417,7 +2417,7 @@ func invokeQuery(network *nwo.Network, peer *nwo.Peer, orderer *nwo.Orderer, cha func queryExpect(network *nwo.Network, peer *nwo.Peer, channel string, key string, expectedBalance int) { Eventually(func() string { - sess, err := network.PeerUserSession(peer, "User1", commands.ChaincodeQuery{ + sess, err := network.PeerCliUserSession(peer, "User1", commands.ChaincodeQuery{ ChannelID: channel, Name: "mycc", Ctor: fmt.Sprintf(`{"Args":["query","%s"]}`, key), diff --git a/internal/peer/chaincode/chaincode.go b/internal/peer/chaincode/chaincode.go index 6087e468576..0f8cafe81f2 100644 --- a/internal/peer/chaincode/chaincode.go +++ b/internal/peer/chaincode/chaincode.go @@ -31,11 +31,16 @@ func addFlags(cmd *cobra.Command) { } // Cmd returns the cobra command for Chaincode -func Cmd(cf *ChaincodeCmdFactory, cryptoProvider bccsp.BCCSP) *cobra.Command { +func Cmd(cf *ChaincodeCmdFactory, cryptoProvider bccsp.BCCSP, isNew bool) *cobra.Command { addFlags(chaincodeCmd) - chaincodeCmd.AddCommand(invokeCmd(cf, cryptoProvider)) - chaincodeCmd.AddCommand(queryCmd(cf, cryptoProvider)) + chaincodeCmd.AddCommand(invokeCmd(cf, cryptoProvider, isNew)) + chaincodeCmd.AddCommand(queryCmd(cf, cryptoProvider, isNew)) + + if !isNew { + chaincodeCmd.Short = "[DEPRECATED] " + chainCmdDes[:len(chainCmdDes)-2] + " (use the \"peercli chaincode\")." + chaincodeCmd.Long = "[DEPRECATED] " + chainCmdDes + " Instead of this command, use \"peercli chaincode\"." + } return chaincodeCmd } diff --git a/internal/peer/chaincode/flags_test.go b/internal/peer/chaincode/flags_test.go index 2e66194e4bb..4486253d77e 100644 --- a/internal/peer/chaincode/flags_test.go +++ b/internal/peer/chaincode/flags_test.go @@ -44,7 +44,7 @@ func TestOrdererFlags(t *testing.T) { cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore()) require.NoError(t, err) - runCmd := Cmd(nil, cryptoProvider) + runCmd := Cmd(nil, cryptoProvider, true) runCmd.AddCommand(testCmd) diff --git a/internal/peer/chaincode/invoke.go b/internal/peer/chaincode/invoke.go index 0ed25090dab..f8cc5b985a0 100644 --- a/internal/peer/chaincode/invoke.go +++ b/internal/peer/chaincode/invoke.go @@ -17,7 +17,7 @@ import ( var chaincodeInvokeCmd *cobra.Command // invokeCmd returns the cobra command for Chaincode Invoke -func invokeCmd(cf *ChaincodeCmdFactory, cryptoProvider bccsp.BCCSP) *cobra.Command { +func invokeCmd(cf *ChaincodeCmdFactory, cryptoProvider bccsp.BCCSP, isNew bool) *cobra.Command { chaincodeInvokeCmd = &cobra.Command{ Use: "invoke", Short: fmt.Sprintf("Invoke the specified %s.", chainFuncName), @@ -27,6 +27,10 @@ func invokeCmd(cf *ChaincodeCmdFactory, cryptoProvider bccsp.BCCSP) *cobra.Comma return chaincodeInvoke(cmd, cf, cryptoProvider) }, } + if !isNew { + chaincodeInvokeCmd.Short = "[DEPRECATED] Invoke the specified chaincode (use the \"peercli chaincode invoke\")." + chaincodeInvokeCmd.Long = "[DEPRECATED] Invoke the specified chaincode. It will try to commit the endorsed transaction to the network. Instead of this command, use \"peercli chaincode invoke\"." + } flagList := []string{ "name", "ctor", diff --git a/internal/peer/chaincode/invoke_test.go b/internal/peer/chaincode/invoke_test.go index c9bdf5d309f..960cc7edf20 100644 --- a/internal/peer/chaincode/invoke_test.go +++ b/internal/peer/chaincode/invoke_test.go @@ -40,15 +40,15 @@ func TestInvokeCmd(t *testing.T) { require.NoError(t, err) // Error case 0: no channelID specified - cmd := invokeCmd(mockCF, cryptoProvider) + cmd := invokeCmd(mockCF, cryptoProvider, true) addFlags(cmd) args := []string{"-n", "example02", "-c", "{\"Args\": [\"invoke\",\"a\",\"b\",\"10\"]}"} cmd.SetArgs(args) err = cmd.Execute() - require.Error(t, err, "'peer chaincode invoke' command should have returned error when called without -C flag") + require.Error(t, err, "'peercli chaincode invoke' command should have returned error when called without -C flag") // Success case - cmd = invokeCmd(mockCF, cryptoProvider) + cmd = invokeCmd(mockCF, cryptoProvider, true) addFlags(cmd) args = []string{"-n", "example02", "-c", "{\"Args\": [\"invoke\",\"a\",\"b\",\"10\"]}", "-C", "mychannel"} cmd.SetArgs(args) @@ -80,7 +80,7 @@ func TestInvokeCmd(t *testing.T) { common.GetOrdererEndpointOfChainFnc = func(chainID string, signer common.Signer, endorserClient pb.EndorserClient, cryptoProvider bccsp.BCCSP) ([]string, error) { return []string{}, nil } - cmd = invokeCmd(nil, cryptoProvider) + cmd = invokeCmd(nil, cryptoProvider, true) addFlags(cmd) args = []string{"-n", "example02", "-c", "{\"Args\": [\"invoke\",\"a\",\"b\",\"10\"]}", "-C", "mychannel"} cmd.SetArgs(args) @@ -181,7 +181,7 @@ func TestInvokeCmdSimulateESCCPluginResponse(t *testing.T) { l, recorder := floggingtest.NewTestLogger(t) logger = l - cmd := invokeCmd(mockCF, cryptoProvider) + cmd := invokeCmd(mockCF, cryptoProvider, true) addFlags(cmd) args := []string{"-n", "example02", "-c", "{\"Args\": [\"invoke\",\"a\",\"b\",\"10\"]}", "-C", "mychannel"} cmd.SetArgs(args) @@ -200,7 +200,7 @@ func TestInvokeCmdEndorsementError(t *testing.T) { cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore()) require.NoError(t, err) - cmd := invokeCmd(mockCF, cryptoProvider) + cmd := invokeCmd(mockCF, cryptoProvider, true) addFlags(cmd) args := []string{"-n", "example02", "-C", "mychannel", "-c", "{\"Args\": [\"invoke\",\"a\",\"b\",\"10\"]}"} cmd.SetArgs(args) @@ -219,7 +219,7 @@ func TestInvokeCmdEndorsementFailure(t *testing.T) { mockCF, err := getMockChaincodeCmdFactoryEndorsementFailure(ccRespStatus[i], ccRespPayload[i]) require.NoError(t, err, "Error getting mock chaincode command factory") - cmd := invokeCmd(mockCF, cryptoProvider) + cmd := invokeCmd(mockCF, cryptoProvider, true) addFlags(cmd) args := []string{"-C", "mychannel", "-n", "example02", "-c", "{\"Args\": [\"invokeinvalid\",\"a\",\"b\",\"10\"]}"} cmd.SetArgs(args) diff --git a/internal/peer/chaincode/query.go b/internal/peer/chaincode/query.go index 553ac0efc8a..121e9672a57 100644 --- a/internal/peer/chaincode/query.go +++ b/internal/peer/chaincode/query.go @@ -17,7 +17,7 @@ import ( var chaincodeQueryCmd *cobra.Command // queryCmd returns the cobra command for Chaincode Query -func queryCmd(cf *ChaincodeCmdFactory, cryptoProvider bccsp.BCCSP) *cobra.Command { +func queryCmd(cf *ChaincodeCmdFactory, cryptoProvider bccsp.BCCSP, isNew bool) *cobra.Command { chaincodeQueryCmd = &cobra.Command{ Use: "query", Short: fmt.Sprintf("Query using the specified %s.", chainFuncName), @@ -27,6 +27,10 @@ func queryCmd(cf *ChaincodeCmdFactory, cryptoProvider bccsp.BCCSP) *cobra.Comman return chaincodeQuery(cmd, cf, cryptoProvider) }, } + if !isNew { + chaincodeQueryCmd.Short = "[DEPRECATED] Query using the specified chaincode (use the \"peercli chaincode query\")." + chaincodeQueryCmd.Long = "[DEPRECATED] Get endorsed result of chaincode function call and print it. It won't generate transaction. Instead of this command, use \"peercli chaincode query\"." + } flagList := []string{ "ctor", "name", diff --git a/internal/peer/chaincode/query_test.go b/internal/peer/chaincode/query_test.go index 9e3ea2e2cb2..f6eb55bfd1f 100644 --- a/internal/peer/chaincode/query_test.go +++ b/internal/peer/chaincode/query_test.go @@ -30,7 +30,7 @@ func TestQueryCmd(t *testing.T) { args := []string{"-n", "example02", "-c", "{\"Args\": [\"query\",\"a\"]}"} cmd := newQueryCmdForTest(mockCF, args, cryptoProvider) err = cmd.Execute() - require.Error(t, err, "'peer chaincode query' command should have failed without -C flag") + require.Error(t, err, "'peercli chaincode query' command should have failed without -C flag") // Success case: run query command without -r or -x option args = []string{"-C", "mychannel", "-n", "example02", "-c", "{\"Args\": [\"query\",\"a\"]}"} @@ -99,7 +99,7 @@ func TestQueryCmdEndorsementFailure(t *testing.T) { } func newQueryCmdForTest(cf *ChaincodeCmdFactory, args []string, cryptoProvider bccsp.BCCSP) *cobra.Command { - cmd := queryCmd(cf, cryptoProvider) + cmd := queryCmd(cf, cryptoProvider, true) addFlags(cmd) cmd.SetArgs(args) return cmd diff --git a/internal/peer/channel/channel.go b/internal/peer/channel/channel.go index 5fb0dd7487f..9e12e5f3038 100644 --- a/internal/peer/channel/channel.go +++ b/internal/peer/channel/channel.go @@ -49,19 +49,24 @@ var ( ) // Cmd returns the cobra command for Node -func Cmd(cf *ChannelCmdFactory) *cobra.Command { +func Cmd(cf *ChannelCmdFactory, isNew bool) *cobra.Command { AddFlags(channelCmd) // Add subcommands - channelCmd.AddCommand(createCmd(cf)) - channelCmd.AddCommand(fetchCmd(cf)) - channelCmd.AddCommand(joinCmd(cf)) - channelCmd.AddCommand(joinBySnapshotCmd(cf)) - channelCmd.AddCommand(joinBySnapshotStatusCmd(cf)) - channelCmd.AddCommand(listCmd(cf)) - channelCmd.AddCommand(updateCmd(cf)) - channelCmd.AddCommand(signconfigtxCmd(cf)) - channelCmd.AddCommand(getinfoCmd(cf)) + channelCmd.AddCommand(fetchCmd(cf, isNew)) + channelCmd.AddCommand(joinCmd(cf, isNew)) + channelCmd.AddCommand(joinBySnapshotCmd(cf, isNew)) + channelCmd.AddCommand(joinBySnapshotStatusCmd(cf, isNew)) + channelCmd.AddCommand(listCmd(cf, isNew)) + channelCmd.AddCommand(signconfigtxCmd(cf, isNew)) + channelCmd.AddCommand(getinfoCmd(cf, isNew)) + + if !isNew { + channelCmd.AddCommand(createCmd(cf)) + channelCmd.AddCommand(updateCmd(cf)) + channelCmd.Short = "[DEPRECATED] Operate a channel: create|fetch|join|joinbysnapshot|joinbysnapshotstatus|list|update|signconfigtx|getinfo (use the \"peercli channel\")." + channelCmd.Long = "[DEPRECATED] Operate a channel: create|fetch|join|joinbysnapshot|joinbysnapshotstatus|list|update|signconfigtx|getinfo. Instead of this command, use \"peercli channel\"." + } return channelCmd } @@ -103,8 +108,8 @@ func attachFlags(cmd *cobra.Command, names []string) { var channelCmd = &cobra.Command{ Use: "channel", - Short: "Operate a channel: create|fetch|join|joinbysnapshot|joinbysnapshotstatus|list|update|signconfigtx|getinfo.", - Long: "Operate a channel: create|fetch|join|joinbysnapshot|joinbysnapshotstatus|list|update|signconfigtx|getinfo.", + Short: "Operate a channel: fetch|join|joinbysnapshot|joinbysnapshotstatus|list|signconfigtx|getinfo.", + Long: "Operate a channel: fetch|join|joinbysnapshot|joinbysnapshotstatus|list|signconfigtx|getinfo.", PersistentPreRun: func(cmd *cobra.Command, args []string) { common.InitCmd(cmd, args) common.SetOrdererEnv(cmd, args) diff --git a/internal/peer/channel/create.go b/internal/peer/channel/create.go index 6287bbafec6..038d7e1ccd9 100644 --- a/internal/peer/channel/create.go +++ b/internal/peer/channel/create.go @@ -42,7 +42,7 @@ func (e InvalidCreateTx) Error() string { func createCmd(cf *ChannelCmdFactory) *cobra.Command { createCmd := &cobra.Command{ Use: "create", - Short: "[DEPRECATED] Create a channel", + Short: "[DEPRECATED] Create a channel (use the \"osnadmin join\").", Long: "[DEPRECATED] Create a channel and write the genesis block to a file. Instead of this command, use Orderer Service Node (OSN).", RunE: func(cmd *cobra.Command, args []string) error { return create(cmd, args, cf) diff --git a/internal/peer/channel/fetch.go b/internal/peer/channel/fetch.go index 7f961a36d04..75fa7f335c8 100644 --- a/internal/peer/channel/fetch.go +++ b/internal/peer/channel/fetch.go @@ -20,15 +20,19 @@ import ( "google.golang.org/protobuf/proto" ) -func fetchCmd(cf *ChannelCmdFactory) *cobra.Command { +func fetchCmd(cf *ChannelCmdFactory, isNew bool) *cobra.Command { fetchCmd := &cobra.Command{ Use: "fetch [outputfile]", - Short: "Fetch a block", - Long: "Fetch a specified block, writing it to a file.", + Short: "Fetch a block from peer.", + Long: "Fetch a specified block from peer, writing it to a file.", RunE: func(cmd *cobra.Command, args []string) error { - return fetch(cmd, args, cf) + return fetch(cmd, args, cf, isNew) }, } + if !isNew { + fetchCmd.Short = "[DEPRECATED] Fetch a block (use the \"peercli channel fetch\" or \"osnadmin fetch\")." + fetchCmd.Long = "[DEPRECATED] Fetch a specified block from peer or orderer, writing it to a file. Instead of this command, use \"peercli channel fetch\" or \"osnadmin fetch\"." + } flagList := []string{ "channelID", "bestEffort", @@ -38,7 +42,7 @@ func fetchCmd(cf *ChannelCmdFactory) *cobra.Command { return fetchCmd } -func fetch(cmd *cobra.Command, args []string, cf *ChannelCmdFactory) error { +func fetch(cmd *cobra.Command, args []string, cf *ChannelCmdFactory, isNew bool) error { if len(args) == 0 { return fmt.Errorf("fetch target required, oldest, newest, config, or a number") } @@ -57,6 +61,9 @@ func fetch(cmd *cobra.Command, args []string, cf *ChannelCmdFactory) error { peerDeliverRequired = PeerDeliverRequired } var err error + if isNew && ordererRequired { + return errors.Errorf("peercli channel fetch only from peer") + } if cf == nil { cf, err = InitCmdFactory(EndorserNotRequired, peerDeliverRequired, ordererRequired) if err != nil { diff --git a/internal/peer/channel/fetch_test.go b/internal/peer/channel/fetch_test.go index d04e141c949..6378bce0184 100644 --- a/internal/peer/channel/fetch_test.go +++ b/internal/peer/channel/fetch_test.go @@ -44,7 +44,7 @@ func TestFetch(t *testing.T) { tempDir := t.TempDir() - cmd := fetchCmd(mockCF) + cmd := fetchCmd(mockCF, true) AddFlags(cmd) // success cases - block and outputBlockPath @@ -90,7 +90,7 @@ func TestFetch(t *testing.T) { func TestFetchArgs(t *testing.T) { // failure - no args - cmd := fetchCmd(nil) + cmd := fetchCmd(nil, true) AddFlags(cmd) err := cmd.Execute() require.Error(t, err, "fetch command expected to fail") @@ -114,7 +114,7 @@ func TestFetchNilCF(t *testing.T) { mockchain := "mockchain" viper.Set("peer.client.connTimeout", 10*time.Millisecond) - cmd := fetchCmd(nil) + cmd := fetchCmd(nil, true) AddFlags(cmd) args := []string{"-c", mockchain, "oldest"} cmd.SetArgs(args) diff --git a/internal/peer/channel/flags_test.go b/internal/peer/channel/flags_test.go index 070e33e040c..caa6496dc4c 100644 --- a/internal/peer/channel/flags_test.go +++ b/internal/peer/channel/flags_test.go @@ -41,7 +41,7 @@ func TestOrdererFlags(t *testing.T) { }, } - runCmd := Cmd(nil) + runCmd := Cmd(nil, true) runCmd.AddCommand(testCmd) diff --git a/internal/peer/channel/getinfo.go b/internal/peer/channel/getinfo.go index 248baf9fd92..bfd1f494919 100644 --- a/internal/peer/channel/getinfo.go +++ b/internal/peer/channel/getinfo.go @@ -22,7 +22,7 @@ import ( "google.golang.org/protobuf/proto" ) -func getinfoCmd(cf *ChannelCmdFactory) *cobra.Command { +func getinfoCmd(cf *ChannelCmdFactory, isNew bool) *cobra.Command { getinfoCmd := &cobra.Command{ Use: "getinfo", Short: "get blockchain information of a specified channel.", @@ -31,6 +31,10 @@ func getinfoCmd(cf *ChannelCmdFactory) *cobra.Command { return getinfo(cmd, cf) }, } + if !isNew { + getinfoCmd.Short = "[DEPRECATED] get blockchain information of a specified channel (use the \"peercli channel getinfo\")." + getinfoCmd.Long = "[DEPRECATED] get blockchain information of a specified channel. Requires '-c'. Instead of this command, use \"peercli channel getinfo\"." + } flagList := []string{ "channelID", } diff --git a/internal/peer/channel/getinfo_test.go b/internal/peer/channel/getinfo_test.go index 41e503ac5ff..bfd573a8ba6 100644 --- a/internal/peer/channel/getinfo_test.go +++ b/internal/peer/channel/getinfo_test.go @@ -45,7 +45,7 @@ func TestGetChannelInfo(t *testing.T) { Signer: signer, } - cmd := getinfoCmd(mockCF) + cmd := getinfoCmd(mockCF, true) AddFlags(cmd) args := []string{"-c", mockChannel} @@ -67,7 +67,7 @@ func TestGetChannelInfoMissingChannelID(t *testing.T) { Signer: signer, } - cmd := getinfoCmd(mockCF) + cmd := getinfoCmd(mockCF, true) AddFlags(cmd) diff --git a/internal/peer/channel/join.go b/internal/peer/channel/join.go index 2e6d6f71c1a..ff618756597 100644 --- a/internal/peer/channel/join.go +++ b/internal/peer/channel/join.go @@ -23,7 +23,7 @@ import ( const commandDescription = "Joins the peer to a channel." -func joinCmd(cf *ChannelCmdFactory) *cobra.Command { +func joinCmd(cf *ChannelCmdFactory, isNew bool) *cobra.Command { // Set the flags on the channel start command. joinCmd := &cobra.Command{ Use: "join", @@ -33,6 +33,10 @@ func joinCmd(cf *ChannelCmdFactory) *cobra.Command { return join(cmd, args, cf) }, } + if !isNew { + joinCmd.Short = "[DEPRECATED] Joins the peer to a channel (use the \"peercli channel join\")." + joinCmd.Long = "[DEPRECATED] Joins the peer to a channel. Instead of this command, use \"peercli channel join\"." + } flagList := []string{ "blockpath", } diff --git a/internal/peer/channel/join_test.go b/internal/peer/channel/join_test.go index d40c36d4f1f..698e298c829 100644 --- a/internal/peer/channel/join_test.go +++ b/internal/peer/channel/join_test.go @@ -23,7 +23,7 @@ func TestMissingBlockFile(t *testing.T) { resetFlags() - cmd := joinCmd(nil) + cmd := joinCmd(nil, true) AddFlags(cmd) args := []string{} cmd.SetArgs(args) @@ -57,7 +57,7 @@ func TestJoin(t *testing.T) { Signer: signer, } - cmd := joinCmd(mockCF) + cmd := joinCmd(mockCF, true) AddFlags(cmd) args := []string{"-b", mockblockfile} @@ -90,7 +90,7 @@ func TestJoinNonExistentBlock(t *testing.T) { Signer: signer, } - cmd := joinCmd(mockCF) + cmd := joinCmd(mockCF, true) AddFlags(cmd) @@ -127,7 +127,7 @@ func TestBadProposalResponse(t *testing.T) { Signer: signer, } - cmd := joinCmd(mockCF) + cmd := joinCmd(mockCF, true) AddFlags(cmd) @@ -149,7 +149,7 @@ func TestJoinNilCF(t *testing.T) { dir := t.TempDir() mockblockfile := filepath.Join(dir, "mockjointest.block") viper.Set("peer.client.connTimeout", 10*time.Millisecond) - cmd := joinCmd(nil) + cmd := joinCmd(nil, true) AddFlags(cmd) args := []string{"-b", mockblockfile} cmd.SetArgs(args) diff --git a/internal/peer/channel/joinbysnapshot.go b/internal/peer/channel/joinbysnapshot.go index 7451923d291..2a6d8556231 100644 --- a/internal/peer/channel/joinbysnapshot.go +++ b/internal/peer/channel/joinbysnapshot.go @@ -15,7 +15,7 @@ import ( "github.com/spf13/cobra" ) -func joinBySnapshotCmd(cf *ChannelCmdFactory) *cobra.Command { +func joinBySnapshotCmd(cf *ChannelCmdFactory, isNew bool) *cobra.Command { // Set the flags on the channel start command. joinbysnapshotCmd := &cobra.Command{ Use: "joinbysnapshot", @@ -25,6 +25,10 @@ func joinBySnapshotCmd(cf *ChannelCmdFactory) *cobra.Command { return joinBySnapshot(cmd, args, cf) }, } + if !isNew { + joinbysnapshotCmd.Short = "[DEPRECATED] Joins the peer to a channel by the specified snapshot (use the \"peercli channel joinbysnapshot\")." + joinbysnapshotCmd.Long = "[DEPRECATED] Joins the peer to a channel by the specified snapshot. Instead of this command, use \"peercli channel joinbysnapshot\"." + } flagList := []string{ "snapshotpath", } @@ -59,6 +63,6 @@ func joinBySnapshot(cmd *cobra.Command, args []string, cf *ChannelCmdFactory) er return err } - logger.Info(`The joinbysnapshot operation is in progress. Use "peer channel joinbysnapshotstatus" to check the status.`) + logger.Info(`The joinbysnapshot operation is in progress. Use "peercli channel joinbysnapshotstatus" to check the status.`) return nil } diff --git a/internal/peer/channel/joinbysnapshot_test.go b/internal/peer/channel/joinbysnapshot_test.go index 5c7842c474a..2775b63676a 100644 --- a/internal/peer/channel/joinbysnapshot_test.go +++ b/internal/peer/channel/joinbysnapshot_test.go @@ -37,14 +37,14 @@ func TestJoinBySnapshot(t *testing.T) { // successful test resetFlags() - cmd := joinBySnapshotCmd(mockCF) + cmd := joinBySnapshotCmd(mockCF, true) AddFlags(cmd) cmd.SetArgs([]string{"--snapshotpath", "path_to_snapshot_directory"}) require.NoError(t, cmd.Execute()) // error due to missing snapshotpath resetFlags() - cmd = joinBySnapshotCmd(mockCF) + cmd = joinBySnapshotCmd(mockCF, true) AddFlags(cmd) cmd.SetArgs([]string{}) require.EqualError(t, cmd.Execute(), "the required parameter 'snapshotpath' is empty. Rerun the command with --snapshotpath flag") @@ -52,7 +52,7 @@ func TestJoinBySnapshot(t *testing.T) { // error due to EndoserClient returning bad response mockResponse.Response = &pb.Response{Status: 500} resetFlags() - cmd = joinBySnapshotCmd(mockCF) + cmd = joinBySnapshotCmd(mockCF, true) AddFlags(cmd) args := []string{"--snapshotpath", "snapshot_path"} cmd.SetArgs(args) @@ -63,7 +63,7 @@ func TestJoinBySnapshot(t *testing.T) { // error due to connection failure to endorser client viper.Set("peer.client.connTimeout", 10*time.Millisecond) resetFlags() - cmd = joinBySnapshotCmd(nil) + cmd = joinBySnapshotCmd(nil, true) AddFlags(cmd) cmd.SetArgs([]string{"--snapshotpath", "snapshot_path"}) err = cmd.Execute() diff --git a/internal/peer/channel/joinbysnapshotstatus.go b/internal/peer/channel/joinbysnapshotstatus.go index 3d1c2eeacfc..f2734b6fffe 100644 --- a/internal/peer/channel/joinbysnapshotstatus.go +++ b/internal/peer/channel/joinbysnapshotstatus.go @@ -19,12 +19,12 @@ import ( "google.golang.org/protobuf/proto" ) -func joinBySnapshotStatusCmd(cf *ChannelCmdFactory) *cobra.Command { +func joinBySnapshotStatusCmd(cf *ChannelCmdFactory, isNew bool) *cobra.Command { // Set the flags on the channel start command. - return &cobra.Command{ + joinBySnapshotStatusCmd := &cobra.Command{ Use: "joinbysnapshotstatus", - Short: "Query if joinbysnapshot is running for any channel", - Long: "Query if joinbysnapshot is running for any channel", + Short: "Query if joinbysnapshot is running for any channel.", + Long: "Query if joinbysnapshot is running for any channel.", RunE: func(cmd *cobra.Command, args []string) error { if len(args) != 0 { return fmt.Errorf("trailing args detected: %s", args) @@ -34,6 +34,13 @@ func joinBySnapshotStatusCmd(cf *ChannelCmdFactory) *cobra.Command { return joinBySnapshotStatus(cf) }, } + + if !isNew { + joinBySnapshotStatusCmd.Short = "[DEPRECATED] Query if joinbysnapshot is running for any channel (use the \"peercli channel joinbysnapshotstatus\")." + joinBySnapshotStatusCmd.Long = "[DEPRECATED] Query if joinbysnapshot is running for any channel. Instead of this command, use \"peercli channel joinbysnapshotstatus\"." + } + + return joinBySnapshotStatusCmd } func joinBySnapshotStatus(cf *ChannelCmdFactory) error { diff --git a/internal/peer/channel/joinbysnapshotstatus_test.go b/internal/peer/channel/joinbysnapshotstatus_test.go index 837e68a2af3..afb4e316bcf 100644 --- a/internal/peer/channel/joinbysnapshotstatus_test.go +++ b/internal/peer/channel/joinbysnapshotstatus_test.go @@ -40,7 +40,7 @@ func TestJoinBySnapshotStatus(t *testing.T) { // successful joinbysnapshotstatuscmd test resetFlags() - cmd := joinBySnapshotStatusCmd(mockCF) + cmd := joinBySnapshotStatusCmd(mockCF, true) AddFlags(cmd) require.NoError(t, cmd.Execute()) @@ -59,7 +59,7 @@ func TestJoinBySnapshotStatus(t *testing.T) { // negative test due to EndoserClient returning bad response mockResponse.Response = &pb.Response{Status: 500, Message: "mock_bad_response"} resetFlags() - cmd = joinBySnapshotStatusCmd(mockCF) + cmd = joinBySnapshotStatusCmd(mockCF, true) AddFlags(cmd) err = cmd.Execute() require.EqualError(t, err, "received bad response, status 500: mock_bad_response") @@ -67,7 +67,7 @@ func TestJoinBySnapshotStatus(t *testing.T) { // negative test due to connection failure to endorser client viper.Set("peer.client.connTimeout", 10*time.Millisecond) resetFlags() - cmd = joinBySnapshotStatusCmd(nil) + cmd = joinBySnapshotStatusCmd(nil, true) AddFlags(cmd) err = cmd.Execute() require.Error(t, err) diff --git a/internal/peer/channel/list.go b/internal/peer/channel/list.go index a29729d10c5..e93ce4d1232 100644 --- a/internal/peer/channel/list.go +++ b/internal/peer/channel/list.go @@ -23,9 +23,9 @@ type endorserClient struct { cf *ChannelCmdFactory } -func listCmd(cf *ChannelCmdFactory) *cobra.Command { +func listCmd(cf *ChannelCmdFactory, isNew bool) *cobra.Command { // Set the flags on the channel start command. - return &cobra.Command{ + listCmd := &cobra.Command{ Use: "list", Short: "List of channels peer has joined.", Long: "List of channels peer has joined.", @@ -38,6 +38,12 @@ func listCmd(cf *ChannelCmdFactory) *cobra.Command { return list(cf) }, } + if !isNew { + listCmd.Short = "[DEPRECATED] List of channels peer has joined (use the \"peercli channel list\")." + listCmd.Long = "[DEPRECATED] List of channels peer has joined. Instead of this command, use \"peercli channel list\"." + } + + return listCmd } func (cc *endorserClient) getChannels() ([]*pb.ChannelInfo, error) { diff --git a/internal/peer/channel/list_test.go b/internal/peer/channel/list_test.go index 0aa2138273c..d5f4cf08f01 100644 --- a/internal/peer/channel/list_test.go +++ b/internal/peer/channel/list_test.go @@ -46,7 +46,7 @@ func TestListChannels(t *testing.T) { Signer: signer, } - cmd := listCmd(mockCF) + cmd := listCmd(mockCF, true) AddFlags(cmd) if err := cmd.Execute(); err != nil { t.Fail() @@ -57,7 +57,7 @@ func TestListChannels(t *testing.T) { } func testListChannelsEmptyCF(t *testing.T, mockCF *ChannelCmdFactory) { - cmd := listCmd(nil) + cmd := listCmd(nil, true) AddFlags(cmd) // Error case 1: no orderer endpoints diff --git a/internal/peer/channel/signconfigtx.go b/internal/peer/channel/signconfigtx.go index 5a869639156..49d28bd3223 100644 --- a/internal/peer/channel/signconfigtx.go +++ b/internal/peer/channel/signconfigtx.go @@ -13,7 +13,7 @@ import ( "github.com/spf13/cobra" ) -func signconfigtxCmd(cf *ChannelCmdFactory) *cobra.Command { +func signconfigtxCmd(cf *ChannelCmdFactory, isNew bool) *cobra.Command { signconfigtxCmd := &cobra.Command{ Use: "signconfigtx", Short: "Signs a configtx update.", @@ -22,6 +22,10 @@ func signconfigtxCmd(cf *ChannelCmdFactory) *cobra.Command { return sign(cmd, args, cf) }, } + if !isNew { + signconfigtxCmd.Short = "[DEPRECATED] Signs a configtx update (use the \"peercli channel signconfigtx\")." + signconfigtxCmd.Long = "[DEPRECATED] Signs the supplied configtx update file in place on the filesystem. Requires '-f'. Instead of this command, use \"peercli channel signconfigtx\"." + } flagList := []string{ "file", } diff --git a/internal/peer/channel/signconfigtx_test.go b/internal/peer/channel/signconfigtx_test.go index 56fce7bfadb..f3df56503b1 100644 --- a/internal/peer/channel/signconfigtx_test.go +++ b/internal/peer/channel/signconfigtx_test.go @@ -35,7 +35,7 @@ func TestSignConfigtx(t *testing.T) { Signer: signer, } - cmd := signconfigtxCmd(mockCF) + cmd := signconfigtxCmd(mockCF, true) AddFlags(cmd) @@ -58,7 +58,7 @@ func TestSignConfigtxMissingConfigTxFlag(t *testing.T) { Signer: signer, } - cmd := signconfigtxCmd(mockCF) + cmd := signconfigtxCmd(mockCF, true) AddFlags(cmd) @@ -80,7 +80,7 @@ func TestSignConfigtxChannelMissingConfigTxFile(t *testing.T) { Signer: signer, } - cmd := signconfigtxCmd(mockCF) + cmd := signconfigtxCmd(mockCF, true) AddFlags(cmd) diff --git a/internal/peer/channel/update.go b/internal/peer/channel/update.go index 15e311f1813..f605652d0f4 100644 --- a/internal/peer/channel/update.go +++ b/internal/peer/channel/update.go @@ -16,11 +16,12 @@ import ( "github.com/spf13/cobra" ) +// deprecated func updateCmd(cf *ChannelCmdFactory) *cobra.Command { updateCmd := &cobra.Command{ Use: "update", - Short: "Send a configtx update.", - Long: "Signs and sends the supplied configtx update file to the channel. Requires '-f', '-o', '-c'.", + Short: "[DEPRECATED] Send a configtx update (use the \"osnadmin update\").", + Long: "[DEPRECATED] Signs and sends the supplied configtx update file to the channel. Requires '-f', '-o', '-c'. . Instead of this command, use Orderer Service Node (OSN).", RunE: func(cmd *cobra.Command, args []string) error { return update(cmd, args, cf) }, @@ -34,6 +35,7 @@ func updateCmd(cf *ChannelCmdFactory) *cobra.Command { return updateCmd } +// deprecated func update(cmd *cobra.Command, args []string, cf *ChannelCmdFactory) error { // the global chainID filled by the "-c" command if channelID == common.UndefinedParamValue { diff --git a/internal/peer/common/common.go b/internal/peer/common/common.go index 06508b80e2f..ea78967dfb6 100644 --- a/internal/peer/common/common.go +++ b/internal/peer/common/common.go @@ -211,7 +211,7 @@ func SetBCCSPKeystorePath() { } } -// GetDefaultSigner return a default Signer(Default/PEER) for cli +// GetDefaultSigner return a default Signer(Default/PEER) for peercli func GetDefaultSigner() (msp.SigningIdentity, error) { signer, err := mspmgmt.GetLocalMSP(factory.GetDefault()).GetDefaultSigningIdentity() if err != nil { @@ -391,8 +391,10 @@ func InitCmd(cmd *cobra.Command, args []string) { }) // chaincode packaging does not require material from the local MSP - if cmd.CommandPath() == "peer lifecycle chaincode package" || cmd.CommandPath() == "peer lifecycle chaincode calculatepackageid" { - mainLogger.Debug("peer lifecycle chaincode package does not need to init crypto") + if cmd.CommandPath() == "peercli lifecycle chaincode package" || cmd.CommandPath() == "peercli lifecycle chaincode calculatepackageid" || + cmd.CommandPath() == "peer lifecycle chaincode package" || cmd.CommandPath() == "peer lifecycle chaincode calculatepackageid" { + // TODO: peer lifecycle is deprecated + mainLogger.Debug("peercli lifecycle chaincode package does not need to init crypto") return } diff --git a/internal/peer/common/common_test.go b/internal/peer/common/common_test.go index ae8d07f6596..ac024cf58e2 100644 --- a/internal/peer/common/common_test.go +++ b/internal/peer/common/common_test.go @@ -226,8 +226,8 @@ func TestInitCmdWithoutInitCrypto(t *testing.T) { configtest.SetDevFabricConfigPath(t) defer viper.Reset() - peerCmd := &cobra.Command{ - Use: "peer", + peercliCmd := &cobra.Command{ + Use: "peercli", } lifecycleCmd := &cobra.Command{ Use: "lifecycle", @@ -238,16 +238,16 @@ func TestInitCmdWithoutInitCrypto(t *testing.T) { packageCmd := &cobra.Command{ Use: "package", } - // peer lifecycle chaincode package + // peercli lifecycle chaincode package chaincodeCmd.AddCommand(packageCmd) lifecycleCmd.AddCommand(chaincodeCmd) - peerCmd.AddCommand(lifecycleCmd) + peercliCmd.AddCommand(lifecycleCmd) // MSPCONFIGPATH is default value common.InitCmd(packageCmd, nil) // set MSPCONFIGPATH to be a missing dir, the function InitCrypto will fail - // confirm that 'peer lifecycle chaincode package' mandates does not require MSPCONFIG information + // confirm that 'peercli lifecycle chaincode package' mandates does not require MSPCONFIG information viper.SetEnvPrefix("core") viper.AutomaticEnv() replacer := strings.NewReplacer(".", "_") diff --git a/internal/peer/lifecycle/chaincode/approveformyorg.go b/internal/peer/lifecycle/chaincode/approveformyorg.go index 3115bcf9bef..a2b912448c4 100644 --- a/internal/peer/lifecycle/chaincode/approveformyorg.go +++ b/internal/peer/lifecycle/chaincode/approveformyorg.go @@ -79,7 +79,7 @@ func (a *ApproveForMyOrgInput) Validate() error { } // ApproveForMyOrgCmd returns the cobra command for chaincode ApproveForMyOrg -func ApproveForMyOrgCmd(a *ApproverForMyOrg, cryptoProvider bccsp.BCCSP) *cobra.Command { +func ApproveForMyOrgCmd(a *ApproverForMyOrg, cryptoProvider bccsp.BCCSP, isNew bool) *cobra.Command { chaincodeApproveForMyOrgCmd := &cobra.Command{ Use: "approveformyorg", Short: "Approve the chaincode definition for my org.", @@ -126,6 +126,12 @@ func ApproveForMyOrgCmd(a *ApproverForMyOrg, cryptoProvider bccsp.BCCSP) *cobra. return a.Approve() }, } + + if !isNew { + chaincodeApproveForMyOrgCmd.Short = "[DEPRECATED] Approve the chaincode definition for my org (use the \"peercli lifecycle chaincode approveformyorg\")." + chaincodeApproveForMyOrgCmd.Long = "[DEPRECATED] Approve the chaincode definition for my organization. Instead of this command, use \"peercli lifecycle chaincode approveformyorg\"." + } + flagList := []string{ "channelID", "name", diff --git a/internal/peer/lifecycle/chaincode/approveformyorg_test.go b/internal/peer/lifecycle/chaincode/approveformyorg_test.go index 543edd194e4..c7aab005ea8 100644 --- a/internal/peer/lifecycle/chaincode/approveformyorg_test.go +++ b/internal/peer/lifecycle/chaincode/approveformyorg_test.go @@ -301,7 +301,7 @@ var _ = Describe("ApproverForMyOrg", func() { BeforeEach(func() { cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore()) Expect(err).To(BeNil()) - approveForMyOrgCmd = chaincode.ApproveForMyOrgCmd(nil, cryptoProvider) + approveForMyOrgCmd = chaincode.ApproveForMyOrgCmd(nil, cryptoProvider, true) approveForMyOrgCmd.SilenceErrors = true approveForMyOrgCmd.SilenceUsage = true approveForMyOrgCmd.SetArgs([]string{ diff --git a/internal/peer/lifecycle/chaincode/calculatepackageid.go b/internal/peer/lifecycle/chaincode/calculatepackageid.go index 168b6b4bcd5..971a95cdeb3 100644 --- a/internal/peer/lifecycle/chaincode/calculatepackageid.go +++ b/internal/peer/lifecycle/chaincode/calculatepackageid.go @@ -50,7 +50,7 @@ func (i *CalculatePackageIDInput) Validate() error { // CalculatePackageIDCmd returns the cobra command for calculating // the package ID for a packaged chaincode -func CalculatePackageIDCmd(p *PackageIDCalculator) *cobra.Command { +func CalculatePackageIDCmd(p *PackageIDCalculator, isNew bool) *cobra.Command { calculatePackageIDCmd := &cobra.Command{ Use: "calculatepackageid [packageFile]", Short: "Calculate the package ID for a chaincode.", @@ -68,6 +68,12 @@ func CalculatePackageIDCmd(p *PackageIDCalculator) *cobra.Command { return p.CalculatePackageID(args) }, } + + if !isNew { + calculatePackageIDCmd.Short = "[DEPRECATED] Calculate the package ID for a chaincode (use the \"peercli lifecycle chaincode calculatepackageid\")." + calculatePackageIDCmd.Long = "[DEPRECATED] Calculate the package ID for a packaged chaincode. Instead of this command, use \"peercli lifecycle chaincode calculatepackageid\"." + } + flagList := []string{ "peerAddresses", "tlsRootCertFiles", diff --git a/internal/peer/lifecycle/chaincode/calculatepackageid_test.go b/internal/peer/lifecycle/chaincode/calculatepackageid_test.go index a45f3f7e9af..b249b8b7059 100644 --- a/internal/peer/lifecycle/chaincode/calculatepackageid_test.go +++ b/internal/peer/lifecycle/chaincode/calculatepackageid_test.go @@ -110,7 +110,7 @@ var _ = Describe("CalculatePackageID", func() { var calculatePackageIDCmd *cobra.Command BeforeEach(func() { - calculatePackageIDCmd = chaincode.CalculatePackageIDCmd(nil) + calculatePackageIDCmd = chaincode.CalculatePackageIDCmd(nil, true) calculatePackageIDCmd.SilenceErrors = true calculatePackageIDCmd.SilenceUsage = true calculatePackageIDCmd.SetArgs([]string{ diff --git a/internal/peer/lifecycle/chaincode/chaincode.go b/internal/peer/lifecycle/chaincode/chaincode.go index b0d392fb4bf..44c69fd308a 100644 --- a/internal/peer/lifecycle/chaincode/chaincode.go +++ b/internal/peer/lifecycle/chaincode/chaincode.go @@ -30,19 +30,24 @@ func addFlags(cmd *cobra.Command) { } // Cmd returns the cobra command for Chaincode -func Cmd(cryptoProvider bccsp.BCCSP) *cobra.Command { +func Cmd(cryptoProvider bccsp.BCCSP, isNew bool) *cobra.Command { addFlags(chaincodeCmd) - chaincodeCmd.AddCommand(PackageCmd(nil)) - chaincodeCmd.AddCommand(CalculatePackageIDCmd(nil)) - chaincodeCmd.AddCommand(InstallCmd(nil, cryptoProvider)) - chaincodeCmd.AddCommand(QueryInstalledCmd(nil, cryptoProvider)) - chaincodeCmd.AddCommand(GetInstalledPackageCmd(nil, cryptoProvider)) - chaincodeCmd.AddCommand(ApproveForMyOrgCmd(nil, cryptoProvider)) - chaincodeCmd.AddCommand(QueryApprovedCmd(nil, cryptoProvider)) - chaincodeCmd.AddCommand(CheckCommitReadinessCmd(nil, cryptoProvider)) - chaincodeCmd.AddCommand(CommitCmd(nil, cryptoProvider)) - chaincodeCmd.AddCommand(QueryCommittedCmd(nil, cryptoProvider)) + chaincodeCmd.AddCommand(PackageCmd(nil, isNew)) + chaincodeCmd.AddCommand(CalculatePackageIDCmd(nil, isNew)) + chaincodeCmd.AddCommand(InstallCmd(nil, cryptoProvider, isNew)) + chaincodeCmd.AddCommand(QueryInstalledCmd(nil, cryptoProvider, isNew)) + chaincodeCmd.AddCommand(GetInstalledPackageCmd(nil, cryptoProvider, isNew)) + chaincodeCmd.AddCommand(ApproveForMyOrgCmd(nil, cryptoProvider, isNew)) + chaincodeCmd.AddCommand(QueryApprovedCmd(nil, cryptoProvider, isNew)) + chaincodeCmd.AddCommand(CheckCommitReadinessCmd(nil, cryptoProvider, isNew)) + chaincodeCmd.AddCommand(CommitCmd(nil, cryptoProvider, isNew)) + chaincodeCmd.AddCommand(QueryCommittedCmd(nil, cryptoProvider, isNew)) + + if !isNew { + chaincodeCmd.Short = "[DEPRECATED] Perform chaincode operations: package|install|queryinstalled|getinstalledpackage|calculatepackageid|approveformyorg|queryapproved|checkcommitreadiness|commit|querycommitted (use the \"peercli lifecycle chaincode\")." + chaincodeCmd.Long = "[DEPRECATED] Perform chaincode operations: package|install|queryinstalled|getinstalledpackage|calculatepackageid|approveformyorg|queryapproved|checkcommitreadiness|commit|querycommitted. Instead of this command, use \"peercli lifecycle chaincode\"." + } return chaincodeCmd } @@ -76,8 +81,8 @@ var ( var chaincodeCmd = &cobra.Command{ Use: "chaincode", - Short: "Perform chaincode operations: package|install|queryinstalled|getinstalledpackage|calculatepackageid|approveformyorg|queryapproved|checkcommitreadiness|commit|querycommitted", - Long: "Perform chaincode operations: package|install|queryinstalled|getinstalledpackage|calculatepackageid|approveformyorg|queryapproved|checkcommitreadiness|commit|querycommitted", + Short: "Perform chaincode operations: package|install|queryinstalled|getinstalledpackage|calculatepackageid|approveformyorg|queryapproved|checkcommitreadiness|commit|querycommitted.", + Long: "Perform chaincode operations: package|install|queryinstalled|getinstalledpackage|calculatepackageid|approveformyorg|queryapproved|checkcommitreadiness|commit|querycommitted.", PersistentPreRun: func(cmd *cobra.Command, args []string) { common.InitCmd(cmd, args) common.SetOrdererEnv(cmd, args) diff --git a/internal/peer/lifecycle/chaincode/checkcommitreadiness.go b/internal/peer/lifecycle/chaincode/checkcommitreadiness.go index 6ee1cf089fe..db7883941d2 100644 --- a/internal/peer/lifecycle/chaincode/checkcommitreadiness.go +++ b/internal/peer/lifecycle/chaincode/checkcommitreadiness.go @@ -83,7 +83,7 @@ func (c *CommitReadinessCheckInput) Validate() error { // CheckCommitReadinessCmd returns the cobra command for the // CheckCommitReadiness lifecycle operation -func CheckCommitReadinessCmd(c *CommitReadinessChecker, cryptoProvider bccsp.BCCSP) *cobra.Command { +func CheckCommitReadinessCmd(c *CommitReadinessChecker, cryptoProvider bccsp.BCCSP, isNew bool) *cobra.Command { chaincodeCheckCommitReadinessCmd := &cobra.Command{ Use: "checkcommitreadiness", Short: "Check whether a chaincode definition is ready to be committed on a channel.", @@ -123,6 +123,12 @@ func CheckCommitReadinessCmd(c *CommitReadinessChecker, cryptoProvider bccsp.BCC return c.ReadinessCheck() }, } + + if !isNew { + chaincodeCheckCommitReadinessCmd.Short = "[DEPRECATED] Check whether a chaincode definition is ready to be committed on a channel (use the \"peercli lifecycle chaincode checkcommitreadiness\")." + chaincodeCheckCommitReadinessCmd.Long = "[DEPRECATED] Check whether a chaincode definition is ready to be committed on a channel. Instead of this command, use \"peercli lifecycle chaincode checkcommitreadiness\"." + } + flagList := []string{ "channelID", "name", diff --git a/internal/peer/lifecycle/chaincode/checkcommitreadiness_test.go b/internal/peer/lifecycle/chaincode/checkcommitreadiness_test.go index 73a984d653f..00b64aeb4f4 100644 --- a/internal/peer/lifecycle/chaincode/checkcommitreadiness_test.go +++ b/internal/peer/lifecycle/chaincode/checkcommitreadiness_test.go @@ -291,7 +291,7 @@ var _ = Describe("CheckCommitReadiness", func() { BeforeEach(func() { cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore()) Expect(err).To(BeNil()) - checkCommitReadinessCmd = chaincode.CheckCommitReadinessCmd(nil, cryptoProvider) + checkCommitReadinessCmd = chaincode.CheckCommitReadinessCmd(nil, cryptoProvider, true) checkCommitReadinessCmd.SilenceErrors = true checkCommitReadinessCmd.SilenceUsage = true checkCommitReadinessCmd.SetArgs([]string{ diff --git a/internal/peer/lifecycle/chaincode/commit.go b/internal/peer/lifecycle/chaincode/commit.go index a13d4abc29b..7b922f436c9 100644 --- a/internal/peer/lifecycle/chaincode/commit.go +++ b/internal/peer/lifecycle/chaincode/commit.go @@ -79,7 +79,7 @@ func (c *CommitInput) Validate() error { } // CommitCmd returns the cobra command for chaincode Commit -func CommitCmd(c *Committer, cryptoProvider bccsp.BCCSP) *cobra.Command { +func CommitCmd(c *Committer, cryptoProvider bccsp.BCCSP, isNew bool) *cobra.Command { chaincodeCommitCmd := &cobra.Command{ Use: "commit", Short: "Commit the chaincode definition on the channel.", @@ -126,6 +126,12 @@ func CommitCmd(c *Committer, cryptoProvider bccsp.BCCSP) *cobra.Command { return c.Commit() }, } + + if !isNew { + chaincodeCommitCmd.Short = "[DEPRECATED] Commit the chaincode definition on the channel (use the \"peercli lifecycle chaincode commit\")." + chaincodeCommitCmd.Long = "[DEPRECATED] Commit the chaincode definition on the channel. Instead of this command, use \"peercli lifecycle chaincode commit\"." + } + flagList := []string{ "channelID", "name", diff --git a/internal/peer/lifecycle/chaincode/commit_test.go b/internal/peer/lifecycle/chaincode/commit_test.go index f57293f78b6..7dc38ee4b32 100644 --- a/internal/peer/lifecycle/chaincode/commit_test.go +++ b/internal/peer/lifecycle/chaincode/commit_test.go @@ -300,7 +300,7 @@ var _ = Describe("Commit", func() { BeforeEach(func() { cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore()) Expect(err).To(BeNil()) - commitCmd = chaincode.CommitCmd(nil, cryptoProvider) + commitCmd = chaincode.CommitCmd(nil, cryptoProvider, true) commitCmd.SilenceErrors = true commitCmd.SilenceUsage = true commitCmd.SetArgs([]string{ diff --git a/internal/peer/lifecycle/chaincode/getinstalledpackage.go b/internal/peer/lifecycle/chaincode/getinstalledpackage.go index a2fb16f2fb5..c769e87a19d 100644 --- a/internal/peer/lifecycle/chaincode/getinstalledpackage.go +++ b/internal/peer/lifecycle/chaincode/getinstalledpackage.go @@ -50,7 +50,7 @@ func (i *GetInstalledPackageInput) Validate() error { // GetInstalledPackageCmd returns the cobra command for getting an // installed chaincode package from a peer. -func GetInstalledPackageCmd(i *InstalledPackageGetter, cryptoProvider bccsp.BCCSP) *cobra.Command { +func GetInstalledPackageCmd(i *InstalledPackageGetter, cryptoProvider bccsp.BCCSP, isNew bool) *cobra.Command { chaincodeGetInstalledPackageCmd := &cobra.Command{ Use: "getinstalledpackage [outputfile]", Short: "Get an installed chaincode package from a peer.", @@ -92,6 +92,11 @@ func GetInstalledPackageCmd(i *InstalledPackageGetter, cryptoProvider bccsp.BCCS }, } + if !isNew { + chaincodeGetInstalledPackageCmd.Short = "[DEPRECATED] Get an installed chaincode package from a peer (use the \"peercli lifecycle chaincode getinstalledpackage\")." + chaincodeGetInstalledPackageCmd.Long = "[DEPRECATED] Get an installed chaincode package from a peer. Instead of this command, use \"peercli lifecycle chaincode getinstalledpackage\"." + } + flagList := []string{ "peerAddresses", "tlsRootCertFiles", diff --git a/internal/peer/lifecycle/chaincode/getinstalledpackage_test.go b/internal/peer/lifecycle/chaincode/getinstalledpackage_test.go index 76e343712dc..afd665db898 100644 --- a/internal/peer/lifecycle/chaincode/getinstalledpackage_test.go +++ b/internal/peer/lifecycle/chaincode/getinstalledpackage_test.go @@ -219,7 +219,7 @@ var _ = Describe("GetInstalledPackage", func() { BeforeEach(func() { cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore()) Expect(err).To(BeNil()) - getInstalledPackageCmd = chaincode.GetInstalledPackageCmd(nil, cryptoProvider) + getInstalledPackageCmd = chaincode.GetInstalledPackageCmd(nil, cryptoProvider, true) getInstalledPackageCmd.SilenceErrors = true getInstalledPackageCmd.SilenceUsage = true getInstalledPackageCmd.SetArgs([]string{ diff --git a/internal/peer/lifecycle/chaincode/install.go b/internal/peer/lifecycle/chaincode/install.go index 150f5b708a6..a86af997bfe 100644 --- a/internal/peer/lifecycle/chaincode/install.go +++ b/internal/peer/lifecycle/chaincode/install.go @@ -53,7 +53,7 @@ func (i *InstallInput) Validate() error { } // InstallCmd returns the cobra command for chaincode install. -func InstallCmd(i *Installer, cryptoProvider bccsp.BCCSP) *cobra.Command { +func InstallCmd(i *Installer, cryptoProvider bccsp.BCCSP, isNew bool) *cobra.Command { chaincodeInstallCmd := &cobra.Command{ Use: "install [packageFile]", Short: "Install a chaincode.", @@ -87,6 +87,12 @@ func InstallCmd(i *Installer, cryptoProvider bccsp.BCCSP) *cobra.Command { return i.InstallChaincode(args) }, } + + if !isNew { + chaincodeInstallCmd.Short = "[DEPRECATED] Install a chaincode (use the \"peercli lifecycle chaincode install\")." + chaincodeInstallCmd.Long = "[DEPRECATED] Install a chaincode on a peer. Instead of this command, use \"peercli lifecycle chaincode install\"." + } + flagList := []string{ "peerAddresses", "tlsRootCertFiles", diff --git a/internal/peer/lifecycle/chaincode/install_test.go b/internal/peer/lifecycle/chaincode/install_test.go index 8f3e43b4056..c47081661bb 100644 --- a/internal/peer/lifecycle/chaincode/install_test.go +++ b/internal/peer/lifecycle/chaincode/install_test.go @@ -173,7 +173,7 @@ var _ = Describe("Install", func() { BeforeEach(func() { cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore()) Expect(err).To(BeNil()) - installCmd = chaincode.InstallCmd(nil, cryptoProvider) + installCmd = chaincode.InstallCmd(nil, cryptoProvider, true) installCmd.SilenceErrors = true installCmd.SilenceUsage = true installCmd.SetArgs([]string{ diff --git a/internal/peer/lifecycle/chaincode/package.go b/internal/peer/lifecycle/chaincode/package.go index 07512524fca..f58b8a89751 100644 --- a/internal/peer/lifecycle/chaincode/package.go +++ b/internal/peer/lifecycle/chaincode/package.go @@ -67,7 +67,7 @@ func (p *PackageInput) Validate() error { } // PackageCmd returns the cobra command for packaging chaincode -func PackageCmd(p *Packager) *cobra.Command { +func PackageCmd(p *Packager, isNew bool) *cobra.Command { chaincodePackageCmd := &cobra.Command{ Use: "package [outputfile]", Short: "Package a chaincode", @@ -87,6 +87,12 @@ func PackageCmd(p *Packager) *cobra.Command { return p.PackageChaincode(args) }, } + + if !isNew { + chaincodePackageCmd.Short = "[DEPRECATED] Package a chaincode (use the \"peercli lifecycle chaincode package\")." + chaincodePackageCmd.Long = "[DEPRECATED] Package a chaincode and write the package to a file. Instead of this command, use \"peercli lifecycle chaincode package\"." + } + flagList := []string{ "label", "lang", diff --git a/internal/peer/lifecycle/chaincode/package_test.go b/internal/peer/lifecycle/chaincode/package_test.go index 0511e2c6374..bf014aa8d65 100644 --- a/internal/peer/lifecycle/chaincode/package_test.go +++ b/internal/peer/lifecycle/chaincode/package_test.go @@ -171,7 +171,7 @@ var _ = Describe("Package", func() { var packageCmd *cobra.Command BeforeEach(func() { - packageCmd = chaincode.PackageCmd(nil) + packageCmd = chaincode.PackageCmd(nil, true) packageCmd.SilenceErrors = true packageCmd.SilenceUsage = true packageCmd.SetArgs([]string{ diff --git a/internal/peer/lifecycle/chaincode/queryapproved.go b/internal/peer/lifecycle/chaincode/queryapproved.go index a96d5cefc83..f0d5ebf75b9 100644 --- a/internal/peer/lifecycle/chaincode/queryapproved.go +++ b/internal/peer/lifecycle/chaincode/queryapproved.go @@ -43,7 +43,7 @@ type ApprovedQueryInput struct { // QueryApprovedCmd returns the cobra command for // querying the approved chaincode definition for the organization -func QueryApprovedCmd(a *ApprovedQuerier, cryptoProvider bccsp.BCCSP) *cobra.Command { +func QueryApprovedCmd(a *ApprovedQuerier, cryptoProvider bccsp.BCCSP, isNew bool) *cobra.Command { chaincodeQueryApprovedCmd := &cobra.Command{ Use: "queryapproved", Short: "Query org's approved chaincode definitions from its peer.", @@ -83,6 +83,12 @@ func QueryApprovedCmd(a *ApprovedQuerier, cryptoProvider bccsp.BCCSP) *cobra.Com return a.Query() }, } + + if !isNew { + chaincodeQueryApprovedCmd.Short = "[DEPRECATED] Query org's approved chaincode definitions from its peer (use the \"peercli lifecycle chaincode queryapproved\")." + chaincodeQueryApprovedCmd.Long = "[DEPRECATED] Query organization's approved chaincode definitions from its peer. Instead of this command, use \"peercli lifecycle chaincode queryapproved\"." + } + flagList := []string{ "channelID", "name", diff --git a/internal/peer/lifecycle/chaincode/queryapproved_test.go b/internal/peer/lifecycle/chaincode/queryapproved_test.go index 8e733248a9f..e4311894cfa 100644 --- a/internal/peer/lifecycle/chaincode/queryapproved_test.go +++ b/internal/peer/lifecycle/chaincode/queryapproved_test.go @@ -402,7 +402,7 @@ var _ = Describe("QueryApproved", func() { BeforeEach(func() { cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore()) Expect(err).To(BeNil()) - queryApprovedCmd = chaincode.QueryApprovedCmd(nil, cryptoProvider) + queryApprovedCmd = chaincode.QueryApprovedCmd(nil, cryptoProvider, true) queryApprovedCmd.SilenceErrors = true queryApprovedCmd.SilenceUsage = true queryApprovedCmd.SetArgs([]string{ diff --git a/internal/peer/lifecycle/chaincode/querycommitted.go b/internal/peer/lifecycle/chaincode/querycommitted.go index 80b42fe75c9..1a8a3a7be20 100644 --- a/internal/peer/lifecycle/chaincode/querycommitted.go +++ b/internal/peer/lifecycle/chaincode/querycommitted.go @@ -44,7 +44,7 @@ type CommittedQueryInput struct { // QueryCommittedCmd returns the cobra command for // querying a committed chaincode definition given // the chaincode name -func QueryCommittedCmd(c *CommittedQuerier, cryptoProvider bccsp.BCCSP) *cobra.Command { +func QueryCommittedCmd(c *CommittedQuerier, cryptoProvider bccsp.BCCSP, isNew bool) *cobra.Command { chaincodeQueryCommittedCmd := &cobra.Command{ Use: "querycommitted", Short: "Query the committed chaincode definitions by channel on a peer.", @@ -84,6 +84,11 @@ func QueryCommittedCmd(c *CommittedQuerier, cryptoProvider bccsp.BCCSP) *cobra.C }, } + if !isNew { + chaincodeQueryCommittedCmd.Short = "[DEPRECATED] Query the committed chaincode definitions by channel on a peer (use the \"peercli lifecycle chaincode querycommitted\")." + chaincodeQueryCommittedCmd.Long = "[DEPRECATED] Query the committed chaincode definitions by channel on a peer. Optional: provide a chaincode name to query a specific definition. Instead of this command, use \"peercli lifecycle chaincode querycommitted\"." + } + flagList := []string{ "channelID", "name", diff --git a/internal/peer/lifecycle/chaincode/querycommitted_test.go b/internal/peer/lifecycle/chaincode/querycommitted_test.go index abdd43a9fd2..e77c686c121 100644 --- a/internal/peer/lifecycle/chaincode/querycommitted_test.go +++ b/internal/peer/lifecycle/chaincode/querycommitted_test.go @@ -317,7 +317,7 @@ var _ = Describe("QueryCommitted", func() { BeforeEach(func() { cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore()) Expect(err).To(BeNil()) - queryCommittedCmd = chaincode.QueryCommittedCmd(nil, cryptoProvider) + queryCommittedCmd = chaincode.QueryCommittedCmd(nil, cryptoProvider, true) queryCommittedCmd.SilenceErrors = true queryCommittedCmd.SilenceUsage = true queryCommittedCmd.SetArgs([]string{ diff --git a/internal/peer/lifecycle/chaincode/queryinstalled.go b/internal/peer/lifecycle/chaincode/queryinstalled.go index a8bb1f0b931..ff738649183 100644 --- a/internal/peer/lifecycle/chaincode/queryinstalled.go +++ b/internal/peer/lifecycle/chaincode/queryinstalled.go @@ -40,7 +40,7 @@ type InstalledQueryInput struct { // QueryInstalledCmd returns the cobra command for listing // the installed chaincodes -func QueryInstalledCmd(i *InstalledQuerier, cryptoProvider bccsp.BCCSP) *cobra.Command { +func QueryInstalledCmd(i *InstalledQuerier, cryptoProvider bccsp.BCCSP, isNew bool) *cobra.Command { chaincodeQueryInstalledCmd := &cobra.Command{ Use: "queryinstalled", Short: "Query the installed chaincodes on a peer.", @@ -81,6 +81,11 @@ func QueryInstalledCmd(i *InstalledQuerier, cryptoProvider bccsp.BCCSP) *cobra.C }, } + if !isNew { + chaincodeQueryInstalledCmd.Short = "[DEPRECATED] Query the installed chaincodes on a peer (use the \"peercli lifecycle chaincode queryinstalled\")." + chaincodeQueryInstalledCmd.Long = "[DEPRECATED] Query the installed chaincodes on a peer. Instead of this command, use \"peercli lifecycle chaincode queryinstalled\"." + } + flagList := []string{ "peerAddresses", "tlsRootCertFiles", diff --git a/internal/peer/lifecycle/chaincode/queryinstalled_test.go b/internal/peer/lifecycle/chaincode/queryinstalled_test.go index bd8588b053a..a82e778748d 100644 --- a/internal/peer/lifecycle/chaincode/queryinstalled_test.go +++ b/internal/peer/lifecycle/chaincode/queryinstalled_test.go @@ -188,7 +188,7 @@ var _ = Describe("QueryInstalled", func() { BeforeEach(func() { cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore()) Expect(err).To(BeNil()) - queryInstalledCmd = chaincode.QueryInstalledCmd(nil, cryptoProvider) + queryInstalledCmd = chaincode.QueryInstalledCmd(nil, cryptoProvider, true) queryInstalledCmd.SilenceErrors = true queryInstalledCmd.SilenceUsage = true queryInstalledCmd.SetArgs([]string{ diff --git a/internal/peer/lifecycle/lifecycle.go b/internal/peer/lifecycle/lifecycle.go index ede14fc5a2b..a59be3fdd67 100644 --- a/internal/peer/lifecycle/lifecycle.go +++ b/internal/peer/lifecycle/lifecycle.go @@ -13,13 +13,18 @@ import ( ) // Cmd returns the cobra command for lifecycle -func Cmd(cryptoProvider bccsp.BCCSP) *cobra.Command { +func Cmd(cryptoProvider bccsp.BCCSP, isNew bool) *cobra.Command { lifecycleCmd := &cobra.Command{ Use: "lifecycle", - Short: "Perform _lifecycle operations", - Long: "Perform _lifecycle operations", + Short: "Perform _lifecycle operations.", + Long: "Perform _lifecycle operations.", + } + lifecycleCmd.AddCommand(chaincode.Cmd(cryptoProvider, isNew)) + + if !isNew { + lifecycleCmd.Short = "[DEPRECATED] Perform _lifecycle operations (use the \"peercli lifecycle\")." + lifecycleCmd.Long = "[DEPRECATED] Perform _lifecycle operations. Instead of this command, use \"peercli lifecycle\"." } - lifecycleCmd.AddCommand(chaincode.Cmd(cryptoProvider)) return lifecycleCmd } diff --git a/internal/peer/snapshot/cancelrequest.go b/internal/peer/snapshot/cancelrequest.go index 687cd3ca2a4..8ee20abc434 100644 --- a/internal/peer/snapshot/cancelrequest.go +++ b/internal/peer/snapshot/cancelrequest.go @@ -17,7 +17,7 @@ import ( ) // cancelRequestCmd returns the cobra command for snapshot cancelrequest command -func cancelRequestCmd(cl *client, cryptoProvider bccsp.BCCSP) *cobra.Command { +func cancelRequestCmd(cl *client, cryptoProvider bccsp.BCCSP, isNew bool) *cobra.Command { snapshotCancelRequestCmd := &cobra.Command{ Use: "cancelrequest", Short: "Cancel a request for a snapshot at the specified block.", @@ -27,6 +27,11 @@ func cancelRequestCmd(cl *client, cryptoProvider bccsp.BCCSP) *cobra.Command { }, } + if !isNew { + snapshotCancelRequestCmd.Short = "[DEPRECATED] Cancel a request for a snapshot at the specified block (use the \"peercli snapshot cancelrequest\")" + snapshotCancelRequestCmd.Long = "[DEPRECATED] Cancel a request for a snapshot at the specified block. Instead of this command, use \"peercli snapshot cancelrequest\"." + } + flagList := []string{ "channelID", "blockNumber", diff --git a/internal/peer/snapshot/cancelrequest_test.go b/internal/peer/snapshot/cancelrequest_test.go index 5a4f92c57a5..fadd16df004 100644 --- a/internal/peer/snapshot/cancelrequest_test.go +++ b/internal/peer/snapshot/cancelrequest_test.go @@ -25,7 +25,7 @@ func TestCancelRequestCmd(t *testing.T) { mockClient := &client{mockSnapshotClient, mockSigner, buffer} resetFlags() - cmd := cancelRequestCmd(mockClient, nil) + cmd := cancelRequestCmd(mockClient, nil, true) cmd.SetArgs([]string{"-c", "mychannel", "-b", "100"}) err := cmd.Execute() require.NoError(t, err) diff --git a/internal/peer/snapshot/client_test.go b/internal/peer/snapshot/client_test.go index ec3f02eea55..b831fdae6ff 100644 --- a/internal/peer/snapshot/client_test.go +++ b/internal/peer/snapshot/client_test.go @@ -41,19 +41,19 @@ func TestValidatePeerConnectionParameters(t *testing.T) { // test error propagation args := []string{"-c", "mychannel"} resetFlags() - cmd := listPendingCmd(nil, nil) + cmd := listPendingCmd(nil, nil, true) cmd.SetArgs(args) err := cmd.Execute() require.EqualError(t, err, expectedErrMsg) resetFlags() - cmd = submitRequestCmd(nil, nil) + cmd = submitRequestCmd(nil, nil, true) cmd.SetArgs(args) err = cmd.Execute() require.EqualError(t, err, expectedErrMsg) resetFlags() - cmd = cancelRequestCmd(nil, nil) + cmd = cancelRequestCmd(nil, nil, true) // append required block number parameter for cancel request args = append(args, []string{"-b", "10"}...) cmd.SetArgs(args) diff --git a/internal/peer/snapshot/listpending.go b/internal/peer/snapshot/listpending.go index 0183a351fed..cf1b92d8804 100644 --- a/internal/peer/snapshot/listpending.go +++ b/internal/peer/snapshot/listpending.go @@ -17,7 +17,7 @@ import ( ) // listPendingCmd returns the cobra command for snapshot listpending command -func listPendingCmd(cl *client, cryptoProvider bccsp.BCCSP) *cobra.Command { +func listPendingCmd(cl *client, cryptoProvider bccsp.BCCSP, isNew bool) *cobra.Command { snapshotGenerateRequestCmd := &cobra.Command{ Use: "listpending", Short: "List pending requests for snapshots.", @@ -26,6 +26,12 @@ func listPendingCmd(cl *client, cryptoProvider bccsp.BCCSP) *cobra.Command { return listPending(cmd, cl, cryptoProvider) }, } + + if !isNew { + snapshotGenerateRequestCmd.Short = "[DEPRECATED] List pending requests for snapshots. (use the \"peercli snapshot listpending\")" + snapshotGenerateRequestCmd.Long = "[DEPRECATED] List pending requests for snapshots. Instead of this command, use \"peercli snapshot listpending\"." + } + flagList := []string{ "channelID", "peerAddress", diff --git a/internal/peer/snapshot/listpending_test.go b/internal/peer/snapshot/listpending_test.go index f7f5e9c86ab..d730a82a573 100644 --- a/internal/peer/snapshot/listpending_test.go +++ b/internal/peer/snapshot/listpending_test.go @@ -25,7 +25,7 @@ func TestListPendingCmd(t *testing.T) { mockClient := &client{mockSnapshotClient, mockSigner, buffer} resetFlags() - cmd := listPendingCmd(mockClient, nil) + cmd := listPendingCmd(mockClient, nil, true) cmd.SetArgs([]string{"-c", "mychannel"}) err := cmd.Execute() require.NoError(t, err) diff --git a/internal/peer/snapshot/snapshot.go b/internal/peer/snapshot/snapshot.go index 42126079837..bbebc113d55 100644 --- a/internal/peer/snapshot/snapshot.go +++ b/internal/peer/snapshot/snapshot.go @@ -21,10 +21,15 @@ import ( var logger = flogging.MustGetLogger("cli.snapshot") // Cmd returns the cobra command for Chaincode -func Cmd(cryptoProvider bccsp.BCCSP) *cobra.Command { - snapshotCmd.AddCommand(submitRequestCmd(nil, cryptoProvider)) - snapshotCmd.AddCommand(cancelRequestCmd(nil, cryptoProvider)) - snapshotCmd.AddCommand(listPendingCmd(nil, cryptoProvider)) +func Cmd(cryptoProvider bccsp.BCCSP, isNew bool) *cobra.Command { + snapshotCmd.AddCommand(submitRequestCmd(nil, cryptoProvider, isNew)) + snapshotCmd.AddCommand(cancelRequestCmd(nil, cryptoProvider, isNew)) + snapshotCmd.AddCommand(listPendingCmd(nil, cryptoProvider, isNew)) + + if !isNew { + snapshotCmd.Short = "[DEPRECATED] Manage snapshot requests: submitrequest|cancelrequest|listpending (use the \"peercli snapshot\")." + snapshotCmd.Long = "[DEPRECATED] Manage snapshot requests: submitrequest|cancelrequest|listpending. Instead of this command, use \"peercli snapshot\"." + } return snapshotCmd } @@ -39,8 +44,8 @@ var ( var snapshotCmd = &cobra.Command{ Use: "snapshot", - Short: "Manage snapshot requests: submitrequest|cancelrequest|listpending", - Long: "Manage snapshot requests: submitrequest|cancelrequest|listpending", + Short: "Manage snapshot requests: submitrequest|cancelrequest|listpending.", + Long: "Manage snapshot requests: submitrequest|cancelrequest|listpending.", PersistentPreRun: func(cmd *cobra.Command, args []string) { common.InitCmd(cmd, args) }, diff --git a/internal/peer/snapshot/submitrequest.go b/internal/peer/snapshot/submitrequest.go index 2fc91612e11..cebb391ccc6 100644 --- a/internal/peer/snapshot/submitrequest.go +++ b/internal/peer/snapshot/submitrequest.go @@ -17,7 +17,7 @@ import ( ) // submitRequestCmd returns the cobra command for snapshot submitrequest command -func submitRequestCmd(cl *client, cryptoProvider bccsp.BCCSP) *cobra.Command { +func submitRequestCmd(cl *client, cryptoProvider bccsp.BCCSP, isNew bool) *cobra.Command { snapshotSubmitRequestCmd := &cobra.Command{ Use: "submitrequest", Short: "Submit a request for a snapshot at the specified block.", @@ -27,6 +27,11 @@ func submitRequestCmd(cl *client, cryptoProvider bccsp.BCCSP) *cobra.Command { }, } + if !isNew { + snapshotSubmitRequestCmd.Short = "[DEPRECATED] Submit a request for a snapshot at the specified block. (use the \"peercli snapshot submitrequest\")." + snapshotSubmitRequestCmd.Long = "[DEPRECATED] Submit a request for a snapshot at the specified block. When the blockNumber parameter is set to 0 or not provided, it will submit a request for the last committed block. Instead of this command, use \"peercli snapshot submitrequest\"." + } + flagList := []string{ "channelID", "blockNumber", diff --git a/internal/peer/snapshot/submitrequest_test.go b/internal/peer/snapshot/submitrequest_test.go index 94ef8691a50..398e7496ddd 100644 --- a/internal/peer/snapshot/submitrequest_test.go +++ b/internal/peer/snapshot/submitrequest_test.go @@ -25,7 +25,7 @@ func TestSubmitRequestCmd(t *testing.T) { mockClient := &client{mockSnapshotClient, mockSigner, buffer} resetFlags() - cmd := submitRequestCmd(mockClient, nil) + cmd := submitRequestCmd(mockClient, nil, true) cmd.SetArgs([]string{"-c", "mychannel"}) require.NoError(t, cmd.Execute()) require.Equal(t, []byte("Snapshot request submitted successfully\n"), buffer.Contents()) @@ -34,7 +34,7 @@ func TestSubmitRequestCmd(t *testing.T) { buffer2 := gbytes.NewBuffer() mockClient.writer = buffer2 resetFlags() - cmd = submitRequestCmd(mockClient, nil) + cmd = submitRequestCmd(mockClient, nil, true) cmd.SetArgs([]string{"-c", "mychannel", "-b", "100"}) require.NoError(t, cmd.Execute()) require.Equal(t, []byte("Snapshot request submitted successfully\n"), buffer2.Contents()) diff --git a/scripts/help_docs.sh b/scripts/help_docs.sh index b3004860d4b..4df06582669 100755 --- a/scripts/help_docs.sh +++ b/scripts/help_docs.sh @@ -113,6 +113,41 @@ generateOrCheck \ docs/wrappers/peer_snapshot_postscript.md \ "${commands[@]}" +commands=("peercli version") +generateOrCheck \ + docs/source/commands/peercliversion.md \ + docs/wrappers/peercli_version_preamble.md \ + docs/wrappers/license_postscript.md \ + "${commands[@]}" + +commands=("peercli chaincode invoke" "peercli chaincode query") +generateOrCheck \ + docs/source/commands/peerclichaincode.md \ + docs/wrappers/peercli_chaincode_preamble.md \ + docs/wrappers/peercli_chaincode_postscript.md \ + "${commands[@]}" + +commands=("peercli lifecycle" "peercli lifecycle chaincode" "peercli lifecycle chaincode package" "peercli lifecycle chaincode install" "peercli lifecycle chaincode queryinstalled" "peercli lifecycle chaincode getinstalledpackage" "peercli lifecycle chaincode calculatepackageid" "peercli lifecycle chaincode approveformyorg" "peercli lifecycle chaincode queryapproved" "peercli lifecycle chaincode checkcommitreadiness" "peercli lifecycle chaincode commit" "peercli lifecycle chaincode querycommitted") +generateOrCheck \ + docs/source/commands/peerclilifecycle.md \ + docs/wrappers/peercli_lifecycle_chaincode_preamble.md \ + docs/wrappers/peercli_lifecycle_chaincode_postscript.md \ + "${commands[@]}" + +commands=("peercli channel" "peercli channel fetch" "peercli channel getinfo" "peercli channel join" "peercli channel joinbysnapshot" "peercli channel joinbysnapshotstatus" "peercli channel list" "peercli channel signconfigtx") +generateOrCheck \ + docs/source/commands/peerclichannel.md \ + docs/wrappers/peercli_channel_preamble.md \ + docs/wrappers/peercli_channel_postscript.md \ + "${commands[@]}" + +commands=("peercli snapshot cancelrequest" "peercli snapshot listpending" "peercli snapshot submitrequest") +generateOrCheck \ + docs/source/commands/peerclisnapshot.md \ + docs/wrappers/peercli_snapshot_preamble.md \ + docs/wrappers/peercli_snapshot_postscript.md \ + "${commands[@]}" + commands=("configtxgen") generateOrCheck \ docs/source/commands/configtxgen.md \