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

[Draft] Zilliqa relayer implementation #1

Open
wants to merge 120 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 85 commits
Commits
Show all changes
120 commits
Select commit Hold shift + click to select a range
5396a9e
init: project
renlulu Nov 11, 2020
f5d508b
chore: define config file, and restruct some part
renlulu Nov 25, 2020
cfccd10
chore: add build and run script
renlulu Jan 13, 2021
9d9cb37
feat: monitor tx block number
renlulu Jan 13, 2021
63d470e
wip: monitor transactions come to cross chain manager, parse event, s…
renlulu Jan 13, 2021
94be137
feat: add dockerfile support
renlulu Jan 13, 2021
bbf073c
doc: update readme
renlulu Jan 13, 2021
f814d43
chore: fix dockerfile, add more scripts
renlulu Jan 13, 2021
8d614a6
feat: add polywallet file
renlulu Jan 13, 2021
90abef4
feat: parse cross chain event
renlulu Jan 15, 2021
f3f9b1d
chore: introduce MonitorDeposit for zil manager, adjust config hierarchy
renlulu Jan 15, 2021
31586f7
doc: update readme
renlulu Jan 15, 2021
accbbff
feat: support poly config
renlulu Jan 15, 2021
67f2d6a
chore: rename sync service name, divide it into two managers(zilliqas…
renlulu Jan 18, 2021
44c4d2d
wip: struct Monitor poly chain
renlulu Jan 19, 2021
06882c1
feat: parse event from polynetwork
renlulu Jan 19, 2021
47f6fdc
feat(PolySyncManager): check if from chain transaction exist in zilli…
renlulu Jan 20, 2021
d4ab90e
chore: restruct directory for more friendly readability
renlulu Jan 20, 2021
efc4109
feat(config): support zil chain id, message version and keystore(mult…
renlulu Jan 20, 2021
98e7b0e
feat: init polymanager, parse zil keystore with pwd set
renlulu Jan 20, 2021
8008ee7
feat(zilsender): commitDepositEventsWithHeader
renlulu Jan 21, 2021
53b6aca
feat: temp use one sender to intereact with cross chain contract
renlulu Jan 21, 2021
68221c3
feat(zilsender): commitHeader
renlulu Jan 21, 2021
43f6cce
feat(polymanager): init start height
renlulu Jan 22, 2021
7c12929
feat(zilliqamanager): init poly wallet infp
renlulu Jan 22, 2021
6437260
chore: update config relative
renlulu Feb 17, 2021
d901574
feat: support target contract setting
renlulu Feb 17, 2021
5542053
feat(zilmamanger): support force height
renlulu Feb 19, 2021
d337d8f
feat(zilmanager): handle block header
renlulu Feb 19, 2021
bb964da
feat(zilmanager): commitHeader
renlulu Feb 21, 2021
4ffdaa9
feat(zilmanager): commit txblock and ds comm
renlulu Feb 22, 2021
094ce41
feat: support ds block commit
renlulu Feb 23, 2021
bad0a21
feat(zilmananger): handleLockDepositEvents
renlulu Feb 23, 2021
e1b4b3f
feat(zilmananger): handleLockDepositEvents
renlulu Feb 23, 2021
979a2fc
feat: rollback ds block num if needed
renlulu Feb 23, 2021
2e9867a
fix: update zilliqa manager init process
renlulu Mar 3, 2021
94253f2
fix: init zilliqa manager, block commit
renlulu Mar 4, 2021
ea8562e
feat: complete cross chain transaction commit
renlulu Mar 6, 2021
8200580
feat: support timestamp in log, update sdk version
renlulu Mar 8, 2021
83a149e
fix(polymanager): add 0x prefix while calling zilliqa contract
renlulu Mar 8, 2021
4fa85b3
fix: handle the situation where proof is nil even no error happens
renlulu Mar 10, 2021
a21bdff
fix: carefully handle poly current height
renlulu Mar 11, 2021
616b0b8
doc: update readme
renlulu Mar 11, 2021
12f0f5c
chore: typo
renlulu Mar 11, 2021
3fcbc27
chore: rename two wallets
renlulu Mar 11, 2021
70a7803
feat: select sender
renlulu Mar 16, 2021
54e404a
fix: init sender
renlulu Mar 16, 2021
1b40f14
chore: one more log
renlulu Mar 16, 2021
c9bc96a
chore: update poly height
renlulu Mar 17, 2021
dcb9243
fix: change keeper 0x issue
renlulu Mar 18, 2021
316c42a
fix: mutex issue of selecting sender
renlulu Mar 18, 2021
4cd70db
feat: nonce manager
renlulu Mar 24, 2021
df1eace
chore: update gitignore
renlulu Mar 24, 2021
6718e14
feat: commit header without blocking
renlulu Mar 26, 2021
c58e826
feat: support hashed storage key
renlulu Mar 29, 2021
fe9c704
fix: lowercase cmcc, in order to geneate correct storage key
renlulu Mar 31, 2021
d6a6e60
feat: enhance nonce manager
renlulu Apr 8, 2021
8d72826
fix: use R/W lock
renlulu Apr 10, 2021
33b103a
chore: remove unnecessary code
renlulu Apr 10, 2021
63f895c
fix: use defer fix deadlock issue
renlulu Apr 10, 2021
9bd13f7
chore: expose somme useful log
renlulu Apr 16, 2021
a36f6f5
chore: remove some annotation code
renlulu Apr 20, 2021
f9bebfd
Merge branch 'main' of github.com:Zilliqa/zilliqa-relayer into main
renlulu Apr 20, 2021
83240c9
chore: update gitignore
renlulu Apr 20, 2021
ac50ba9
Added db path for persistence location.
Annihilatopia Apr 20, 2021
f82f5d4
Merge branch 'main' into feature/docker-compose.yml
Annihilatopia Apr 20, 2021
daa2eda
Fixed variable typo.
Annihilatopia Apr 20, 2021
8220c03
Added docker-compose.
Annihilatopia Apr 20, 2021
8fe2da6
Updated Dockerfile run command.
Annihilatopia Apr 20, 2021
64d4693
Updated dockerfile and added all configs to docker compose.
Annihilatopia Apr 20, 2021
a3e2a03
Updated run-docker.sh
Annihilatopia Apr 20, 2021
f06a017
Updated build-docker.sh
Annihilatopia Apr 20, 2021
02d09cf
Added container name to docker run.
Annihilatopia Apr 20, 2021
11be2f6
Set docker-compose container name.
Annihilatopia Apr 20, 2021
10395dc
Updated Readme.
Annihilatopia Apr 20, 2021
34713a3
Fixed readme typo.
Annihilatopia Apr 20, 2021
5747433
Added dockerhub post push hook to tag with commit.
Annihilatopia Apr 20, 2021
e591df7
Added branch detection to post_push hook.
Annihilatopia Apr 20, 2021
326f41b
Merge pull request #1 from Zilliqa/feature/docker-compose.yml
Annihilatopia Apr 20, 2021
884f277
Updated tag to use first 7 char of commit hash
Annihilatopia Apr 22, 2021
9e72572
updated readme
Annihilatopia Apr 23, 2021
6577db8
feat: add removedb option
renlulu Apr 27, 2021
fed17de
Merge pull request #2 from Zilliqa/feat/removedb
Annihilatopia Apr 27, 2021
447ea9e
doc: add license header
renlulu Jun 28, 2021
fc38bbb
chore: add license file
renlulu Jun 28, 2021
b60f292
chore: add log for querying new ds block
renlulu Jul 6, 2021
a977fe2
feat: handle empty ds block
renlulu Jul 13, 2021
c58370e
Merge pull request #3 from Zilliqa/feat/handleemptyds
Annihilatopia Jul 13, 2021
0f7f18d
fix: remove goto to avoid loop
renlulu Jul 14, 2021
600516e
Merge pull request #4 from Zilliqa/fix/removegoto
Jul 14, 2021
0ce01c9
fix: handle dummy ds block
renlulu Jul 15, 2021
e0ed0b5
Merge pull request #5 from Zilliqa/fix/dummyds
Annihilatopia Jul 15, 2021
4356c6e
fix: retry if encounter tx block not exist
renlulu Jul 29, 2021
6fa2043
Merge pull request #6 from Zilliqa/fix/retrytxn
Annihilatopia Jul 30, 2021
db02563
enhance: retry 100 times committing blocks
renlulu Sep 17, 2021
c162de1
Merge pull request #7 from Zilliqa/enhance/commitblk
Annihilatopia Sep 20, 2021
8f4c3bf
enhance: audit log
renlulu Sep 21, 2021
cc2528a
Merge pull request #8 from Zilliqa/feat/auditlog
Annihilatopia Sep 21, 2021
8432bf5
fix: nil error for audit log
renlulu Sep 22, 2021
894e9aa
Merge pull request #9 from Zilliqa/fix/logissue
Annihilatopia Sep 22, 2021
d30ded0
dep: update golang sdk
renlulu Sep 27, 2021
ac5dec1
enhance: adjust wait time
renlulu Sep 27, 2021
6b3ddac
Merge pull request #10 from Zilliqa/dep/zilsdk
Annihilatopia Sep 27, 2021
de2d5b0
Fix some relayer bugs
HenryTimelessness Sep 2, 2022
85b85da
Merge pull request #11 from Switcheo/main
pavlops Sep 7, 2022
65c23dc
feat: add relayer pipeline (#13)
frankmeds Jan 5, 2024
efd966c
corrected condition (#12)
stevenkhong Feb 28, 2024
5c81aae
Debug (#14)
mauromedda Feb 28, 2024
73f7cf3
(add): more debug (#15)
mauromedda Feb 28, 2024
844f457
Users/richard/debug (#16)
rrw-zilliqa Feb 29, 2024
88594be
More debug (#17)
rrw-zilliqa Feb 29, 2024
13d0a28
More debug! (#18)
rrw-zilliqa Mar 1, 2024
6666992
Yet more debug (#19)
rrw-zilliqa Mar 1, 2024
e0050b8
Yet more debug (#20)
rrw-zilliqa Mar 1, 2024
23118e2
And more (#21)
rrw-zilliqa Mar 1, 2024
63fd1ca
Round 6 (#22)
rrw-zilliqa Mar 1, 2024
baf74b1
Search .. (#23)
rrw-zilliqa Mar 1, 2024
c31613e
(fix): zil2poly dsblock override prevention (#24)
mauromedda Mar 4, 2024
2d061c8
(hack): print the data and returns without commit to poly (#26)
mauromedda Mar 5, 2024
da42edb
(feat) If we're lucky, this conditionalises the debug and practice on…
rrw-zilliqa Mar 25, 2024
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
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
zilliqa-relayer
.idea
bolt.bin
config.local.yaml
constants.xml
cross_chain_manager_admin.json
xiaohuo.wallet
zilliqa.wallet
poly.wallet
relayer.wallet
secrets
config.devnet.yaml
config.testnet.yaml
target_contracts_devnet.json
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM golang:1.15 AS build
WORKDIR /app/zilliqa-relayer
COPY . ./
RUN go build
#RUN git clone https://github.com/Zilliqa/zilliqa-relayer.git && \
# cd zilliqa-relayer && \
# go build

FROM ubuntu:18.04
RUN apt-get update && apt-get install -y ca-certificates
WORKDIR /app
COPY run.sh run.sh
COPY --from=build /app/zilliqa-relayer/zilliqa-relayer zilliqa-relayer
ENTRYPOINT ["/bin/bash", "run.sh"]
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

131 changes: 130 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,130 @@
# zilliqa-relayer
# zilliqa-relayer

*This program is still under developing!*

Zilliqa Relayer is an important character of Poly cross-chain interactive protocol which is responsible for relaying cross-chain transaction from and to Zilliqa.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Zilliqa Relayer is an important character of Poly cross-chain interactive protocol which is responsible for relaying cross-chain transaction from and to Zilliqa.
Zilliqa Relayer is an important character of PolyNetwork cross-chain interactive protocol which is responsible for relaying cross-chain transaction from and to Zilliqa.


## Build From Source

### Prerequisites

- [Golang](https://golang.org/doc/install) version 1.14 or later

### Build

```shell
git clone https://github.com/polynetwork/zil-relayer.git
cd zil-relayer
./build.sh
```

After building the source code successfully, you should see the executable program `zilliqa-relayer`.

### Build Docker Image

```
docker build -t polynetwork/zilliqa-relayer .
```

This command will copy config.yaml to /app/config.yaml in the image. So you need to prepare config.yaml before running this command and you should start the zilliqa-relayer in container basing on the configuration in /app/config.yaml.


## Run Relayer
Before you can run the relayer you will need to create a wallet file of PolyNetwork by running(build Poly CLI first):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Before you can run the relayer you will need to create a wallet file of PolyNetwork by running(build Poly CLI first):
Before you can run the relayer you will need to create a keystore file for PolyNetwork by running the following command:
Note: You will need to build and use Poly CLI


```shell
./poly account add -d
```

After creation, you need to register it as a Relayer to Poly net and get consensus nodes approving your registeration. And then you can send transaction to Poly net and start relaying.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
After creation, you need to register it as a Relayer to Poly net and get consensus nodes approving your registeration. And then you can send transaction to Poly net and start relaying.
After creation, you need to register it as a Relayer to PolyNetwork and get consensus nodes approving your registration. Afterwhich, you can start sending transactions to PolyNetwork and start relaying it.


Before running, you need feed the configuration file `config.yaml`.

```yaml
zil_config:
zil_api: https://api.zilliqa.com
zil_chain_id: 111
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be chain_id 1

zil_message_version: 1
zil_force_height: 0
zil_monitor_interval: 10
zil_headers_per_batch: 2
corss_chain_manager_address: zil1tjru7m5zdn3x6k0t72nzmmpz62e5qds62nte9t
cross_chain_manager_proxy_address: zil1n7wkwr0xxslwsrhnqtjrwlus80dp5ncnlpaw93
side_chain_id: 85
key_store_path: zilliqa.wallet
key_store_pwd_set:
6c89b62d65dc632e259b96f7ae2f1d68a27e3383: ""
poly_config:
poly_wallet_file: poly.wallet
poly_wallet_pwd:
poly_start_height: 0
poly_monitor_interval: 2
entrance_contract_address: "0300000000000000000000000000000000000000"
rest_url: http://poly.com
target_contracts: target_contracts.json
db_path: persistence
```

A sample keystore file could be:

```text
{"address":"7d48043742a1103042d327111746531ca26be9be","id":"6cd445ed-8f5f-4565-af2a-cc2306a82b73","version":3,"crypto":{"cipher":"aes-128-ctr","ciphertext":"d136660a4e5664709031ebc162616556e8c812ab37d0157ea3276aa08d0a6c2d","kdf":"pbkdf2","mac":"b30dd459f1fd9d99c0b2f3452ccd2bf11414ad92d32ac70d1d7b52f17281b4e5","cipherparams":{"iv":"6a14f95c8cbafe7d1f317bec88e9d1b8"},"kdfparams":{"n":8192,"c":262144,"r":8,"p":1,"dklen":32,"salt":"c4939e7cead32935d1972a2cd06d249dd501181e6ad2d1872fa0eb397d7fea20"}}}
```
# Relayer Container Administration
## Running the Relayer Container
### Prerequisites:
If you are running via docker-compose, you'll need to install docker-compose first via the following guide:
```
https://docs.docker.com/compose/install/
```

You need the following files and folders created: <br />
If persistence is already created:
```
./persistence/bolt.bin
```
If persistence folder is not created:
```
create a folder named 'persistence'. The container will use that folder to store the bolt.bin file.
```
Configuration Files:
```
secrets/config.local.yaml
secrets/target_contracts.json
secrets/poly.wallet
secrets/zilliqa.wallet
```
### Running Relayer via Docker Container
```
./docker-run
```

### Running Relayer via Docker Compose
```
docker-compose up -d
```
## Stopping the Relayer
### Stopping Relayer via Docker Container
```
docker stop zilliqa-relayer && docker rm zilliqa-relayer
```
### Stopping Relayer via Docker Compose
```
docker-compose down
```
## Getting logs
```
docker logs -f zilliqa-relayer
```


## Other Resources
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update the resource to the latest repo


- [zilliqa cross chain manager proxy](https://github.com/Zilliqa/zilliqa-contracts/blob/main/contracts/ZilCrossChainManagerProxy.scilla)
- [zilliqa cross chain manager](https://github.com/Zilliqa/zilliqa-contracts/blob/main/contracts/ZilCrossChainManager.scilla)
- [zilliqa lock proxy](https://github.com/Zilliqa/zilliqa-contracts/blob/main/contracts/LockProxy.scilla)
- [polynetwork](https://github.com/polynetwork/poly)




2 changes: 2 additions & 0 deletions build-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
docker build -t polynetwork/zilliqa-relayer .
2 changes: 2 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
go build
40 changes: 40 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (C) 2021 Zilliqa
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package cmd

import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"os"
)

var RootCmd = &cobra.Command{
Use: "zilliqa-relayer",
Short: "To run zilliqa relayer for poly network",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Short: "To run zilliqa relayer for poly network",
Short: "To run zilliqa relayer for PolyNetwork",

Long: `To run zilliqa relayer for poly network`,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Long: `To run zilliqa relayer for poly network`,
Long: `To run zilliqa relayer for PolyNetwork`,

Run: func(cmd *cobra.Command, args []string) {
},
}

func Execute() {
if err := RootCmd.Execute(); err != nil {
log.Error(err)
os.Exit(1)
}
}
180 changes: 180 additions & 0 deletions cmd/run.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
/*
* Copyright (C) 2021 Zilliqa
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package cmd
renlulu marked this conversation as resolved.
Show resolved Hide resolved

import (
"encoding/json"
"github.com/Zilliqa/gozilliqa-sdk/provider"
poly_go_sdk "github.com/polynetwork/poly-go-sdk"
"github.com/polynetwork/zilliqa-relayer/config"
"github.com/polynetwork/zilliqa-relayer/db"
"github.com/polynetwork/zilliqa-relayer/service"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"io/ioutil"
"os"
"path"
)

var cfgFile string

func init() {
cobra.OnInitialize(initConfig)
RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.cobra.yaml)")

RootCmd.AddCommand(runCmd)
log.SetFormatter(&log.TextFormatter{
FullTimestamp: true,
})
}

func initConfig() {
if cfgFile != "" {
// Use config file from the flag.
viper.SetConfigFile(cfgFile)
} else {
viper.AddConfigPath("./")
viper.SetConfigName("config.local")
}

viper.AutomaticEnv()

err := viper.ReadInConfig()
if err == nil {
log.Info("Using config file:", viper.ConfigFileUsed())
} else {
log.Error(err.Error())
}
}

func setUpPoly(poly *poly_go_sdk.PolySdk, RpcAddr string) error {
poly.NewRpcClient().SetAddress(RpcAddr)
hdr, err := poly.GetHeaderByHeight(0)
if err != nil {
return err
}
poly.SetChainId(hdr.ChainID)
return nil
}

func checkIfExist(dir string) bool {
_, err := os.Stat(dir)
if err != nil && !os.IsExist(err) {
return false
}
return true
}

var runCmd = &cobra.Command{
Use: "run",
Short: "Run zilliqa relayer",
Long: `Run zilliqa relayer`,
Run: func(cmd *cobra.Command, args []string) {
zilConfigMap := viper.GetStringMap("zil_config")
targetContractsPath := viper.GetString("target_contracts")
dbPath := viper.GetString("db_path")
removeDb := viper.GetBool("remove_db")
bytes, e := ioutil.ReadFile(targetContractsPath)
if e != nil {
log.Errorf("read target contracts error: %s, path: %s\n", e.Error(), targetContractsPath)
return
}
var targetContract []map[string]map[string][]uint64
e2 := json.Unmarshal(bytes, &targetContract)
if e2 != nil {
log.Errorf("unmarshal target contracts error: %s\n", e2.Error())
return
}
log.Info(targetContract)
zilConfig := &config.ZILConfig{
ZilApiEndpoint: zilConfigMap["zil_api"].(string),
ZilChainId: zilConfigMap["zil_chain_id"].(int),
ZilMessageVersion: zilConfigMap["zil_message_version"].(int),
ZilForceHeight: uint64(zilConfigMap["zil_force_height"].(int)),
ZilMonitorInterval: uint32(zilConfigMap["zil_monitor_interval"].(int)),
ZilHeadersPerBatch: uint32(zilConfigMap["zil_headers_per_batch"].(int)),
SideChainId: uint64(zilConfigMap["side_chain_id"].(int)),
CrossChainManagerContract: zilConfigMap["corss_chain_manager_address"].(string),
CrossChainManagerProxyContract: zilConfigMap["cross_chain_manager_proxy_address"].(string),
MaxExistTxEpoch: zilConfigMap["max_exist_tx_epoch"].(int),
KeyStorePath: zilConfigMap["key_store_path"].(string),
KeyStorePwdSet: zilConfigMap["key_store_pwd_set"].(map[string]interface{}),
}

polyConfigMap := viper.GetStringMap("poly_config")

polyConfig := &config.POLYConfig{
PolyWalletFile: polyConfigMap["poly_wallet_file"].(string),
PolyWalletPassword: polyConfigMap["poly_wallet_pwd"].(string),
PolyStartHeight: uint32(polyConfigMap["poly_start_height"].(int)),
PolyMonitorInterval: uint32(polyConfigMap["poly_monitor_interval"].(int)),
EntranceContractAddress: polyConfigMap["entrance_contract_address"].(string),
RestUrl: polyConfigMap["rest_url"].(string),
}

cfg := &config.Config{
ZilConfig: zilConfig,
PolyConfig: polyConfig,
TargetContracts: targetContract,
Path: dbPath,
RemoveDB: removeDb,
}

cfgStr, _ := json.Marshal(cfg)
log.Infof("config file: %s\n", cfgStr)

zilSdk := provider.NewProvider(cfg.ZilConfig.ZilApiEndpoint)
polySdk := poly_go_sdk.NewPolySdk()
err1 := setUpPoly(polySdk, cfg.PolyConfig.RestUrl)
if err1 != nil {
log.Errorf("init poly sdk error: %s\n", err1.Error())
return
}

if cfg.RemoveDB {
os.Remove(path.Join(cfg.Path, "bolt.bin"))
}

if !checkIfExist(cfg.Path) {
os.Mkdir(cfg.Path, os.ModePerm)
}
boltDB, err2 := db.NewBoltDB(cfg.Path)
if err2 != nil {
log.Errorf("cannot init bolt db: %s\n", err2.Error())
return
}

zilliqaManager, err := service.NewZilliqaSyncManager(cfg, zilSdk, polySdk, boltDB)
if err != nil {
log.Errorf("init zilliqamanger error: %s\n", err.Error())
return
}
polyManager, err1 := service.NewPolySyncManager(cfg, zilSdk, polySdk, boltDB, cfg.ZilConfig.CrossChainManagerContract, cfg.ZilConfig.CrossChainManagerProxyContract)
if err1 != nil {
log.Errorf("init polymanager error: %s\n", err1.Error())
return
}

zilliqaManager.Run(true)
polyManager.Run(true)

service.WaitToExit()

},
}
Loading