-
Notifications
You must be signed in to change notification settings - Fork 1
/
relay.go
44 lines (36 loc) · 1.1 KB
/
relay.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
package main
import (
"errors"
"github.com/codexnetwork/trunk/blockdb"
"github.com/codexnetwork/codex-go/p2p"
"github.com/codexnetwork/trunk/cfg"
"github.com/codexnetwork/trunk/chainhandler"
"github.com/codexnetwork/trunk/logger"
"github.com/codexnetwork/trunk/relay"
"github.com/codexnetwork/trunk/side"
)
func startRelayService() {
// from relay to side, so create side client
data, p2ps := cfg.GetChainCfg("relay")
chainTyp := cfg.GetChainTyp("relay")
// for chain id
info, err := side.Client().GetInfoData()
if err != nil {
panic(errors.New("get info err"))
}
logger.Debugf("get info %v", *info)
p2pPeers := p2p.NewP2PClient(chainTyp, p2p.P2PInitParams{
Name: "watcher",
ClientID: info.ChainID.String(),
StartBlockNum: data.StartNum,
Peers: p2ps,
Logger: logger.Logger(),
})
p2pPeers.RegHandler(&handlerImp{
verifier: blockdb.NewFastBlockVerifier(p2ps, data.StartNum, chainhandler.NewChainHandler(
func(block *chainhandler.Block, actions []chainhandler.Action) {
relay.HandRelayBlock(block, actions)
}, chainTyp)),
})
p2pPeers.Start()
}