Skip to content

Commit

Permalink
feat(engine): usding local node for blockchain info, and random node …
Browse files Browse the repository at this point in the history
…for network info
  • Loading branch information
kehiy committed Jan 31, 2024
1 parent b36fc83 commit 67b7a5c
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ check:

### building
build:
go build -o build/robopac-server ./cmd/server
go build -o build/robopac-client ./cmd/client
go build -o build/robopac-discord ./cmd/discord
go build -o build/robopac-cmd ./cmd/cmd


.PHONY: build
18 changes: 15 additions & 3 deletions client/client_mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ func (cm *Mgr) GetLastBlockTime() (uint32, uint32) {
}

func (cm *Mgr) GetNetworkInfo() (*pactus.GetNetworkInfoResponse, error) {
for _, c := range cm.clients {
for name, c := range cm.clients {
if name == "local-node" {
continue
}

info, err := c.GetNetworkInfo()
if err != nil {
continue
Expand All @@ -83,7 +87,11 @@ func (cm *Mgr) GetNetworkInfo() (*pactus.GetNetworkInfoResponse, error) {
}

func (cm *Mgr) GetPeerInfoFirstVal(address string) (*pactus.PeerInfo, error) {
for _, c := range cm.clients {
for name, c := range cm.clients {
if name == "local-node" {
continue
}

networkInfo, err := c.GetNetworkInfo()
if err != nil {
continue
Expand All @@ -107,7 +115,11 @@ func (cm *Mgr) GetPeerInfoFirstVal(address string) (*pactus.PeerInfo, error) {
}

func (cm *Mgr) GetPeerInfo(address string) (*pactus.PeerInfo, error) {
for _, c := range cm.clients {
for name, c := range cm.clients {
if name == "local-node" {
continue
}

networkInfo, err := c.GetNetworkInfo()
if err != nil {
continue
Expand Down
2 changes: 1 addition & 1 deletion cmd/client/main.go → cmd/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

func main() {
rootCmd := &cobra.Command{
Use: "robopac-server",
Use: "robopac-cmd",
Version: "0.0.1",
}

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion cmd/server/main.go → cmd/discord/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

func main() {
rootCmd := &cobra.Command{
Use: "robopac",
Use: "robopac-discord",
Version: "0.0.1",
}

Expand Down
File renamed without changes.
13 changes: 11 additions & 2 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,22 @@ type BotEngine struct {

func NewBotEngine(cfg *config.Config) (IEngine, error) {
cm := client.NewClientMgr()

c, err := client.NewClient(cfg.LocalNode)
if err != nil {
log.Error("can't make a new local-net client", "err", err, "addr", cfg.LocalNode)
log.Error("can't make a new local client", "err", err, "addr", cfg.LocalNode)
return nil, err
}

cm.AddClient("local-net", c)
cm.AddClient("local-node", c)

for _, nn := range cfg.NetworkNodes {
c, err := client.NewClient(nn)
if err != nil {
log.Error("can't add new network node client", "err", err, "addr", nn)
}
cm.AddClient("client", c)
}

// initializing logger global instance.
log.InitGlobalLogger()
Expand Down

0 comments on commit 67b7a5c

Please sign in to comment.