代码拉取完成,页面将自动刷新
/*
Copyright IBM Corp. 2016 All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package multichain
import (
"github.com/hyperledger/fabric/common/config"
mockconfig "github.com/hyperledger/fabric/common/mocks/config"
"github.com/hyperledger/fabric/orderer/common/blockcutter"
"github.com/hyperledger/fabric/orderer/common/filter"
mockblockcutter "github.com/hyperledger/fabric/orderer/mocks/blockcutter"
cb "github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/utils"
"github.com/op/go-logging"
)
var logger = logging.MustGetLogger("orderer/mocks/multichain")
// ConsenterSupport is used to mock the multichain.ConsenterSupport interface
// Whenever a block is written, it writes to the Batches channel to allow for synchronization
type ConsenterSupport struct {
// SharedConfigVal is the value returned by SharedConfig()
SharedConfigVal *mockconfig.Orderer
// BlockCutterVal is the value returned by BlockCutter()
BlockCutterVal *mockblockcutter.Receiver
// Blocks is the channel where WriteBlock writes the most recently created block
Blocks chan *cb.Block
// ChainIDVal is the value returned by ChainID()
ChainIDVal string
// HeightVal is the value returned by Height()
HeightVal uint64
// NextBlockVal stores the block created by the most recent CreateNextBlock() call
NextBlockVal *cb.Block
}
// BlockCutter returns BlockCutterVal
func (mcs *ConsenterSupport) BlockCutter() blockcutter.Receiver {
return mcs.BlockCutterVal
}
// SharedConfig returns SharedConfigVal
func (mcs *ConsenterSupport) SharedConfig() config.Orderer {
return mcs.SharedConfigVal
}
// CreateNextBlock creates a simple block structure with the given data
func (mcs *ConsenterSupport) CreateNextBlock(data []*cb.Envelope) *cb.Block {
block := cb.NewBlock(0, nil)
mtxs := make([][]byte, len(data))
for i := range data {
mtxs[i] = utils.MarshalOrPanic(data[i])
}
block.Data = &cb.BlockData{Data: mtxs}
mcs.NextBlockVal = block
return block
}
// WriteBlock writes data to the Blocks channel
// Note that _committers is ignored by this mock implementation
func (mcs *ConsenterSupport) WriteBlock(block *cb.Block, _committers []filter.Committer, encodedMetadataValue []byte) *cb.Block {
if encodedMetadataValue != nil {
block.Metadata.Metadata[cb.BlockMetadataIndex_ORDERER] = utils.MarshalOrPanic(&cb.Metadata{Value: encodedMetadataValue})
}
mcs.HeightVal++
mcs.Blocks <- block
return block
}
// ChainID returns the chain ID this specific consenter instance is associated with
func (mcs *ConsenterSupport) ChainID() string {
return mcs.ChainIDVal
}
// Height returns the number of blocks of the chain this specific consenter instance is associated with
func (mcs *ConsenterSupport) Height() uint64 {
return mcs.HeightVal
}
// Sign returns the bytes passed in
func (mcs *ConsenterSupport) Sign(message []byte) ([]byte, error) {
return message, nil
}
// NewSignatureHeader returns an empty signature header
func (mcs *ConsenterSupport) NewSignatureHeader() (*cb.SignatureHeader, error) {
return &cb.SignatureHeader{}, nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。