github.com/osdi23p228/fabric@v0.0.0-20221218062954-77808885f5db/integration/nwo/commands/peer.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package commands
     8  
     9  import (
    10  	"strconv"
    11  	"time"
    12  )
    13  
    14  type NodeStart struct {
    15  	PeerID  string
    16  	DevMode bool
    17  }
    18  
    19  func (n NodeStart) SessionName() string {
    20  	return n.PeerID
    21  }
    22  
    23  func (n NodeStart) Args() []string {
    24  	args := []string{"node", "start"}
    25  	if n.DevMode {
    26  		args = append(args, "--peer-chaincodedev")
    27  	}
    28  	return args
    29  }
    30  
    31  type NodeReset struct {
    32  }
    33  
    34  func (n NodeReset) SessionName() string {
    35  	return "peer-node-reset"
    36  }
    37  
    38  func (n NodeReset) Args() []string {
    39  	return []string{
    40  		"node", "reset",
    41  	}
    42  }
    43  
    44  type NodeRollback struct {
    45  	ChannelID   string
    46  	BlockNumber int
    47  }
    48  
    49  func (n NodeRollback) SessionName() string {
    50  	return "peer-node-rollback"
    51  }
    52  
    53  func (n NodeRollback) Args() []string {
    54  	return []string{
    55  		"node", "rollback",
    56  		"--channelID", n.ChannelID,
    57  		"--blockNumber", strconv.Itoa(n.BlockNumber),
    58  	}
    59  }
    60  
    61  type NodePause struct {
    62  	ChannelID string
    63  }
    64  
    65  func (n NodePause) SessionName() string {
    66  	return "peer-node-pause"
    67  }
    68  
    69  func (n NodePause) Args() []string {
    70  	return []string{
    71  		"node", "pause",
    72  		"--channelID", n.ChannelID,
    73  	}
    74  }
    75  
    76  type NodeResume struct {
    77  	ChannelID string
    78  }
    79  
    80  func (n NodeResume) SessionName() string {
    81  	return "peer-node-resume"
    82  }
    83  
    84  func (n NodeResume) Args() []string {
    85  	return []string{
    86  		"node", "resume",
    87  		"--channelID", n.ChannelID,
    88  	}
    89  }
    90  
    91  type ChannelCreate struct {
    92  	ChannelID   string
    93  	Orderer     string
    94  	File        string
    95  	OutputBlock string
    96  	ClientAuth  bool
    97  }
    98  
    99  func (c ChannelCreate) SessionName() string {
   100  	return "peer-channel-create"
   101  }
   102  
   103  func (c ChannelCreate) Args() []string {
   104  	args := []string{
   105  		"channel", "create",
   106  		"--channelID", c.ChannelID,
   107  		"--orderer", c.Orderer,
   108  		"--file", c.File,
   109  		"--outputBlock", c.OutputBlock,
   110  		"--timeout", "15s",
   111  	}
   112  	if c.ClientAuth {
   113  		args = append(args, "--clientauth")
   114  	}
   115  	return args
   116  }
   117  
   118  type ChannelJoin struct {
   119  	BlockPath  string
   120  	ClientAuth bool
   121  }
   122  
   123  func (c ChannelJoin) SessionName() string {
   124  	return "peer-channel-join"
   125  }
   126  
   127  func (c ChannelJoin) Args() []string {
   128  	args := []string{
   129  		"channel", "join",
   130  		"-b", c.BlockPath,
   131  	}
   132  	if c.ClientAuth {
   133  		args = append(args, "--clientauth")
   134  	}
   135  	return args
   136  }
   137  
   138  type ChannelFetch struct {
   139  	ChannelID             string
   140  	Block                 string
   141  	Orderer               string
   142  	OutputFile            string
   143  	ClientAuth            bool
   144  	TLSHandshakeTimeShift time.Duration
   145  }
   146  
   147  func (c ChannelFetch) SessionName() string {
   148  	return "peer-channel-fetch"
   149  }
   150  
   151  func (c ChannelFetch) Args() []string {
   152  	args := []string{
   153  		"channel", "fetch", c.Block,
   154  		"--channelID", c.ChannelID,
   155  		"--orderer", c.Orderer,
   156  		"--tlsHandshakeTimeShift", c.TLSHandshakeTimeShift.String(),
   157  		c.OutputFile,
   158  	}
   159  	if c.ClientAuth {
   160  		args = append(args, "--clientauth")
   161  	}
   162  
   163  	return args
   164  }
   165  
   166  type ChaincodePackage struct {
   167  	Path       string
   168  	Lang       string
   169  	Label      string
   170  	OutputFile string
   171  	ClientAuth bool
   172  }
   173  
   174  func (c ChaincodePackage) SessionName() string {
   175  	return "peer-lifecycle-chaincode-package"
   176  }
   177  
   178  func (c ChaincodePackage) Args() []string {
   179  	args := []string{
   180  		"lifecycle", "chaincode", "package",
   181  		"--path", c.Path,
   182  		"--lang", c.Lang,
   183  		"--label", c.Label,
   184  		c.OutputFile,
   185  	}
   186  
   187  	if c.ClientAuth {
   188  		args = append(args, "--clientauth")
   189  	}
   190  
   191  	return args
   192  }
   193  
   194  type ChaincodePackageLegacy struct {
   195  	Name       string
   196  	Version    string
   197  	Path       string
   198  	Lang       string
   199  	OutputFile string
   200  	ClientAuth bool
   201  }
   202  
   203  func (c ChaincodePackageLegacy) SessionName() string {
   204  	return "peer-chaincode-package"
   205  }
   206  
   207  func (c ChaincodePackageLegacy) Args() []string {
   208  	args := []string{
   209  		"chaincode", "package",
   210  		"--name", c.Name,
   211  		"--version", c.Version,
   212  		"--path", c.Path,
   213  		c.OutputFile,
   214  	}
   215  
   216  	if c.ClientAuth {
   217  		args = append(args, "--clientauth")
   218  	}
   219  	if c.Lang != "" {
   220  		args = append(args, "--lang", c.Lang)
   221  	}
   222  
   223  	return args
   224  }
   225  
   226  type ChaincodeInstall struct {
   227  	PackageFile   string
   228  	PeerAddresses []string
   229  	ClientAuth    bool
   230  }
   231  
   232  func (c ChaincodeInstall) SessionName() string {
   233  	return "peer-lifecycle-chaincode-install"
   234  }
   235  
   236  func (c ChaincodeInstall) Args() []string {
   237  	args := []string{
   238  		"lifecycle", "chaincode", "install",
   239  		c.PackageFile,
   240  	}
   241  
   242  	for _, p := range c.PeerAddresses {
   243  		args = append(args, "--peerAddresses", p)
   244  	}
   245  	if c.ClientAuth {
   246  		args = append(args, "--clientauth")
   247  	}
   248  
   249  	return args
   250  }
   251  
   252  type ChaincodeGetInstalledPackage struct {
   253  	PackageID       string
   254  	OutputDirectory string
   255  	ClientAuth      bool
   256  }
   257  
   258  func (c ChaincodeGetInstalledPackage) SessionName() string {
   259  	return "peer-lifecycle-chaincode-getinstalledpackage"
   260  }
   261  
   262  func (c ChaincodeGetInstalledPackage) Args() []string {
   263  	args := []string{
   264  		"lifecycle", "chaincode", "getinstalledpackage",
   265  		"--package-id", c.PackageID,
   266  		"--output-directory", c.OutputDirectory,
   267  	}
   268  	if c.ClientAuth {
   269  		args = append(args, "--clientauth")
   270  	}
   271  
   272  	return args
   273  }
   274  
   275  type ChaincodeInstallLegacy struct {
   276  	Name        string
   277  	Version     string
   278  	Path        string
   279  	Lang        string
   280  	PackageFile string
   281  	ClientAuth  bool
   282  }
   283  
   284  func (c ChaincodeInstallLegacy) SessionName() string {
   285  	return "peer-chaincode-install"
   286  }
   287  
   288  func (c ChaincodeInstallLegacy) Args() []string {
   289  	args := []string{
   290  		"chaincode", "install",
   291  	}
   292  
   293  	if c.PackageFile != "" {
   294  		args = append(args, c.PackageFile)
   295  	}
   296  	if c.Name != "" {
   297  		args = append(args, "--name", c.Name)
   298  	}
   299  	if c.Version != "" {
   300  		args = append(args, "--version", c.Version)
   301  	}
   302  	if c.Path != "" {
   303  		args = append(args, "--path", c.Path)
   304  	}
   305  	if c.Lang != "" {
   306  		args = append(args, "--lang", c.Lang)
   307  	}
   308  
   309  	if c.ClientAuth {
   310  		args = append(args, "--clientauth")
   311  	}
   312  	return args
   313  }
   314  
   315  type ChaincodeApproveForMyOrg struct {
   316  	ChannelID           string
   317  	Orderer             string
   318  	Name                string
   319  	Version             string
   320  	PackageID           string
   321  	Sequence            string
   322  	EndorsementPlugin   string
   323  	ValidationPlugin    string
   324  	SignaturePolicy     string
   325  	ChannelConfigPolicy string
   326  	InitRequired        bool
   327  	CollectionsConfig   string
   328  	PeerAddresses       []string
   329  	WaitForEvent        bool
   330  	ClientAuth          bool
   331  }
   332  
   333  func (c ChaincodeApproveForMyOrg) SessionName() string {
   334  	return "peer-lifecycle-chaincode-approveformyorg"
   335  }
   336  
   337  func (c ChaincodeApproveForMyOrg) Args() []string {
   338  	args := []string{
   339  		"lifecycle", "chaincode", "approveformyorg",
   340  		"--channelID", c.ChannelID,
   341  		"--orderer", c.Orderer,
   342  		"--name", c.Name,
   343  		"--version", c.Version,
   344  		"--package-id", c.PackageID,
   345  		"--sequence", c.Sequence,
   346  		"--endorsement-plugin", c.EndorsementPlugin,
   347  		"--validation-plugin", c.ValidationPlugin,
   348  		"--signature-policy", c.SignaturePolicy,
   349  		"--channel-config-policy", c.ChannelConfigPolicy,
   350  	}
   351  
   352  	if c.InitRequired {
   353  		args = append(args, "--init-required")
   354  	}
   355  
   356  	if c.CollectionsConfig != "" {
   357  		args = append(args, "--collections-config", c.CollectionsConfig)
   358  	}
   359  
   360  	if c.ClientAuth {
   361  		args = append(args, "--clientauth")
   362  	}
   363  
   364  	for _, p := range c.PeerAddresses {
   365  		args = append(args, "--peerAddresses", p)
   366  	}
   367  
   368  	return args
   369  }
   370  
   371  type ChaincodeQueryApproved struct {
   372  	ChannelID     string
   373  	Name          string
   374  	Sequence      string
   375  	PeerAddresses []string
   376  	ClientAuth    bool
   377  }
   378  
   379  func (c ChaincodeQueryApproved) SessionName() string {
   380  	return "peer-lifecycle-chaincode-queryapproved"
   381  }
   382  
   383  func (c ChaincodeQueryApproved) Args() []string {
   384  	args := []string{
   385  		"lifecycle", "chaincode", "queryapproved",
   386  		"--channelID", c.ChannelID,
   387  		"--name", c.Name,
   388  		"--sequence", c.Sequence,
   389  		"--output", "json",
   390  	}
   391  	for _, p := range c.PeerAddresses {
   392  		args = append(args, "--peerAddresses", p)
   393  	}
   394  	if c.ClientAuth {
   395  		args = append(args, "--clientauth")
   396  	}
   397  
   398  	return args
   399  }
   400  
   401  type ChaincodeCheckCommitReadiness struct {
   402  	ChannelID           string
   403  	Name                string
   404  	Version             string
   405  	Sequence            string
   406  	EndorsementPlugin   string
   407  	ValidationPlugin    string
   408  	SignaturePolicy     string
   409  	ChannelConfigPolicy string
   410  	InitRequired        bool
   411  	CollectionsConfig   string
   412  	PeerAddresses       []string
   413  	ClientAuth          bool
   414  }
   415  
   416  func (c ChaincodeCheckCommitReadiness) SessionName() string {
   417  	return "peer-lifecycle-chaincode-checkcommitreadiness"
   418  }
   419  
   420  func (c ChaincodeCheckCommitReadiness) Args() []string {
   421  	args := []string{
   422  		"lifecycle", "chaincode", "checkcommitreadiness",
   423  		"--channelID", c.ChannelID,
   424  		"--name", c.Name,
   425  		"--version", c.Version,
   426  		"--sequence", c.Sequence,
   427  		"--endorsement-plugin", c.EndorsementPlugin,
   428  		"--validation-plugin", c.ValidationPlugin,
   429  		"--signature-policy", c.SignaturePolicy,
   430  		"--channel-config-policy", c.ChannelConfigPolicy,
   431  		"--output", "json",
   432  	}
   433  
   434  	if c.InitRequired {
   435  		args = append(args, "--init-required")
   436  	}
   437  
   438  	if c.CollectionsConfig != "" {
   439  		args = append(args, "--collections-config", c.CollectionsConfig)
   440  	}
   441  
   442  	for _, p := range c.PeerAddresses {
   443  		args = append(args, "--peerAddresses", p)
   444  	}
   445  
   446  	if c.ClientAuth {
   447  		args = append(args, "--clientauth")
   448  	}
   449  	return args
   450  }
   451  
   452  type ChaincodeCommit struct {
   453  	ChannelID           string
   454  	Orderer             string
   455  	Name                string
   456  	Version             string
   457  	Sequence            string
   458  	EndorsementPlugin   string
   459  	ValidationPlugin    string
   460  	SignaturePolicy     string
   461  	ChannelConfigPolicy string
   462  	InitRequired        bool
   463  	CollectionsConfig   string
   464  	PeerAddresses       []string
   465  	WaitForEvent        bool
   466  	ClientAuth          bool
   467  }
   468  
   469  func (c ChaincodeCommit) SessionName() string {
   470  	return "peer-lifecycle-chaincode-commit"
   471  }
   472  
   473  func (c ChaincodeCommit) Args() []string {
   474  	args := []string{
   475  		"lifecycle", "chaincode", "commit",
   476  		"--channelID", c.ChannelID,
   477  		"--orderer", c.Orderer,
   478  		"--name", c.Name,
   479  		"--version", c.Version,
   480  		"--sequence", c.Sequence,
   481  		"--endorsement-plugin", c.EndorsementPlugin,
   482  		"--validation-plugin", c.ValidationPlugin,
   483  		"--signature-policy", c.SignaturePolicy,
   484  		"--channel-config-policy", c.ChannelConfigPolicy,
   485  	}
   486  	if c.InitRequired {
   487  		args = append(args, "--init-required")
   488  	}
   489  	for _, p := range c.PeerAddresses {
   490  		args = append(args, "--peerAddresses", p)
   491  	}
   492  	if c.CollectionsConfig != "" {
   493  		args = append(args, "--collections-config", c.CollectionsConfig)
   494  	}
   495  	if c.ClientAuth {
   496  		args = append(args, "--clientauth")
   497  	}
   498  	return args
   499  }
   500  
   501  type ChaincodeInstantiateLegacy struct {
   502  	ChannelID         string
   503  	Orderer           string
   504  	Name              string
   505  	Version           string
   506  	Ctor              string
   507  	Policy            string
   508  	Lang              string
   509  	CollectionsConfig string
   510  	ClientAuth        bool
   511  }
   512  
   513  func (c ChaincodeInstantiateLegacy) SessionName() string {
   514  	return "peer-chaincode-instantiate"
   515  }
   516  
   517  func (c ChaincodeInstantiateLegacy) Args() []string {
   518  	args := []string{
   519  		"chaincode", "instantiate",
   520  		"--channelID", c.ChannelID,
   521  		"--orderer", c.Orderer,
   522  		"--name", c.Name,
   523  		"--version", c.Version,
   524  		"--ctor", c.Ctor,
   525  		"--policy", c.Policy,
   526  	}
   527  	if c.CollectionsConfig != "" {
   528  		args = append(args, "--collections-config", c.CollectionsConfig)
   529  	}
   530  
   531  	if c.Lang != "" {
   532  		args = append(args, "--lang", c.Lang)
   533  	}
   534  
   535  	if c.ClientAuth {
   536  		args = append(args, "--clientauth")
   537  	}
   538  	return args
   539  }
   540  
   541  type ChaincodeQueryInstalled struct {
   542  	ClientAuth bool
   543  }
   544  
   545  func (c ChaincodeQueryInstalled) SessionName() string {
   546  	return "peer-lifecycle-chaincode-queryinstalled"
   547  }
   548  
   549  func (c ChaincodeQueryInstalled) Args() []string {
   550  	args := []string{
   551  		"lifecycle", "chaincode", "queryinstalled",
   552  		"--output", "json",
   553  	}
   554  	if c.ClientAuth {
   555  		args = append(args, "--clientauth")
   556  	}
   557  	return args
   558  }
   559  
   560  type ChaincodeListInstalledLegacy struct {
   561  	ClientAuth bool
   562  }
   563  
   564  func (c ChaincodeListInstalledLegacy) SessionName() string {
   565  	return "peer-chaincode-list-installed"
   566  }
   567  
   568  func (c ChaincodeListInstalledLegacy) Args() []string {
   569  	args := []string{
   570  		"chaincode", "list", "--installed",
   571  	}
   572  	if c.ClientAuth {
   573  		args = append(args, "--clientauth")
   574  	}
   575  	return args
   576  }
   577  
   578  type ChaincodeListCommitted struct {
   579  	ChannelID  string
   580  	Name       string
   581  	ClientAuth bool
   582  }
   583  
   584  func (c ChaincodeListCommitted) SessionName() string {
   585  	return "peer-lifecycle-chaincode-querycommitted"
   586  }
   587  
   588  func (c ChaincodeListCommitted) Args() []string {
   589  	args := []string{
   590  		"lifecycle", "chaincode", "querycommitted",
   591  		"--channelID", c.ChannelID,
   592  		"--name", c.Name,
   593  		"--output", "json",
   594  	}
   595  	if c.ClientAuth {
   596  		args = append(args, "--clientauth")
   597  	}
   598  	return args
   599  }
   600  
   601  type ChaincodeListInstantiatedLegacy struct {
   602  	ChannelID  string
   603  	ClientAuth bool
   604  }
   605  
   606  func (c ChaincodeListInstantiatedLegacy) SessionName() string {
   607  	return "peer-chaincode-list-instantiated"
   608  }
   609  
   610  func (c ChaincodeListInstantiatedLegacy) Args() []string {
   611  	args := []string{
   612  		"chaincode", "list", "--instantiated",
   613  		"--channelID", c.ChannelID,
   614  	}
   615  	if c.ClientAuth {
   616  		args = append(args, "--clientauth")
   617  	}
   618  	return args
   619  }
   620  
   621  type ChaincodeQuery struct {
   622  	ChannelID  string
   623  	Name       string
   624  	Ctor       string
   625  	ClientAuth bool
   626  }
   627  
   628  func (c ChaincodeQuery) SessionName() string {
   629  	return "peer-chaincode-query"
   630  }
   631  
   632  func (c ChaincodeQuery) Args() []string {
   633  	args := []string{
   634  		"chaincode", "query",
   635  		"--channelID", c.ChannelID,
   636  		"--name", c.Name,
   637  		"--ctor", c.Ctor,
   638  	}
   639  	if c.ClientAuth {
   640  		args = append(args, "--clientauth")
   641  	}
   642  	return args
   643  }
   644  
   645  type ChaincodeInvoke struct {
   646  	ChannelID     string
   647  	Orderer       string
   648  	Name          string
   649  	Ctor          string
   650  	Transient     string
   651  	PeerAddresses []string
   652  	WaitForEvent  bool
   653  	IsInit        bool
   654  	ClientAuth    bool
   655  }
   656  
   657  func (c ChaincodeInvoke) SessionName() string {
   658  	return "peer-chaincode-invoke"
   659  }
   660  
   661  func (c ChaincodeInvoke) Args() []string {
   662  	args := []string{
   663  		"chaincode", "invoke",
   664  		"--channelID", c.ChannelID,
   665  		"--orderer", c.Orderer,
   666  		"--name", c.Name,
   667  		"--ctor", c.Ctor,
   668  	}
   669  
   670  	if c.Transient != "" {
   671  		args = append(args, "--transient", c.Transient)
   672  	}
   673  	for _, p := range c.PeerAddresses {
   674  		args = append(args, "--peerAddresses", p)
   675  	}
   676  	if c.WaitForEvent {
   677  		args = append(args, "--waitForEvent")
   678  	}
   679  	if c.IsInit {
   680  		args = append(args, "--isInit")
   681  	}
   682  	if c.ClientAuth {
   683  		args = append(args, "--clientauth")
   684  	}
   685  	return args
   686  }
   687  
   688  type ChaincodeUpgradeLegacy struct {
   689  	Name              string
   690  	Version           string
   691  	Path              string // optional
   692  	ChannelID         string
   693  	Orderer           string
   694  	Ctor              string
   695  	Policy            string
   696  	CollectionsConfig string // optional
   697  	ClientAuth        bool
   698  }
   699  
   700  func (c ChaincodeUpgradeLegacy) SessionName() string {
   701  	return "peer-chaincode-upgrade"
   702  }
   703  
   704  func (c ChaincodeUpgradeLegacy) Args() []string {
   705  	args := []string{
   706  		"chaincode", "upgrade",
   707  		"--name", c.Name,
   708  		"--version", c.Version,
   709  		"--channelID", c.ChannelID,
   710  		"--orderer", c.Orderer,
   711  		"--ctor", c.Ctor,
   712  		"--policy", c.Policy,
   713  	}
   714  	if c.Path != "" {
   715  		args = append(args, "--path", c.Path)
   716  	}
   717  	if c.CollectionsConfig != "" {
   718  		args = append(args, "--collections-config", c.CollectionsConfig)
   719  	}
   720  	if c.ClientAuth {
   721  		args = append(args, "--clientauth")
   722  	}
   723  	return args
   724  }
   725  
   726  type SignConfigTx struct {
   727  	File       string
   728  	ClientAuth bool
   729  }
   730  
   731  func (s SignConfigTx) SessionName() string {
   732  	return "peer-channel-signconfigtx"
   733  }
   734  
   735  func (s SignConfigTx) Args() []string {
   736  	args := []string{
   737  		"channel", "signconfigtx",
   738  		"--file", s.File,
   739  	}
   740  	if s.ClientAuth {
   741  		args = append(args, "--clientauth")
   742  	}
   743  	return args
   744  }
   745  
   746  type ChannelUpdate struct {
   747  	ChannelID             string
   748  	Orderer               string
   749  	File                  string
   750  	ClientAuth            bool
   751  	TLSHandshakeTimeShift time.Duration
   752  }
   753  
   754  func (c ChannelUpdate) SessionName() string {
   755  	return "peer-channel-update"
   756  }
   757  
   758  func (c ChannelUpdate) Args() []string {
   759  	args := []string{
   760  		"channel", "update",
   761  		"--channelID", c.ChannelID,
   762  		"--orderer", c.Orderer,
   763  		"--file", c.File,
   764  		"--tlsHandshakeTimeShift", c.TLSHandshakeTimeShift.String(),
   765  	}
   766  	if c.ClientAuth {
   767  		args = append(args, "--clientauth")
   768  	}
   769  	return args
   770  }
   771  
   772  type ChannelInfo struct {
   773  	ChannelID  string
   774  	ClientAuth bool
   775  }
   776  
   777  func (c ChannelInfo) SessionName() string {
   778  	return "peer-channel-info"
   779  }
   780  
   781  func (c ChannelInfo) Args() []string {
   782  	args := []string{
   783  		"channel", "getinfo",
   784  		"-c", c.ChannelID,
   785  	}
   786  	if c.ClientAuth {
   787  		args = append(args, "--clientauth")
   788  	}
   789  	return args
   790  }