-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
110 lines (105 loc) · 2.22 KB
/
options.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Package node
//
// @author: xwc1125
package node
import (
"fmt"
"github.com/chain5j/chain5j-pkg/codec"
"github.com/chain5j/chain5j-protocol/protocol"
)
type option func(opt *node) error
func apply(f *node, opts ...option) error {
for _, opt := range opts {
if opt == nil {
continue
}
if err := opt(f); err != nil {
return fmt.Errorf("option apply err:%v", err)
}
}
return nil
}
func WithCodec(codec codec.Codec) option {
return func(opt *node) error {
opt.codec = codec
return nil
}
}
func WithConsensus(consensus protocol.Consensus) option {
return func(opt *node) error {
opt.consensus = consensus
return nil
}
}
func WithPacker(packer protocol.Packer) option {
return func(opt *node) error {
opt.packer = packer
return nil
}
}
func WithDatabase(database protocol.Database) option {
return func(opt *node) error {
opt.database = database
return nil
}
}
func WithBlockReader(blockReader protocol.BlockReader) option {
return func(opt *node) error {
opt.blockReader = blockReader
return nil
}
}
func WithBlockWriter(blockWriter protocol.BlockWriter) option {
return func(opt *node) error {
opt.blockWriter = blockWriter
return nil
}
}
func WithBlockReadWriter(blockReadWriter protocol.BlockReadWriter) option {
return func(opt *node) error {
opt.blockReadWriter = blockReadWriter
return nil
}
}
func WithNodeKey(nodeKey protocol.NodeKey) option {
return func(opt *node) error {
opt.nodeKey = nodeKey
return nil
}
}
func WithApps(apps protocol.Apps) option {
return func(opt *node) error {
opt.apps = apps
return nil
}
}
func WithP2PService(p2pService protocol.P2PService) option {
return func(opt *node) error {
opt.p2pService = p2pService
return nil
}
}
func WithBroadcaster(broadcaster protocol.Broadcaster) option {
return func(opt *node) error {
opt.broadcaster = broadcaster
return nil
}
}
func WithTxPools(txPools protocol.TxPools) option {
return func(opt *node) error {
opt.txPools = txPools
return nil
}
}
func WithSyncer(syncer protocol.Syncer) option {
return func(opt *node) error {
opt.syncer = syncer
return nil
}
}
func WithPermission(permission protocol.Permission) option {
return func(opt *node) error {
opt.permission = permission
return nil
}
}