Skip to content

Commit

Permalink
fix(config): invalid check
Browse files Browse the repository at this point in the history
  • Loading branch information
kehiy committed Apr 5, 2024
1 parent c7d54d0 commit f7b18a7
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Enviroment
ENVIROMENT=(dev | prod)
ENVIRONMENT=(dev | prod)

# Pactus

Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
PACKAGES=$(shell go list ./... | grep -v 'tests' | grep -v 'grpc/gen')

ifneq (,$(filter $(OS),Windows_NT MINGW64))
EXE = .exe
RM = del /q
else
RM = rm -rf
Expand All @@ -15,7 +16,8 @@ devtools:

### Building

# TODO
build:
go build -o build/wrapto$(EXE) .

### ABIs (EVM contracts)
build-abis:
Expand Down
4 changes: 2 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func LoadConfig() (*Config, error) {
}

cfg := &Config{
Environment: os.Getenv("NETWORK"),
Environment: os.Getenv("ENVIRONMENT"),
Logger: LoggerConfig{
Filename: os.ExpandEnv("LOG_FILENAME"),
LogLevel: os.Getenv("LOG_LEVEL"),
Expand Down Expand Up @@ -99,7 +99,7 @@ func LoadConfig() (*Config, error) {
}

func (c *Config) basicCheck() error {
if !(c.Environment == "dev") || !(c.Environment == "prod") {
if c.Environment != "dev" && c.Environment != "prod" { //nolint
return InvalidEnvironmentError{
Environment: c.Environment,
}
Expand Down
10 changes: 3 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ package main
import (
"context"
"os"
"os/signal"
"syscall"

"github.com/PACZone/wrapto/core"
logger "github.com/PACZone/wrapto/log"
"github.com/spf13/cobra"
)

Expand All @@ -17,11 +16,8 @@ func run(cmd *cobra.Command, _ []string) {

c.Start()

sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
<-sigChan

cancel()
<-ctx.Done()
logger.Info("shutdown")
}

func main() {
Expand Down
4 changes: 2 additions & 2 deletions sides/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ func NewManager(ctx context.Context, cancel context.CancelFunc, cfg *config.Conf
pactusCh := make(chan message.Message, 10)
polygonCh := make(chan message.Message, 10)

pactusSide, err := pactus.NewSide(ctx, highway, 0, pactusCh, cfg.Environment, cfg.Pactus, db)
pactusSide, err := pactus.NewSide(ctx, highway, 1, pactusCh, cfg.Environment, cfg.Pactus, db)
if err != nil {
return nil, err
}

polygonSide, err := polygon.NewSide(ctx, highway, 0, polygonCh, cfg.Environment, cfg.Polygon, db)
polygonSide, err := polygon.NewSide(ctx, highway, 4, polygonCh, cfg.Environment, cfg.Polygon, db)
if err != nil {
return nil, err
}
Expand Down
2 changes: 2 additions & 0 deletions sides/pactus/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ func (b Bridge) processMsg(msg message.Message) error {

txID, err := b.wallet.transferTx(payload.Receiver, memo, amt)
if err != nil {
logger.Error("can't send transaction to pactus network", "actor", b.bypassName, "err", err, "payload", payload)

dbErr := b.db.AddLog(&database.Log{
OrderID: msg.Payload.ID,
Actor: string(b.bypassName),
Expand Down
5 changes: 2 additions & 3 deletions sides/pactus/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func (l *Listener) Start() error {

return err
}
l.nextBlock++
}
}
}
Expand Down Expand Up @@ -157,8 +158,6 @@ func (l *Listener) processBlocks() error {
}
}

l.nextBlock++

return nil
}

Expand All @@ -175,7 +174,7 @@ func (l *Listener) filterValidTxs(txs []*pactus.TransactionInfo) []*pactus.Trans
validTxs := make([]*pactus.TransactionInfo, 0)

for _, tx := range txs {
if tx.PayloadType != pactus.PayloadType_TRANSFER_PAYLOAD &&
if tx.PayloadType != pactus.PayloadType_TRANSFER_PAYLOAD ||
tx.GetTransfer().Receiver != l.lockAddr {
continue
}
Expand Down
8 changes: 7 additions & 1 deletion sides/pactus/pactus.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func NewSide(ctx context.Context,
db *database.DB,
) (*Side, error) {
if env == "dev" {
crypto.AddressHRP = "tpc"
crypto.AddressHRP = "pc"
}

client, err := newClient(ctx, cfg.RPCNode)
Expand Down Expand Up @@ -69,6 +69,9 @@ func (s *Side) Start() {
Payload: nil,
}
}

logger.Error("error starting listener", "actor", bypass.PACTUS, "err", err)

wg.Done()
}()

Expand All @@ -81,6 +84,9 @@ func (s *Side) Start() {
Payload: nil,
}
}

logger.Error("error starting bridge", "actor", bypass.PACTUS, "err", err)

wg.Done()
}()

Expand Down
3 changes: 3 additions & 0 deletions sides/polygon/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ func (l *Listener) Start() error {
return nil
default:
if err := l.processOrder(); err != nil {
logger.Error("can't process block on listener", "actor", l.bypassName, "err", err)

return err
}
l.nextOrder++
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions sides/polygon/polygon.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ func (s *Side) Start() {
Payload: nil,
}
}

logger.Error("error starting listener", "actor", bypass.POLYGON, "err", err)

wg.Done()
}()

Expand All @@ -83,6 +86,9 @@ func (s *Side) Start() {
Payload: nil,
}
}

logger.Error("error starting bridge", "actor", bypass.POLYGON, "err", err)

wg.Done()
}()

Expand Down

0 comments on commit f7b18a7

Please sign in to comment.