github.com/yimialmonte/fabric@v2.1.1+incompatible/core/peer/configtx_processor.go (about) 1 /* 2 Copyright IBM Corp. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package peer 8 9 import ( 10 "fmt" 11 12 "github.com/golang/protobuf/proto" 13 "github.com/hyperledger/fabric-protos-go/common" 14 "github.com/hyperledger/fabric/core/ledger" 15 "github.com/hyperledger/fabric/protoutil" 16 ) 17 18 const ( 19 channelConfigKey = "CHANNEL_CONFIG_ENV_BYTES" 20 peerNamespace = "" 21 ) 22 23 // ConfigTxProcessor implements the interface 'github.com/hyperledger/fabric/core/ledger/customtx/Processor' 24 type ConfigTxProcessor struct{} 25 26 // GenerateSimulationResults implements function in the interface 'github.com/hyperledger/fabric/core/ledger/customtx/Processor' 27 // This implementation processes CONFIG transactions which simply stores the config-envelope-bytes 28 func (tp *ConfigTxProcessor) GenerateSimulationResults(txEnv *common.Envelope, simulator ledger.TxSimulator, initializingLedger bool) error { 29 payload := protoutil.UnmarshalPayloadOrPanic(txEnv.Payload) 30 channelHdr := protoutil.UnmarshalChannelHeaderOrPanic(payload.Header.ChannelHeader) 31 txType := common.HeaderType(channelHdr.GetType()) 32 33 switch txType { 34 case common.HeaderType_CONFIG: 35 peerLogger.Debugf("Processing CONFIG") 36 if payload.Data == nil { 37 return fmt.Errorf("channel config found nil") 38 } 39 return simulator.SetState(peerNamespace, channelConfigKey, payload.Data) 40 default: 41 return fmt.Errorf("tx type [%s] is not expected", txType) 42 } 43 } 44 45 func retrieveChannelConfig(queryExecuter ledger.QueryExecutor) (*common.Config, error) { 46 configBytes, err := queryExecuter.GetState(peerNamespace, channelConfigKey) 47 if err != nil { 48 return nil, err 49 } 50 if configBytes == nil { 51 return nil, nil 52 } 53 configEnvelope := &common.ConfigEnvelope{} 54 if err := proto.Unmarshal(configBytes, configEnvelope); err != nil { 55 return nil, err 56 } 57 return configEnvelope.Config, nil 58 }