mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-20 05:41:35 +00:00
81 lines
2.5 KiB
Go
81 lines
2.5 KiB
Go
package utils
|
|
|
|
import (
|
|
"github.com/XinFinOrg/XDPoSChain/XDCx"
|
|
"github.com/XinFinOrg/XDPoSChain/XDCxlending"
|
|
"github.com/XinFinOrg/XDPoSChain/eth"
|
|
"github.com/XinFinOrg/XDPoSChain/eth/downloader"
|
|
"github.com/XinFinOrg/XDPoSChain/eth/ethconfig"
|
|
"github.com/XinFinOrg/XDPoSChain/ethstats"
|
|
"github.com/XinFinOrg/XDPoSChain/les"
|
|
"github.com/XinFinOrg/XDPoSChain/node"
|
|
whisper "github.com/XinFinOrg/XDPoSChain/whisper/whisperv6"
|
|
)
|
|
|
|
// RegisterEthService adds an Ethereum client to the stack.
|
|
func RegisterEthService(stack *node.Node, cfg *ethconfig.Config) {
|
|
var err error
|
|
if cfg.SyncMode == downloader.LightSync {
|
|
err = stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
|
|
return les.New(ctx, cfg)
|
|
})
|
|
} else {
|
|
err = stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
|
|
var XDCXServ *XDCx.XDCX
|
|
ctx.Service(&XDCXServ)
|
|
var lendingServ *XDCxlending.Lending
|
|
ctx.Service(&lendingServ)
|
|
fullNode, err := eth.New(ctx, cfg, XDCXServ, lendingServ)
|
|
if fullNode != nil && cfg.LightServ > 0 {
|
|
ls, _ := les.NewLesServer(fullNode, cfg)
|
|
fullNode.AddLesServer(ls)
|
|
}
|
|
return fullNode, err
|
|
})
|
|
}
|
|
if err != nil {
|
|
Fatalf("Failed to register the Ethereum service: %v", err)
|
|
}
|
|
}
|
|
|
|
// RegisterShhService configures Whisper and adds it to the given node.
|
|
func RegisterShhService(stack *node.Node, cfg *whisper.Config) {
|
|
if err := stack.Register(func(n *node.ServiceContext) (node.Service, error) {
|
|
return whisper.New(cfg), nil
|
|
}); err != nil {
|
|
Fatalf("Failed to register the Whisper service: %v", err)
|
|
}
|
|
}
|
|
|
|
// RegisterEthStatsService configures the Ethereum Stats daemon and adds it to
|
|
// th egiven node.
|
|
func RegisterEthStatsService(stack *node.Node, url string) {
|
|
if err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
|
|
// Retrieve both eth and les services
|
|
var ethServ *eth.Ethereum
|
|
ctx.Service(ðServ)
|
|
|
|
var lesServ *les.LightEthereum
|
|
ctx.Service(&lesServ)
|
|
|
|
return ethstats.New(url, ethServ, lesServ)
|
|
}); err != nil {
|
|
Fatalf("Failed to register the Ethereum Stats service: %v", err)
|
|
}
|
|
}
|
|
|
|
func RegisterXDCXService(stack *node.Node, cfg *XDCx.Config) {
|
|
XDCX := XDCx.New(cfg)
|
|
if err := stack.Register(func(n *node.ServiceContext) (node.Service, error) {
|
|
return XDCX, nil
|
|
}); err != nil {
|
|
Fatalf("Failed to register the XDCX service: %v", err)
|
|
}
|
|
|
|
// register XDCxlending service
|
|
if err := stack.Register(func(n *node.ServiceContext) (node.Service, error) {
|
|
return XDCxlending.New(XDCX), nil
|
|
}); err != nil {
|
|
Fatalf("Failed to register the XDCXLending service: %v", err)
|
|
}
|
|
}
|