forked from hyperledger/fabric-sdk-go
/
mockevents.go
executable file
·56 lines (48 loc) · 1.73 KB
/
mockevents.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package mocks
import (
"fmt"
"github.com/hyperledger/fabric-sdk-go/pkg/fab/events/deliverclient/connection"
servicemocks "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/service/mocks"
cb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common"
pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer"
)
// NewBlockEvent returns a new mock block event initialized with the given block
func NewBlockEvent(block *cb.Block, sourceURL string) *connection.Event {
return connection.NewEvent(
&pb.DeliverResponse{
Type: &pb.DeliverResponse_Block{
Block: block,
},
}, sourceURL,
)
}
// NewFilteredBlockEvent returns a new mock filtered block event initialized with the given filtered block
func NewFilteredBlockEvent(fblock *pb.FilteredBlock, sourceURL string) *connection.Event {
return connection.NewEvent(
&pb.DeliverResponse{
Type: &pb.DeliverResponse_FilteredBlock{
FilteredBlock: fblock,
},
}, sourceURL,
)
}
// BlockEventFactory creates block events
var BlockEventFactory = func(block servicemocks.Block, sourceURL string) servicemocks.BlockEvent {
b, ok := block.(*servicemocks.BlockWrapper)
if !ok {
panic(fmt.Sprintf("Invalid block type: %T", block))
}
return NewBlockEvent(b.Block(), sourceURL)
}
// FilteredBlockEventFactory creates filtered block events
var FilteredBlockEventFactory = func(block servicemocks.Block, sourceURL string) servicemocks.BlockEvent {
b, ok := block.(*servicemocks.FilteredBlockWrapper)
if !ok {
panic(fmt.Sprintf("Invalid block type: %T", block))
}
return NewFilteredBlockEvent(b.Block(), sourceURL)
}