-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #107 from ckb-cell/develop
Merge develop into main branch (20240812)
- Loading branch information
Showing
37 changed files
with
10,707 additions
and
8,210 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 |
---|---|---|
|
@@ -61,3 +61,6 @@ jobs: | |
cat .env | ||
pnpm run test | ||
working-directory: backend | ||
|
||
- name: Docker Build Test | ||
run: docker compose build |
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,29 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { HealthIndicator, HealthIndicatorResult, HealthCheckError } from '@nestjs/terminus'; | ||
import { InjectSentry, SentryService } from '@ntegral/nestjs-sentry'; | ||
import { BitcoinApiService } from './bitcoin-api.service'; | ||
|
||
@Injectable() | ||
export class BitcoinApiHealthIndicator extends HealthIndicator { | ||
constructor( | ||
private bitcoinApiService: BitcoinApiService, | ||
@InjectSentry() private sentryService: SentryService, | ||
) { | ||
super(); | ||
} | ||
|
||
public async isHealthy(): Promise<HealthIndicatorResult> { | ||
try { | ||
const info = await this.bitcoinApiService.getBlockchainInfo(); | ||
const isHealthy = !!info.blocks; | ||
const result = this.getStatus('bitcoin-api', isHealthy, { info }); | ||
if (isHealthy) { | ||
return result; | ||
} | ||
throw new HealthCheckError('BitcoinApiService failed', result); | ||
} catch (e) { | ||
this.sentryService.instance().captureException(e); | ||
throw new HealthCheckError('BitcoinApiService failed', e); | ||
} | ||
} | ||
} |
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,31 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { HealthIndicator, HealthIndicatorResult, HealthCheckError } from '@nestjs/terminus'; | ||
import { InjectSentry, SentryService } from '@ntegral/nestjs-sentry'; | ||
import { CkbExplorerService } from './ckb-explorer.service'; | ||
|
||
@Injectable() | ||
export class CkbExplorerHealthIndicator extends HealthIndicator { | ||
constructor( | ||
private ckbExplorerService: CkbExplorerService, | ||
@InjectSentry() private sentryService: SentryService, | ||
) { | ||
super(); | ||
} | ||
|
||
public async isHealthy(): Promise<HealthIndicatorResult> { | ||
try { | ||
const stats = await this.ckbExplorerService.getStatistics(); | ||
const isHealthy = !!stats.data.attributes.tip_block_number; | ||
const result = this.getStatus('ckb-explorer', isHealthy, { | ||
stats: stats.data.attributes, | ||
}); | ||
if (isHealthy) { | ||
return result; | ||
} | ||
throw new HealthCheckError('CkbExplorerService failed', result); | ||
} catch (e) { | ||
this.sentryService.instance().captureException(e); | ||
throw new HealthCheckError('CkbExplorerService failed', e); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,10 +1,11 @@ | ||
import { forwardRef, Module } from '@nestjs/common'; | ||
import { CkbExplorerService } from './ckb-explorer.service'; | ||
import { CkbRpcModule } from '../ckb-rpc/ckb-rpc.module'; | ||
import { CkbExplorerHealthIndicator } from './ckb-explorer.health'; | ||
|
||
@Module({ | ||
imports: [forwardRef(() => CkbRpcModule)], | ||
providers: [CkbExplorerService], | ||
exports: [CkbExplorerService], | ||
providers: [CkbExplorerService, CkbExplorerHealthIndicator], | ||
exports: [CkbExplorerService, CkbExplorerHealthIndicator], | ||
}) | ||
export class CkbExplorerModule {} |
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,57 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { HealthIndicator, HealthIndicatorResult, HealthCheckError } from '@nestjs/terminus'; | ||
import { CkbRpcWebsocketService } from './ckb-rpc-websocket.service'; | ||
import { InjectSentry, SentryService } from '@ntegral/nestjs-sentry'; | ||
|
||
export enum CkbRpcHealthIndicatorKey { | ||
Websocket = 'ckb-rpc-websocket', | ||
} | ||
|
||
@Injectable() | ||
export class CkbRpcHealthIndicator extends HealthIndicator { | ||
constructor( | ||
private ckbRpcWebsocketService: CkbRpcWebsocketService, | ||
@InjectSentry() private sentryService: SentryService, | ||
) { | ||
super(); | ||
} | ||
|
||
public async isHealthy(key: CkbRpcHealthIndicatorKey): Promise<HealthIndicatorResult> { | ||
try { | ||
let isHealthy = false; | ||
let result: HealthIndicatorResult = {}; | ||
|
||
switch (key) { | ||
case CkbRpcHealthIndicatorKey.Websocket: | ||
const { isHealthy: websocketIsHealthy, result: websocketResult } = | ||
await this.isWebsocketHealthy(); | ||
isHealthy = websocketIsHealthy; | ||
result = websocketResult; | ||
break; | ||
default: | ||
throw new HealthCheckError(`Unknown health indicator key`, key); | ||
} | ||
|
||
if (isHealthy) { | ||
return result; | ||
} | ||
throw new HealthCheckError('CkbRpcWebsocketService failed', result); | ||
} catch (e) { | ||
this.sentryService.instance().captureException(e); | ||
throw new HealthCheckError('CkbRpcWebsocketService failed', e); | ||
} | ||
} | ||
|
||
private async isWebsocketHealthy(): Promise<{ | ||
isHealthy: boolean; | ||
result: HealthIndicatorResult; | ||
}> { | ||
const tipBlockNumber = await this.ckbRpcWebsocketService.getTipBlockNumber(); | ||
const isHealthy = !!tipBlockNumber; | ||
const result = this.getStatus('ckb-rpc.websocket', isHealthy, { tipBlockNumber }); | ||
return { | ||
isHealthy, | ||
result, | ||
}; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { CkbRpcHealthIndicator } from './ckb-rpc.health'; | ||
import { CkbRpcWebsocketService } from './ckb-rpc-websocket.service'; | ||
|
||
@Module({ | ||
providers: [CkbRpcWebsocketService], | ||
exports: [CkbRpcWebsocketService], | ||
providers: [CkbRpcWebsocketService, CkbRpcHealthIndicator], | ||
exports: [CkbRpcWebsocketService, CkbRpcHealthIndicator], | ||
}) | ||
export class CkbRpcModule {} |
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,27 @@ | ||
import { Controller, Get } from '@nestjs/common'; | ||
import { HealthCheckService, HealthCheck, HttpHealthIndicator } from '@nestjs/terminus'; | ||
import { CkbRpcHealthIndicator, CkbRpcHealthIndicatorKey } from '../ckb-rpc/ckb-rpc.health'; | ||
import { BitcoinApiHealthIndicator } from '../bitcoin-api/bitcoin-api.health'; | ||
import { CkbExplorerHealthIndicator } from '../ckb-explorer/ckb-explorer.health'; | ||
|
||
@Controller('health') | ||
export class HealthController { | ||
constructor( | ||
private health: HealthCheckService, | ||
private http: HttpHealthIndicator, | ||
private bitcoinApiHealthIndicator: BitcoinApiHealthIndicator, | ||
private ckbRpcHealthIndicator: CkbRpcHealthIndicator, | ||
private ckbExplorerHealthIndicator: CkbExplorerHealthIndicator, | ||
) {} | ||
|
||
@Get() | ||
@HealthCheck() | ||
check() { | ||
return this.health.check([ | ||
() => this.http.pingCheck('graphql', 'http://localhost:3000/graphql'), | ||
() => this.bitcoinApiHealthIndicator.isHealthy(), | ||
() => this.ckbRpcHealthIndicator.isHealthy(CkbRpcHealthIndicatorKey.Websocket), | ||
() => this.ckbExplorerHealthIndicator.isHealthy(), | ||
]); | ||
} | ||
} |
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 { Module } from '@nestjs/common'; | ||
import { TerminusModule } from '@nestjs/terminus'; | ||
import { HealthController } from './health.controller'; | ||
import { CkbRpcModule } from '../ckb-rpc/ckb-rpc.module'; | ||
import { CkbExplorerModule } from '../ckb-explorer/ckb-explorer.module'; | ||
import { BitcoinApiModule } from '../bitcoin-api/bitcoin-api.module'; | ||
import { HttpModule } from '@nestjs/axios'; | ||
|
||
@Module({ | ||
imports: [TerminusModule, HttpModule, BitcoinApiModule, CkbRpcModule, CkbExplorerModule], | ||
providers: [HealthController], | ||
controllers: [HealthController], | ||
}) | ||
export class HealthModule {} |
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
Oops, something went wrong.
1b7ae41
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
utxo-stack-explorer – ./
utxo-stack-explorer-cell-studio.vercel.app
explorer.utxostack.network
utxo-stack-explorer-git-main-cell-studio.vercel.app
utxo-stack-explorer.vercel.app
explorer.rgbpp.io