-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/relay-service' into 'dev'
feat: add relay service Closes #93 See merge request ergo/rosen-bridge/rosenet!58
- Loading branch information
Showing
15 changed files
with
224 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
--- |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
"type": "module", | ||
"workspaces": { | ||
"packages": [ | ||
"services/*", | ||
"tests/*", | ||
"packages/*" | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# @rosen-bridge/relay-service | ||
|
||
## Table of contents | ||
|
||
- [Introduction](#introduction) | ||
|
||
## Introduction | ||
|
||
Rosen Bridge relay service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
logs: | ||
- type: 'file' | ||
path: './logs/' | ||
maxSize: '10m' | ||
maxFiles: '14d' | ||
level: 'info' | ||
- type: 'console' | ||
level: 'info' | ||
listen: | ||
host: 0.0.0.0 | ||
port: 44123 | ||
whitelist: [] | ||
pubsubTopics: [] | ||
privateKeyFilePath: './rosenet-secret.json' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"name": "@rosen-bridge/relay-service", | ||
"version": "0.1.0", | ||
"description": "Rosen Bridge relay service", | ||
"repository": "", | ||
"license": "GPL-3.0", | ||
"author": "Rosen Team", | ||
"type": "module", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"scripts": { | ||
"lint": "eslint --fix . && npm run prettify", | ||
"prettify": "prettier --write . --ignore-path ./.gitignore", | ||
"start": "node --watch --loader ./ts-node-esm-loader.js --loader extensionless ./src/index.ts", | ||
"start:prod": "node --loader extensionless ./dist/index.js", | ||
"type-check": "tsc --noEmit" | ||
}, | ||
"dependencies": { | ||
"@rosen-bridge/abstract-logger": "^2.0.1", | ||
"@rosen-bridge/rosenet-relay": "^0.1.1", | ||
"@rosen-bridge/rosenet-utils": "^0.2.0", | ||
"@rosen-bridge/winston-logger": "^1.0.2", | ||
"config": "^3.3.7" | ||
}, | ||
"devDependencies": { | ||
"@types/config": "^0.0.41", | ||
"@types/node": "^20.11.9", | ||
"@typescript-eslint/eslint-plugin": "^6.19.1", | ||
"@typescript-eslint/parser": "^6.19.1", | ||
"eslint": "^8.56.0", | ||
"eslint-config-prettier": "^9.1.0", | ||
"extensionless": "^1.9.6", | ||
"prettier": "^3.2.4", | ||
"ts-node": "^10.7.0", | ||
"tsconfig-paths": "^4.1.2", | ||
"typescript": "^5.3.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { DefaultLoggerFactory } from '@rosen-bridge/abstract-logger'; | ||
import WinstonLogger from '@rosen-bridge/winston-logger'; | ||
|
||
import { logs } from './configs'; | ||
|
||
const winston = new WinstonLogger(logs); | ||
DefaultLoggerFactory.init(winston); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { TransportOptions } from '@rosen-bridge/winston-logger'; | ||
import config from 'config'; | ||
|
||
export const host = config.get<string>('listen.host') ?? '0.0.0.0'; | ||
export const port = config.get<number>('listen.port') ?? 44123; | ||
|
||
export const whitelist = config.get<string[]>('whitelist') ?? []; | ||
|
||
export const pubsubTopics = config.get<string[]>('pubsubTopics') ?? []; | ||
|
||
export const logs = config.get<TransportOptions[]>('logs') ?? []; | ||
|
||
export const privateKeyFilePath = | ||
config.get<string>('privateKeyFilePath') ?? './rosenet-secret.json'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import './bootstrap'; | ||
|
||
import { DefaultLoggerFactory } from '@rosen-bridge/abstract-logger'; | ||
|
||
import { startRelay } from './relay'; | ||
|
||
const logger = DefaultLoggerFactory.getInstance().getLogger(import.meta.url); | ||
|
||
try { | ||
await startRelay(); | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
logger.error(`An error occurred while starting relay: [${error.message}]`); | ||
} else { | ||
logger.error(`An unknown error occurred while starting relay`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { DefaultLoggerFactory } from '@rosen-bridge/abstract-logger'; | ||
import { createRoseNetRelay } from '@rosen-bridge/rosenet-relay'; | ||
import { readPrivateKeyFromFile } from '@rosen-bridge/rosenet-utils'; | ||
|
||
import { | ||
host, | ||
port, | ||
privateKeyFilePath, | ||
pubsubTopics, | ||
whitelist, | ||
} from './configs'; | ||
|
||
const logger = DefaultLoggerFactory.getInstance().getLogger(import.meta.url); | ||
const rosenetLogger = DefaultLoggerFactory.getInstance().getLogger('rosenet'); | ||
|
||
/** | ||
* Start relay service | ||
*/ | ||
const startRelay = async () => { | ||
const privateKey = await readPrivateKeyFromFile(privateKeyFilePath); | ||
const node = await createRoseNetRelay({ | ||
privateKey, | ||
listen: { | ||
host, | ||
port, | ||
}, | ||
whitelist, | ||
logger: rosenetLogger, | ||
}); | ||
|
||
await node.start(); | ||
|
||
pubsubTopics.forEach((topic) => node.subscribe(topic, () => {})); | ||
|
||
logger.info('RoseNet relay started'); | ||
}; | ||
|
||
export { startRelay }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { resolve as resolveTs } from 'ts-node/esm'; | ||
import * as tsConfigPaths from 'tsconfig-paths'; | ||
import { pathToFileURL } from 'url'; | ||
|
||
const { absoluteBaseUrl, paths } = tsConfigPaths.loadConfig(); | ||
const matchPath = tsConfigPaths.createMatchPath(absoluteBaseUrl, paths); | ||
|
||
export function resolve(specifier, ctx, defaultResolve) { | ||
const match = matchPath(specifier); | ||
return match | ||
? resolveTs(pathToFileURL(`${match}`).href, ctx, defaultResolve) | ||
: resolveTs(specifier, ctx, defaultResolve); | ||
} | ||
|
||
export { load, transformSource } from 'ts-node/esm'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"outDir": "./dist", | ||
"baseUrl": ".", | ||
}, | ||
"include": ["src"], | ||
"ts-node": { | ||
"esm": true, | ||
}, | ||
"references": [ | ||
{ | ||
"path": "../../packages/rosenet-relay", | ||
}, | ||
{ | ||
"path": "../../packages/utils", | ||
}, | ||
], | ||
} |