github.com/adnan-c/fabric_e2e_couchdb@v0.6.1-preview.0.20170228180935-21ce6b23cf91/orderer/mocks/multichain/multichain.go (about) 1 /* 2 Copyright IBM Corp. 2016 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 multichain 18 19 import ( 20 configvaluesapi "github.com/hyperledger/fabric/common/configvalues" 21 mockconfigtxorderer "github.com/hyperledger/fabric/common/mocks/configvalues/channel/orderer" 22 "github.com/hyperledger/fabric/orderer/common/blockcutter" 23 "github.com/hyperledger/fabric/orderer/common/filter" 24 mockblockcutter "github.com/hyperledger/fabric/orderer/mocks/blockcutter" 25 cb "github.com/hyperledger/fabric/protos/common" 26 "github.com/hyperledger/fabric/protos/utils" 27 28 "github.com/op/go-logging" 29 ) 30 31 var logger = logging.MustGetLogger("orderer/mocks/multichain") 32 33 // ConsenterSupport is used to mock the multichain.ConsenterSupport interface 34 // Whenever a block is written, it writes to the Batches channel to allow for synchronization 35 type ConsenterSupport struct { 36 // SharedConfigVal is the value returned by SharedConfig() 37 SharedConfigVal *mockconfigtxorderer.SharedConfig 38 39 // BlockCutterVal is the value returned by BlockCutter() 40 BlockCutterVal *mockblockcutter.Receiver 41 42 // Batches is the channel which WriteBlock writes data to 43 Batches chan []*cb.Envelope 44 45 // ChainIDVal is the value returned by ChainID() 46 ChainIDVal string 47 48 // NextBlockVal stores the block created by the most recent CreateNextBlock() call 49 NextBlockVal *cb.Block 50 51 // WriteBlockVal stores the block created by the most recent WriteBlock() call 52 WriteBlockVal *cb.Block 53 } 54 55 // BlockCutter returns BlockCutterVal 56 func (mcs *ConsenterSupport) BlockCutter() blockcutter.Receiver { 57 return mcs.BlockCutterVal 58 } 59 60 // SharedConfig returns SharedConfigVal 61 func (mcs *ConsenterSupport) SharedConfig() configvaluesapi.Orderer { 62 return mcs.SharedConfigVal 63 } 64 65 // CreateNextBlock creates a simple block structure with the given data 66 func (mcs *ConsenterSupport) CreateNextBlock(data []*cb.Envelope) *cb.Block { 67 block := cb.NewBlock(0, nil) 68 mtxs := make([][]byte, len(data)) 69 for i := range data { 70 mtxs[i] = utils.MarshalOrPanic(data[i]) 71 } 72 block.Data = &cb.BlockData{Data: mtxs} 73 mcs.NextBlockVal = block 74 return block 75 } 76 77 // WriteBlock writes data to the Batches channel 78 // Note that _committers is ignored by this mock implementation 79 func (mcs *ConsenterSupport) WriteBlock(block *cb.Block, _committers []filter.Committer, encodedMetadataValue []byte) *cb.Block { 80 logger.Debugf("mockWriter: attempting to write batch") 81 umtxs := make([]*cb.Envelope, len(block.Data.Data)) 82 for i := range block.Data.Data { 83 umtxs[i] = utils.UnmarshalEnvelopeOrPanic(block.Data.Data[i]) 84 } 85 mcs.Batches <- umtxs 86 if encodedMetadataValue != nil { 87 block.Metadata.Metadata[cb.BlockMetadataIndex_ORDERER] = utils.MarshalOrPanic(&cb.Metadata{Value: encodedMetadataValue}) 88 } 89 mcs.WriteBlockVal = block 90 return block 91 } 92 93 // ChainID returns the chain ID this specific consenter instance is associated with 94 func (mcs *ConsenterSupport) ChainID() string { 95 return mcs.ChainIDVal 96 } 97 98 // Sign returns the bytes passed in 99 func (mcs *ConsenterSupport) Sign(message []byte) ([]byte, error) { 100 return message, nil 101 } 102 103 // NewSignatureHeader returns an empty signature header 104 func (mcs *ConsenterSupport) NewSignatureHeader() (*cb.SignatureHeader, error) { 105 return &cb.SignatureHeader{}, nil 106 }