github.com/inklabsfoundation/inkchain@v0.17.1-0.20181025012015-c3cef8062f19/core/scc/importsysccs.go (about)

     1  /*
     2  Copyright IBM Corp. 2016, 2017 All Rights Reserved.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8  		 http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package scc
    18  
    19  import (
    20  	//import system chain codes here
    21  	"github.com/inklabsfoundation/inkchain/core/scc/ascc"
    22  	"github.com/inklabsfoundation/inkchain/core/scc/cscc"
    23  	"github.com/inklabsfoundation/inkchain/core/scc/escc"
    24  	"github.com/inklabsfoundation/inkchain/core/scc/lscc"
    25  	"github.com/inklabsfoundation/inkchain/core/scc/qscc"
    26  	"github.com/inklabsfoundation/inkchain/core/scc/samplesyscc"
    27  	"github.com/inklabsfoundation/inkchain/core/scc/vscc"
    28  )
    29  
    30  //see systemchaincode_test.go for an example using "sample_syscc"
    31  var systemChaincodes = []*SystemChaincode{
    32  	{
    33  		Enabled:           true,
    34  		Name:              "cscc",
    35  		Path:              "github.com/inklabsfoundation/inkchain/core/scc/cscc",
    36  		InitArgs:          [][]byte{[]byte("")},
    37  		Chaincode:         &cscc.PeerConfiger{},
    38  		InvokableExternal: true, // cscc is invoked to join a channel
    39  	},
    40  	{
    41  		Enabled:           true,
    42  		Name:              "lscc",
    43  		Path:              "github.com/inklabsfoundation/inkchain/core/scc/lscc",
    44  		InitArgs:          [][]byte{[]byte("")},
    45  		Chaincode:         &lscc.LifeCycleSysCC{},
    46  		InvokableExternal: true, // lscc is invoked to deploy new chaincodes
    47  		InvokableCC2CC:    true, // lscc can be invoked by other chaincodes
    48  	},
    49  	{
    50  		Enabled:   true,
    51  		Name:      "escc",
    52  		Path:      "github.com/inklabsfoundation/inkchain/core/scc/escc",
    53  		InitArgs:  [][]byte{[]byte("")},
    54  		Chaincode: &escc.EndorserOneValidSignature{},
    55  	},
    56  	{
    57  		Enabled:   true,
    58  		Name:      "vscc",
    59  		Path:      "github.com/inklabsfoundation/inkchain/core/scc/vscc",
    60  		InitArgs:  [][]byte{[]byte("")},
    61  		Chaincode: &vscc.ValidatorOneValidSignature{},
    62  	},
    63  	{
    64  		Enabled:           true,
    65  		Name:              "qscc",
    66  		Path:              "github.com/inklabsfoundation/inkchain/core/scc/qscc",
    67  		InitArgs:          [][]byte{[]byte("")},
    68  		Chaincode:         &qscc.LedgerQuerier{},
    69  		InvokableExternal: true, // qscc can be invoked to retrieve blocks
    70  		InvokableCC2CC:    true, // qscc can be invoked to retrieve blocks also by a cc
    71  	},
    72  	{
    73  		Enabled:           true,
    74  		Name:              "ascc",
    75  		Path:              "github.com/inklabsfoundation/inkchain/core/scc/ascc",
    76  		InitArgs:          [][]byte{[]byte("")},
    77  		Chaincode:         &ascc.AssetSysCC{},
    78  		InvokableExternal: true, // ascc is invoked for token management
    79  	},
    80  	{
    81  		Enabled:           true,
    82  		Name:              "samplesyscc",
    83  		Path:              "github.com/inklabsfoundation/inkchain/core/scc/samplesyscc",
    84  		InitArgs:          [][]byte{[]byte("")},
    85  		Chaincode:         &samplesyscc.SampleSysCC{},
    86  		InvokableExternal: true,
    87  		InvokableCC2CC:    true,
    88  	},
    89  }
    90  
    91  //RegisterSysCCs is the hook for system chaincodes where system chaincodes are registered with the inkchain
    92  //note the chaincode must still be deployed and launched like a user chaincode will be
    93  func RegisterSysCCs() {
    94  	for _, sysCC := range systemChaincodes {
    95  		RegisterSysCC(sysCC)
    96  	}
    97  }
    98  
    99  //DeploySysCCs is the hook for system chaincodes where system chaincodes are registered with the inkchain
   100  //note the chaincode must still be deployed and launched like a user chaincode will be
   101  func DeploySysCCs(chainID string) {
   102  	for _, sysCC := range systemChaincodes {
   103  		deploySysCC(chainID, sysCC)
   104  	}
   105  }
   106  
   107  //DeDeploySysCCs is used in unit tests to stop and remove the system chaincodes before
   108  //restarting them in the same process. This allows clean start of the system
   109  //in the same process
   110  func DeDeploySysCCs(chainID string) {
   111  	for _, sysCC := range systemChaincodes {
   112  		DeDeploySysCC(chainID, sysCC)
   113  	}
   114  }
   115  
   116  //IsSysCC returns true if the name matches a system chaincode's
   117  //system chaincode names are system, chain wide
   118  func IsSysCC(name string) bool {
   119  	for _, sysCC := range systemChaincodes {
   120  		if sysCC.Name == name {
   121  			return true
   122  		}
   123  	}
   124  	return false
   125  }
   126  
   127  // IsSysCCAndNotInvokableExternal returns true if the chaincode
   128  // is a system chaincode and *CANNOT* be invoked through
   129  // a proposal to this peer
   130  func IsSysCCAndNotInvokableExternal(name string) bool {
   131  	for _, sysCC := range systemChaincodes {
   132  		if sysCC.Name == name {
   133  			return !sysCC.InvokableExternal
   134  		}
   135  	}
   136  	return false
   137  }
   138  
   139  // IsSysCCAndNotInvokableCC2CC returns true if the chaincode
   140  // is a system chaincode and *CANNOT* be invoked through
   141  // a cc2cc invocation
   142  func IsSysCCAndNotInvokableCC2CC(name string) bool {
   143  	for _, sysCC := range systemChaincodes {
   144  		if sysCC.Name == name {
   145  			return !sysCC.InvokableCC2CC
   146  		}
   147  	}
   148  	return false
   149  }
   150  
   151  // MockRegisterSysCCs is used only for testing
   152  // This is needed to break import cycle
   153  func MockRegisterSysCCs(mockSysCCs []*SystemChaincode) []*SystemChaincode {
   154  	orig := systemChaincodes
   155  	systemChaincodes = mockSysCCs
   156  	RegisterSysCCs()
   157  	return orig
   158  }
   159  
   160  // MockResetSysCCs restore orig system ccs - is used only for testing
   161  func MockResetSysCCs(mockSysCCs []*SystemChaincode) {
   162  	systemChaincodes = mockSysCCs
   163  }