forked from hyperledger/fabric-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blockproducer.go
executable file
·41 lines (33 loc) · 1.04 KB
/
blockproducer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package mocks
import (
"sync/atomic"
cb "github.com/hyperledger/fabric-protos-go/common"
pb "github.com/hyperledger/fabric-protos-go/peer"
)
// BlockProducer is a block BlockProducer that ensures the block
// number is set sequencially
type BlockProducer struct {
blockNum uint64
}
// NewBlockProducer returns a new block producer
func NewBlockProducer() *BlockProducer {
return &BlockProducer{}
}
// NewBlock returns a new block
func (p *BlockProducer) NewBlock(channelID string, transactions ...*TxInfo) *cb.Block {
block := NewBlock(channelID, transactions...)
block.Header.Number = p.blockNum
atomic.AddUint64(&p.blockNum, 1)
return block
}
// NewFilteredBlock returns a new filtered block
func (p *BlockProducer) NewFilteredBlock(channelID string, filteredTx ...*pb.FilteredTransaction) *pb.FilteredBlock {
block := NewFilteredBlock(channelID, filteredTx...)
block.Number = p.blockNum
atomic.AddUint64(&p.blockNum, 1)
return block
}