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