Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/silver-suns-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rosen-bridge/watcher': minor
---

Integrate Handshake watcher
10 changes: 10 additions & 0 deletions config/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ firo:
timeout: 10 # rpc request timeout (in seconds)
# username: '' # rpc username for authentication required instances
# password: '' # rpc password for authentication required instances
handshake:
type: 'rpc' # options: rpc
initial:
height: -1 # initial height of scanning
interval: 180 # scanning interval (in seconds)
rpc:
url: '' # rpc url
timeout: 10 # rpc request timeout (in seconds)
# username: '' # rpc username for authentication required instances
# password: '' # rpc password for authentication required instances
ergo:
network: 'Mainnet' # ergo network type. testnet or mainnet
type: 'node' # ergo scanner type. options: node, explorer
Expand Down
4 changes: 4 additions & 0 deletions docker/custom-environment-variables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ firo:
rpc:
username: 'FIRO_RPC_USERNAME'
password: 'FIRO_RPC_PASSWORD'
handshake:
rpc:
username: 'HANDSHAKE_RPC_USERNAME'
password: 'HANDSHAKE_RPC_PASSWORD'
overrideLokiBasicAuth: 'OVERRIDE_LOKI_BASIC_AUTH'
36 changes: 36 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@
"@rosen-bridge/extended-typeorm": "1.1.0",
"@rosen-bridge/firo-observation-extractor": "^1.0.1",
"@rosen-bridge/firo-scanner": "^0.1.2",
"@rosen-bridge/handshake-observation-extractor": "^1.0.1",
"@rosen-bridge/handshake-scanner": "^0.1.2",
"@rosen-bridge/health-check": "^8.0.0",
"@rosen-bridge/json-bigint": "^1.1.0",
"@rosen-bridge/log-level-check": "^4.0.0",
Expand Down
63 changes: 50 additions & 13 deletions src/config/config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { ErgoNetworkType } from '@rosen-bridge/scanner-interfaces';
import { TransportOptions } from '@rosen-bridge/winston-logger';
import { RateLimitedAxiosConfig } from '@rosen-clients/rate-limited-axios';
import { generateMnemonic } from 'bip39';
import config from 'config';
import * as wasm from 'ergo-lib-wasm-nodejs';
import { SecretError } from '../errors/errors';
import * as Constants from './constants';
import { RosenConfig } from './rosenConfig';
import { cloneDeep } from 'lodash-es';
import { SecretError } from '../errors/errors';
import { NetworkType } from '../types';
import { generateMnemonic } from 'bip39';
import { convertMnemonicToSecretKey } from '../utils/utils';
import { ErgoNetworkType } from '@rosen-bridge/scanner-interfaces';
import { TransportOptions } from '@rosen-bridge/winston-logger';
import { RateLimitedAxiosConfig } from '@rosen-clients/rate-limited-axios';
import * as Constants from './constants';
import { RosenConfig } from './rosenConfig';

const supportedNetworks: Array<NetworkType> = [
Constants.ERGO_CHAIN_NAME,
Expand All @@ -19,6 +19,7 @@ const supportedNetworks: Array<NetworkType> = [
Constants.DOGE_CHAIN_NAME,
Constants.ETHEREUM_CHAIN_NAME,
Constants.BINANCE_CHAIN_NAME,
Constants.HANDSHAKE_CHAIN_NAME,
Constants.FIRO_CHAIN_NAME,
];

Expand All @@ -31,6 +32,7 @@ interface ConfigType {
binance: BinanceConfig;
firo: FiroConfig;
doge: DogeConfig;
handshake: HandshakeConfig;
general: Config;
rosen: RosenConfig;
database: DatabaseConfig;
Expand Down Expand Up @@ -239,6 +241,7 @@ class Config {
[Constants.ETHEREUM_CHAIN_NAME]: Constants.ETHEREUM_BLOCK_TIME,
[Constants.DOGE_CHAIN_NAME]: Constants.DOGE_BLOCK_TIME,
[Constants.FIRO_CHAIN_NAME]: Constants.FIRO_BLOCK_TIME,
[Constants.HANDSHAKE_CHAIN_NAME]: Constants.HANDSHAKE_BLOCK_TIME,
}[this.networkWatcher];
this.observationValidThreshold = Math.floor(
getRequiredNumber('observation.validThreshold') / blockTime
Expand Down Expand Up @@ -639,6 +642,37 @@ class FiroConfig {
}
}

class HandshakeConfig {
type: string;
initialHeight: number;
interval: number;
rpc?: {
url: string;
timeout: number;
username?: string;
password?: string;
};

constructor(network: string) {
this.type = config.get<string>('handshake.type');
if (network === Constants.HANDSHAKE_CHAIN_NAME) {
this.initialHeight = getRequiredNumber('handshake.initial.height');
this.interval = getRequiredNumber('handshake.interval');
if (this.type == Constants.RPC_TYPE) {
const url = getRequiredString('handshake.rpc.url');
const timeout = getRequiredNumber('handshake.rpc.timeout');
const username = getOptionalString('handshake.rpc.username', undefined);
const password = getOptionalString('handshake.rpc.password', undefined);
this.rpc = { url, timeout, username, password };
} else {
throw new Error(
`Improperly configured. handshake configuration type is invalid available choices are '${Constants.RPC_TYPE}'`
);
}
}
}
}

class DatabaseConfig {
type: string;
path = '';
Expand Down Expand Up @@ -749,6 +783,7 @@ const getConfig = (): ConfigType => {
const doge = new DogeConfig(general.networkWatcher);
const ethereum = new EthereumConfig(general.networkWatcher);
const binance = new BinanceConfig(general.networkWatcher);
const handshake = new HandshakeConfig(general.networkWatcher);
const firo = new FiroConfig(general.networkWatcher);
const rosen = new RosenConfig(
general.networkWatcher,
Expand All @@ -764,6 +799,7 @@ const getConfig = (): ConfigType => {
doge,
ethereum,
binance,
handshake,
firo,
logger,
general,
Expand All @@ -777,14 +813,15 @@ const getConfig = (): ConfigType => {
};

export {
getConfig,
Config,
RosenConfig,
CardanoConfig,
BinanceConfig,
BitcoinConfig,
BitcoinRunesConfig,
CardanoConfig,
Config,
DogeConfig,
EthereumConfig,
BinanceConfig,
FiroConfig,
DogeConfig,
getConfig,
HandshakeConfig,
RosenConfig,
};
2 changes: 2 additions & 0 deletions src/config/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const BITCOIN_RUNES_CHAIN_NAME = 'bitcoin-runes';
export const DOGE_CHAIN_NAME = 'doge';
export const ETHEREUM_CHAIN_NAME = 'ethereum';
export const BINANCE_CHAIN_NAME = 'binance';
export const HANDSHAKE_CHAIN_NAME = 'handshake';
export const FIRO_CHAIN_NAME = 'firo';
export const ERGO_NATIVE_ASSET = 'erg';
export const ERGO_DECIMALS = 9;
Expand All @@ -34,6 +35,7 @@ export const CARDANO_BLOCK_TIME = 20;
export const ERGO_BLOCK_TIME = 120;
export const ETHEREUM_BLOCK_TIME = 12;
export const DOGE_BLOCK_TIME = 60;
export const HANDSHAKE_BLOCK_TIME = 600;
export const FIRO_BLOCK_TIME = 150;
export const UNISAT_TYPE = 'unisat';
export const ORDISCAN_TYPE = 'ordiscan';
13 changes: 10 additions & 3 deletions src/jobs/initScanner.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { DefaultLogger } from '@rosen-bridge/abstract-logger';
import { GeneralScanner } from '@rosen-bridge/abstract-scanner';
import { CardanoOgmiosScanner } from '@rosen-bridge/cardano-scanner';
import * as Constants from '../config/constants';
import { getConfig } from '../config/config';
import { DefaultLogger } from '@rosen-bridge/abstract-logger';
import { EvmRpcScanner } from '@rosen-bridge/evm-scanner';
import { getConfig } from '../config/config';
import * as Constants from '../config/constants';
import { CreateScanner } from '../utils/scanner';

const allConfig = getConfig();
Expand All @@ -15,6 +15,7 @@ const {
doge: dogeConfig,
ethereum: ethereumConfig,
binance: binanceConfig,
handshake: handshakeConfig,
firo: firoConfig,
} = allConfig;

Expand Down Expand Up @@ -87,6 +88,12 @@ export const scannerInit = () => {
scanner.getObservationScanner() as GeneralScanner<unknown>
).then(() => null);
break;
case Constants.HANDSHAKE_CHAIN_NAME:
scanningJob(
handshakeConfig.interval,
scanner.getObservationScanner() as GeneralScanner<unknown>
).then(() => null);
break;
case Constants.ERGO_CHAIN_NAME:
break;
default:
Expand Down
3 changes: 2 additions & 1 deletion src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type NetworkType =
| typeof Constants.DOGE_CHAIN_NAME
| typeof Constants.ETHEREUM_CHAIN_NAME
| typeof Constants.BINANCE_CHAIN_NAME
| typeof Constants.FIRO_CHAIN_NAME;
| typeof Constants.FIRO_CHAIN_NAME
| typeof Constants.HANDSHAKE_CHAIN_NAME;

export { NetworkType };
Loading
Loading