-
Notifications
You must be signed in to change notification settings - Fork 246
/
node.go
88 lines (66 loc) · 1.83 KB
/
node.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
package gethbridge
import (
"errors"
"go.uber.org/zap"
"github.com/status-im/status-go/waku"
"github.com/status-im/status-go/wakuv2"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/p2p/enode"
gethens "github.com/status-im/status-go/eth-node/bridge/geth/ens"
"github.com/status-im/status-go/eth-node/types"
enstypes "github.com/status-im/status-go/eth-node/types/ens"
)
type gethNodeWrapper struct {
stack *node.Node
waku1 *waku.Waku
waku2 *wakuv2.Waku
}
func NewNodeBridge(stack *node.Node, waku1 *waku.Waku, waku2 *wakuv2.Waku) types.Node {
return &gethNodeWrapper{stack: stack, waku1: waku1, waku2: waku2}
}
func (w *gethNodeWrapper) Poll() {
// noop
}
func (w *gethNodeWrapper) NewENSVerifier(logger *zap.Logger) enstypes.ENSVerifier {
return gethens.NewVerifier(logger)
}
func (w *gethNodeWrapper) SetWaku1(waku *waku.Waku) {
w.waku1 = waku
}
func (w *gethNodeWrapper) SetWaku2(waku *wakuv2.Waku) {
w.waku2 = waku
}
func (w *gethNodeWrapper) GetWaku(ctx interface{}) (types.Waku, error) {
if w.waku1 == nil {
return nil, errors.New("waku service is not available")
}
return NewGethWakuWrapper(w.waku1), nil
}
func (w *gethNodeWrapper) GetWakuV2(ctx interface{}) (types.Waku, error) {
if w.waku2 == nil {
return nil, errors.New("waku service is not available")
}
return NewGethWakuV2Wrapper(w.waku2), nil
}
func (w *gethNodeWrapper) AddPeer(url string) error {
parsedNode, err := enode.ParseV4(url)
if err != nil {
return err
}
w.stack.Server().AddPeer(parsedNode)
return nil
}
func (w *gethNodeWrapper) RemovePeer(url string) error {
parsedNode, err := enode.ParseV4(url)
if err != nil {
return err
}
w.stack.Server().RemovePeer(parsedNode)
return nil
}
func (w *gethNodeWrapper) PeersCount() int {
if w.stack.Server() == nil {
return 0
}
return len(w.stack.Server().Peers())
}