-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'binance-scanner' into 'dev'
Binance scanner Closes #463 See merge request ergo/rosen-bridge/ui!386
- Loading branch information
Showing
9 changed files
with
163 additions
and
11 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,5 @@ | ||
--- | ||
'@rosen-bridge/rosen-service': minor | ||
--- | ||
|
||
Add binance chain scanner with observation and event trigger extractors |
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
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,41 @@ | ||
import { BinanceRpcObservationExtractor } from '@rosen-bridge/evm-observation-extractor'; | ||
import { EvmRpcScanner } from '@rosen-bridge/evm-rpc-scanner'; | ||
import WinstonLogger from '@rosen-bridge/winston-logger'; | ||
|
||
import config from '../../configs'; | ||
import dataSource from '../../data-source'; | ||
import AppError from '../../errors/AppError'; | ||
import { getRosenTokens } from '../../utils'; | ||
|
||
const logger = WinstonLogger.getInstance().getLogger(import.meta.url); | ||
|
||
/** | ||
* register an observation extractor for the provided scanner | ||
* @param scanner | ||
*/ | ||
export const registerBinanceExtractor = (scanner: EvmRpcScanner) => { | ||
try { | ||
const observationExtractor = new BinanceRpcObservationExtractor( | ||
config.binance.addresses.lock, | ||
dataSource, | ||
getRosenTokens(), | ||
logger | ||
); | ||
|
||
scanner.registerExtractor(observationExtractor); | ||
|
||
logger.debug('binance observation extractor registered', { | ||
scannerName: scanner.name(), | ||
}); | ||
} catch (error) { | ||
throw new AppError( | ||
`cannot create or register binance observation extractor due to error: ${error}`, | ||
false, | ||
'error', | ||
error instanceof Error ? error.stack : undefined, | ||
{ | ||
scannerName: scanner.name(), | ||
} | ||
); | ||
} | ||
}; |
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,53 @@ | ||
import { EvmRpcScanner } from '@rosen-bridge/evm-rpc-scanner'; | ||
import WinstonLogger from '@rosen-bridge/winston-logger'; | ||
|
||
import config from '../../configs'; | ||
import { | ||
BINANCE_SCANNER_INTERVAL, | ||
BINANCE_SCANNER_LOGGER_NAME, | ||
SCANNER_API_TIMEOUT, | ||
} from '../../constants'; | ||
import dataSource from '../../data-source'; | ||
import AppError from '../../errors/AppError'; | ||
import observationService from '../../observation/observation-service'; | ||
import { startScanner } from '../scanner-utils'; | ||
|
||
const logger = WinstonLogger.getInstance().getLogger(import.meta.url); | ||
const scannerLogger = WinstonLogger.getInstance().getLogger( | ||
BINANCE_SCANNER_LOGGER_NAME | ||
); | ||
|
||
/** | ||
* create a binance scanner, initializing it and calling its update method | ||
* periodically | ||
*/ | ||
export const startBinanceScanner = async () => { | ||
try { | ||
const scanner = new EvmRpcScanner( | ||
'binance', | ||
{ | ||
RpcUrl: config.binance.rpcUrl, | ||
dataSource, | ||
initialHeight: config.binance.initialHeight, | ||
timeout: SCANNER_API_TIMEOUT, | ||
}, | ||
scannerLogger, | ||
config.binance.rpcAuthToken | ||
); | ||
|
||
observationService.registerBinanceExtractor(scanner); | ||
|
||
await startScanner(scanner, import.meta.url, BINANCE_SCANNER_INTERVAL); | ||
|
||
logger.debug('binance scanner started'); | ||
|
||
return scanner; | ||
} catch (error) { | ||
throw new AppError( | ||
`cannot create or start binance scanner due to error: ${error}`, | ||
false, | ||
'error', | ||
error instanceof Error ? error.stack : undefined | ||
); | ||
} | ||
}; |
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