Skip to content

Commit

Permalink
Merge pull request #6 from oraichain/feat/ton-to-cw-health-check
Browse files Browse the repository at this point in the history
Feat/ton to cw health check
  • Loading branch information
ducphamle2 authored Jun 27, 2024
2 parents 8a0c963 + 18a68f0 commit fde3b06
Show file tree
Hide file tree
Showing 20 changed files with 14,085 additions and 10,285 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
TON_HTTP_API_URL=http://localhost:5000/jsonRPC
TON_HTTP_API_URL=http://localhost:5000/jsonRPC
HEALTH_CHECK_PORT=3000
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,13 @@ dist
.pnp.*

.nx
**/packages/*/build/
**/packages/*/build/

# Yarn 3 files
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,17 @@
```bash
yarn patch-package
```

# publish packages

```bash

# normal
yarn deploy

# minor change
yarn deploy minor

# patch
yarn deploy patch
```
4 changes: 2 additions & 2 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"npmClient": "yarn",
"version": "1.0.7",
"version": "1.0.8",
"command": {
"publish": {
"registry": "https://registry.npmjs.org/"
}
}
}
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
"name": "root",
"private": "true",
"license": "MIT",
"scripts": {
"postinstall": "patch-package",
"test": "yarn build && jest",
"clean": "lerna clean --yes && lerna exec -- rimraf build/ dist/ cache/",
"build": "lerna run build --concurrency 1",
"build-tsc": "tsc -p",
"deploy": "yarn publish --access public",
"deploy": "yarn lerna publish",
"prepare": "husky install",
"build:docker": "lerna run build --concurrency 1"
},
Expand Down Expand Up @@ -57,5 +56,6 @@
"typedoc": "^0.25.12",
"typescript": "5.4.5"
},
"version": "1.0.1"
"version": "1.0.1",
"packageManager": "yarn@4.3.1"
}
3 changes: 0 additions & 3 deletions packages/common/README.md

This file was deleted.

17 changes: 0 additions & 17 deletions packages/common/package.json

This file was deleted.

Empty file removed packages/common/src/index.ts
Empty file.
15 changes: 0 additions & 15 deletions packages/common/tsconfig.json

This file was deleted.

17 changes: 0 additions & 17 deletions packages/cw-to-ton/package.json

This file was deleted.

Empty file removed packages/cw-to-ton/src/index.ts
Empty file.
21 changes: 21 additions & 0 deletions packages/orchestrator/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "@oraichain/tonbridge-orchestrator",
"version": "1.0.8",
"main": "build/index.js",
"files": [
"build/",
"@types"
],
"scripts": {
"build": "tsc -p tsconfig.json"
},
"license": "MIT",
"dependencies": {
"express": "^4.19.2"
},
"devDependencies": {
"@oraichain/tonbridge-relayer-to-cw": "workspace:^",
"@types/express": "^4",
"dotenv": "^16.4.5"
}
}
29 changes: 29 additions & 0 deletions packages/orchestrator/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import express, { Request, Response } from "express";
import dotenv from "dotenv";
import { exit } from "process";
import TonToCwRelayer from "@oraichain/tonbridge-relayer-to-cw";
dotenv.config();

(async () => {
try {
const app = express();
const port = process.env.HEALTH_CHECK_PORT
? Number(process.env.HEALTH_CHECK_PORT)
: 3000;

app.get("/", (req: Request, res: Response) => {
res.send("Pong from ton-to-cw relayer");
});

app.listen(port, "0.0.0.0", () => {
console.log(`Server is running at http://0.0.0.0:${port}`);
});

// FIXME: add block & tx processor initiator here. Also add relayer from cw-to-ton as well
const tonToCwRelayer = new TonToCwRelayer();
tonToCwRelayer.relay();
} catch (error) {
console.error("error is: ", error);
exit(1);
}
})();
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"baseUrl": ".",
"outDir": "build",
"declaration": true,
"strict": false,
"rootDir": "src"
},
"include": [
Expand Down
2 changes: 1 addition & 1 deletion packages/relayer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oraichain/tonbridge-relayer",
"version": "1.0.0",
"version": "1.0.8",
"main": "build/index.js",
"files": [
"build/",
Expand Down
14 changes: 7 additions & 7 deletions packages/ton-to-cw/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oraichain/tonbridge-relayer-to-cw",
"version": "1.0.0",
"version": "1.0.8",
"main": "build/index.js",
"files": [
"build/",
Expand All @@ -16,17 +16,17 @@
"@cosmjs/proto-signing": "0.31.3",
"@cosmjs/stargate": "0.31.3",
"@cosmjs/tendermint-rpc": "0.31.3",
"bignumber.js": "^9.1.2",
"cosmjs-types": "0.8.0",
"@oraichain/tonbridge-contracts-sdk": "latest",
"@oraichain/tonbridge-contracts-build": "latest",
"@oraichain/oraidex-contracts-sdk": "latest",
"@oraichain/oraidex-common": "latest",
"@oraichain/oraidex-contracts-sdk": "latest",
"@oraichain/tonbridge-contracts-build": "latest",
"@oraichain/tonbridge-contracts-sdk": "latest",
"@oraichain/tonbridge-utils": "^1.0.0",
"@orbs-network/ton-access": "^2.3.3",
"@ton/core": "^0.56.3",
"@ton/crypto": "^3.2.0",
"@ton/ton": "^13.11.1",
"@ton/core": "^0.56.3",
"bignumber.js": "^9.1.2",
"cosmjs-types": "0.8.0",
"ton-lite-client": "^3.0.0",
"tonweb": "^0.0.66"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/ton-to-cw/src/demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
import TonWeb from "tonweb";
import TonBlockProcessor from "./block-processor";
import TonTxProcessor from "./tx-processor";
import TonToCwRelayer from "./index";
import TonToCwRelayer from ".";
import dotenv from "dotenv";
import { InstantiateMsg } from "@oraichain/tonbridge-contracts-sdk/build/TonbridgeBridge.types";
dotenv.config();
Expand Down
45 changes: 21 additions & 24 deletions packages/ton-to-cw/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { exit } from "process";
import TonBlockProcessor from "./block-processor";
import TonTxProcessor from "./tx-processor";
import { setTimeout } from "timers/promises";
Expand All @@ -21,32 +22,28 @@ export default class TonToCwRelayer {
if (!this.blockProcessor || !this.txProcessor)
throw new Error("block and tx processors are not initialized yet");

try {
while (true) {
try {
const latestMasterchainBlock =
await this.blockProcessor.getMasterchainInfo();
const { rawBlockData, parsedBlock } =
await this.blockProcessor.queryKeyBlock(
latestMasterchainBlock.last.seqno
);
console.log(
"Prepare to verify masterchain keyblock: ",
parsedBlock.info.seq_no
while (true) {
try {
const latestMasterchainBlock =
await this.blockProcessor.getMasterchainInfo();
const { rawBlockData, parsedBlock } =
await this.blockProcessor.queryKeyBlock(
latestMasterchainBlock.last.seqno
);
await this.blockProcessor.verifyMasterchainKeyBlock(rawBlockData);
await this.blockProcessor.storeKeyBlockNextValSet(
rawBlockData,
parsedBlock
);
await this.txProcessor.processTransactions();
} catch (error) {
console.error("error processing block and tx: ", error);
}
await setTimeout(processInterval);
console.log(
"Prepare to verify masterchain keyblock: ",
parsedBlock.info.seq_no
);
await this.blockProcessor.verifyMasterchainKeyBlock(rawBlockData);
await this.blockProcessor.storeKeyBlockNextValSet(
rawBlockData,
parsedBlock
);
await this.txProcessor.processTransactions();
} catch (error) {
console.error("error processing block and tx: ", error);
}
} catch (error) {
console.error("Error in subcribing blocks: ", error);
await setTimeout(processInterval);
}
}
}
Loading

0 comments on commit fde3b06

Please sign in to comment.