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