github.com/yacovm/fabric@v2.0.0-alpha.0.20191128145320-c5d4087dc723+incompatible/common/capabilities/application.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package capabilities
     8  
     9  import (
    10  	cb "github.com/hyperledger/fabric-protos-go/common"
    11  )
    12  
    13  const (
    14  	applicationTypeName = "Application"
    15  
    16  	// ApplicationV1_1 is the capabilties string for standard new non-backwards compatible fabric v1.1 application capabilities.
    17  	ApplicationV1_1 = "V1_1"
    18  
    19  	// ApplicationV1_2 is the capabilties string for standard new non-backwards compatible fabric v1.2 application capabilities.
    20  	ApplicationV1_2 = "V1_2"
    21  
    22  	// ApplicationV1_3 is the capabilties string for standard new non-backwards compatible fabric v1.3 application capabilities.
    23  	ApplicationV1_3 = "V1_3"
    24  
    25  	// ApplicationV1_4_2 is the capabilties string for standard new non-backwards compatible fabric v1.4.2 application capabilities.
    26  	ApplicationV1_4_2 = "V1_4_2"
    27  
    28  	// ApplicationV2_0 is the capabilties string for standard new non-backwards compatible fabric v2.0 application capabilities.
    29  	ApplicationV2_0 = "V2_0"
    30  
    31  	// ApplicationPvtDataExperimental is the capabilties string for private data using the experimental feature of collections/sideDB.
    32  	ApplicationPvtDataExperimental = "V1_1_PVTDATA_EXPERIMENTAL"
    33  
    34  	// ApplicationResourcesTreeExperimental is the capabilties string for private data using the experimental feature of collections/sideDB.
    35  	ApplicationResourcesTreeExperimental = "V1_1_RESOURCETREE_EXPERIMENTAL"
    36  )
    37  
    38  // ApplicationProvider provides capabilities information for application level config.
    39  type ApplicationProvider struct {
    40  	*registry
    41  	v11                    bool
    42  	v12                    bool
    43  	v13                    bool
    44  	v142                   bool
    45  	v20                    bool
    46  	v11PvtDataExperimental bool
    47  }
    48  
    49  // NewApplicationProvider creates a application capabilities provider.
    50  func NewApplicationProvider(capabilities map[string]*cb.Capability) *ApplicationProvider {
    51  	ap := &ApplicationProvider{}
    52  	ap.registry = newRegistry(ap, capabilities)
    53  	_, ap.v11 = capabilities[ApplicationV1_1]
    54  	_, ap.v12 = capabilities[ApplicationV1_2]
    55  	_, ap.v13 = capabilities[ApplicationV1_3]
    56  	_, ap.v142 = capabilities[ApplicationV1_4_2]
    57  	_, ap.v20 = capabilities[ApplicationV2_0]
    58  	_, ap.v11PvtDataExperimental = capabilities[ApplicationPvtDataExperimental]
    59  	return ap
    60  }
    61  
    62  // Type returns a descriptive string for logging purposes.
    63  func (ap *ApplicationProvider) Type() string {
    64  	return applicationTypeName
    65  }
    66  
    67  // ACLs returns whether ACLs may be specified in the channel application config
    68  func (ap *ApplicationProvider) ACLs() bool {
    69  	return ap.v12 || ap.v13 || ap.v142 || ap.v20
    70  }
    71  
    72  // ForbidDuplicateTXIdInBlock specifies whether two transactions with the same TXId are permitted
    73  // in the same block or whether we mark the second one as TxValidationCode_DUPLICATE_TXID
    74  func (ap *ApplicationProvider) ForbidDuplicateTXIdInBlock() bool {
    75  	return ap.v11 || ap.v12 || ap.v13 || ap.v142 || ap.v20
    76  }
    77  
    78  // PrivateChannelData returns true if support for private channel data (a.k.a. collections) is enabled.
    79  // In v1.1, the private channel data is experimental and has to be enabled explicitly.
    80  // In v1.2, the private channel data is enabled by default.
    81  func (ap *ApplicationProvider) PrivateChannelData() bool {
    82  	return ap.v11PvtDataExperimental || ap.v12 || ap.v13 || ap.v142 || ap.v20
    83  }
    84  
    85  // CollectionUpgrade returns true if this channel is configured to allow updates to
    86  // existing collection or add new collections through chaincode upgrade (as introduced in v1.2)
    87  func (ap ApplicationProvider) CollectionUpgrade() bool {
    88  	return ap.v12 || ap.v13 || ap.v142 || ap.v20
    89  }
    90  
    91  // V1_1Validation returns true is this channel is configured to perform stricter validation
    92  // of transactions (as introduced in v1.1).
    93  func (ap *ApplicationProvider) V1_1Validation() bool {
    94  	return ap.v11 || ap.v12 || ap.v13 || ap.v142 || ap.v20
    95  }
    96  
    97  // V1_2Validation returns true if this channel is configured to perform stricter validation
    98  // of transactions (as introduced in v1.2).
    99  func (ap *ApplicationProvider) V1_2Validation() bool {
   100  	return ap.v12 || ap.v13 || ap.v142 || ap.v20
   101  }
   102  
   103  // V1_3Validation returns true if this channel is configured to perform stricter validation
   104  // of transactions (as introduced in v1.3).
   105  func (ap *ApplicationProvider) V1_3Validation() bool {
   106  	return ap.v13 || ap.v142 || ap.v20
   107  }
   108  
   109  // V2_0Validation returns true if this channel supports transaction validation
   110  // as introduced in v2.0. This includes:
   111  //  - new chaincode lifecycle
   112  //  - implicit per-org collections
   113  func (ap *ApplicationProvider) V2_0Validation() bool {
   114  	return ap.v20
   115  }
   116  
   117  // LifecycleV20 indicates whether the peer should use the deprecated and problematic
   118  // v1.x lifecycle, or whether it should use the newer per channel approve/commit definitions
   119  // process introduced in v2.0.  Note, this should only be used on the endorsing side
   120  // of peer processing, so that we may safely remove all checks against it in v2.1.
   121  func (ap *ApplicationProvider) LifecycleV20() bool {
   122  	return ap.v20
   123  }
   124  
   125  // MetadataLifecycle always returns false
   126  func (ap *ApplicationProvider) MetadataLifecycle() bool {
   127  	return false
   128  }
   129  
   130  // KeyLevelEndorsement returns true if this channel supports endorsement
   131  // policies expressible at a ledger key granularity, as described in FAB-8812
   132  func (ap *ApplicationProvider) KeyLevelEndorsement() bool {
   133  	return ap.v13 || ap.v142 || ap.v20
   134  }
   135  
   136  // StorePvtDataOfInvalidTx returns true if the peer needs to store
   137  // the pvtData of invalid transactions.
   138  func (ap *ApplicationProvider) StorePvtDataOfInvalidTx() bool {
   139  	return ap.v142 || ap.v20
   140  }
   141  
   142  // HasCapability returns true if the capability is supported by this binary.
   143  func (ap *ApplicationProvider) HasCapability(capability string) bool {
   144  	switch capability {
   145  	// Add new capability names here
   146  	case ApplicationV1_1:
   147  		return true
   148  	case ApplicationV1_2:
   149  		return true
   150  	case ApplicationV1_3:
   151  		return true
   152  	case ApplicationV1_4_2:
   153  		return true
   154  	case ApplicationV2_0:
   155  		return true
   156  	case ApplicationPvtDataExperimental:
   157  		return true
   158  	case ApplicationResourcesTreeExperimental:
   159  		return true
   160  	default:
   161  		return false
   162  	}
   163  }