Skip to content

Commit

Permalink
Merge branch 'dev' into 'master'
Browse files Browse the repository at this point in the history
Dev

See merge request ergo/rosen-bridge/watcher!204
  • Loading branch information
vorujack committed Dec 21, 2023
2 parents 07415dc + 9bb7d36 commit 09772a1
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 2 deletions.
7 changes: 6 additions & 1 deletion services/watcher/config/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ observation:
confirmation: 60 # number of required block confirmations to create the commitment after observing an event
validThreshold: 4320 # observations that have not been triggered won't be processed after this period (in blocks)
cardano:
type: '' # options: koios, ogmios
type: '' # options: koios, ogmios, blockfrost
initial:
slot: -1 # initial block global slot, only used for ogmios
hash: '' # initial block hash, only used for ogmios
Expand All @@ -17,6 +17,11 @@ cardano:
host: '' # ogmios node host address
port: 1337 # ogmios port
useTls: false # connect to ogmios using https or not
blockfrost:
url: '' # url to connect to blockfrost
projectId: '' # blockfrost project Id
timeout: 10 # blockfrost request timeout
interval: 20 # blockfrost check timeout
ergo:
network: 'Mainnet' # ergo network type. testnet or mainnet
type: 'node' # ergo scanner type. options: node, explorer
Expand Down
16 changes: 16 additions & 0 deletions services/watcher/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,13 @@ class CardanoConfig {
interval: number;
authToken?: string;
};
blockfrost?: {
url?: string;
timeout: number;
initialHeight: number;
interval: number;
projectId: string;
};

constructor(network: string) {
this.type = config.get<string>('cardano.type');
Expand All @@ -297,6 +304,15 @@ class CardanoConfig {
? config.get<string>('cardano.koios.authToken')
: undefined;
this.koios = { url, initialHeight, interval, timeout, authToken };
} else if (this.type === Constants.BLOCK_FROST_TYPE) {
const url = config.has('cardano.blockfrost.url')
? getRequiredString('cardano.blockfrost.url')
: undefined;
const interval = getRequiredNumber('cardano.blockfrost.interval');
const timeout = getRequiredNumber('cardano.blockfrost.timeout');
const initialHeight = getRequiredNumber('cardano.initial.height');
const projectId = config.get<string>('cardano.blockfrost.projectId');
this.blockfrost = { url, timeout, initialHeight, interval, projectId };
} else {
throw new Error(
`Improperly configured. cardano configuration type is invalid available choices are '${Constants.OGMIOS_TYPE}', '${Constants.KOIOS_TYPE}'`
Expand Down
1 change: 1 addition & 0 deletions services/watcher/src/config/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const COMMITMENT_EXTRACTOR_NAME = 'watcher-commitment-extractor';
export const TRIGGER_EXTRACTOR_NAME = 'watcher-trigger-extractor';
export const OGMIOS_TYPE = 'ogmios';
export const KOIOS_TYPE = 'koios';
export const BLOCK_FROST_TYPE = 'blockfrost';
export const NODE_TYPE = 'node';
export const EXPLORER_TYPE = 'explorer';
export const ERGO_CHAIN_NAME = 'ergo';
Expand Down
6 changes: 6 additions & 0 deletions services/watcher/src/jobs/initScanner.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
CardanoBlockFrostScanner,
CardanoKoiosScanner,
CardanoOgmiosScanner,
GeneralScanner,
Expand Down Expand Up @@ -35,6 +36,11 @@ export const scannerInit = () => {
cardanoConfig.koios.interval,
scanner.observationScanner as CardanoKoiosScanner
).then(() => null);
} else if (cardanoConfig.blockfrost) {
scanningJob(
cardanoConfig.blockfrost.interval,
scanner.observationScanner as CardanoBlockFrostScanner
).then(() => null);
} else {
throw new Error(
`The observing network [${config.networkWatcher}] is not supported`
Expand Down
23 changes: 22 additions & 1 deletion services/watcher/src/utils/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import {
CardanoKoiosScanner,
CardanoOgmiosScanner,
ErgoNetworkType,
CardanoBlockFrostScanner,
} from '@rosen-bridge/scanner';
import {
ErgoObservationExtractor,
CardanoKoiosObservationExtractor,
CardanoOgmiosObservationExtractor,
CardanoBlockFrostObservationExtractor,
} from '@rosen-bridge/observation-extractor';
import {
CommitmentExtractor,
Expand Down Expand Up @@ -55,7 +57,11 @@ const logger = WinstonLogger.getInstance().getLogger(import.meta.url);

class CreateScanner {
ergoScanner: ErgoScanner;
observationScanner: ErgoScanner | CardanoKoiosScanner | CardanoOgmiosScanner;
observationScanner:
| ErgoScanner
| CardanoKoiosScanner
| CardanoOgmiosScanner
| CardanoBlockFrostScanner;

constructor() {
this.createErgoScanner();
Expand Down Expand Up @@ -184,6 +190,21 @@ class CreateScanner {
loggers.observationExtractorLogger
);
this.observationScanner.registerExtractor(observationExtractor);
} else if (cardanoConfig.blockfrost) {
this.observationScanner = new CardanoBlockFrostScanner({
dataSource,
initialHeight: cardanoConfig.blockfrost.initialHeight,
projectId: cardanoConfig.blockfrost.projectId,
timeout: cardanoConfig.blockfrost.timeout,
blockFrostUrl: cardanoConfig.blockfrost.url,
});
const observationExtractor = new CardanoBlockFrostObservationExtractor(
dataSource,
tokensConfig.tokens,
rosenConfig.lockAddress,
loggers.observationExtractorLogger
);
this.observationScanner.registerExtractor(observationExtractor);
}
}
};
Expand Down

0 comments on commit 09772a1

Please sign in to comment.