Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(client): using proto files for pactus client #6

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
PACKAGES=$(shell go list ./... | grep -v 'tests' | grep -v 'grpc/gen')

ifneq (,$(filter $(OS),Windows_NT MINGW64))
RM = del /q
else
RM = rm -rf
endif

### Tools needed for development
devtools:
@echo "Installing devtools"
Expand All @@ -14,7 +20,12 @@ build:

### ABIs (EVM contracts)
build-abis:
abigen --abi ./abis/WrappedPac.json --pkg polygonClient --type WrappedPac --out ./client/polygon_client/WrappedPac.go
abigen --abi ./abis/WrappedPac.json --pkg polygonClient --type WrappedPac --out ./client/polygon_client/wrapped_pac.go

### proto
proto:
$(RM) -rf client/pactus/gen/go
cd client/pactus/buf && buf generate --template buf.gen.yaml ../proto

### Testing
unit_test:
Expand Down
21 changes: 11 additions & 10 deletions bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,30 @@ package bridge
import (
"math/big"

pactusClient "github.com/PacmanHQ/teleport/client/pactusclient"
polygonClient "github.com/PacmanHQ/teleport/client/polygonclient"
"github.com/PacmanHQ/teleport/database"
"github.com/PacmanHQ/teleport/order"
"github.com/PacmanHQ/teleport/wallet"
pactus "github.com/PACZone/teleport/client/pactus"
"github.com/PACZone/teleport/client/polygon"
"github.com/PACZone/teleport/database"
"github.com/PACZone/teleport/order"
"github.com/PACZone/teleport/wallet"
"github.com/ethereum/go-ethereum/common"
)

type Bridge struct {
pactusClient pactusClient.PactusClient
polygonClient polygonClient.PolygonClient
pactusClient *pactus.Mgr

polygonClient *polygon.Client
orderCh chan order.Order
wallet wallet.Wallet
db database.DB
}

func NewBridge(pactusC pactusClient.PactusClient, polygonC *polygonClient.PolygonClient,
func NewBridge(pactusCmgr *pactus.Mgr, polygonC *polygon.Client,
orderCh chan order.Order,
w wallet.Wallet, db database.DB,
) *Bridge {
return &Bridge{
pactusClient: pactusC,
polygonClient: *polygonC,
pactusClient: pactusCmgr,
polygonClient: polygonC,
orderCh: orderCh,
wallet: w,
db: db,
Expand Down
9 changes: 9 additions & 0 deletions client/pactus/buf/buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: v1
plugins:
- name: go
out: ../gen/go
opt: paths=source_relative
- name: go-grpc
out: ../gen/go
opt: paths=source_relative,require_unimplemented_servers=false

50 changes: 50 additions & 0 deletions client/pactus/client_mgr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package pactus

import (
"context"
"fmt"

pactus "github.com/PACZone/teleport/client/pactus/gen/go"
)

type Mgr struct {
ctx context.Context
clients []Client
}

func NewClientMgr(ctx context.Context) *Mgr {
return &Mgr{
clients: make([]Client, 0),
ctx: ctx,
}
}

func (cm *Mgr) AddClient(c Client) {
cm.clients = append(cm.clients, c)
}

func (cm *Mgr) GetBlock(height uint32) (*pactus.GetBlockResponse, error) {
for _, c := range cm.clients {
txs, err := c.GetBlock(cm.ctx, height)
if err == nil {
return txs, nil
}

continue
}

return nil, fmt.Errorf("can't find block with height %d", height)
}

func (cm *Mgr) GetHeight() (uint32, error) {
for _, c := range cm.clients {
lbh, err := c.GetHeight(cm.ctx)
if err == nil {
return lbh, nil
}

continue
}

return 0, fmt.Errorf("can't find last block height")
}
Loading
Loading