Skip to content

Commit

Permalink
Merge pull request #30 from ckb-cell/develop
Browse files Browse the repository at this point in the history
Merge develop into main branch
  • Loading branch information
Vibes-INS authored Aug 5, 2024
2 parents cc9c392 + b751a08 commit a8d1ace
Show file tree
Hide file tree
Showing 155 changed files with 3,783 additions and 1,426 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/backend-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ name: Backend Deploy

on:
push:
branches: [main, deploy-testnet]
branches: [develop]
paths:
- backend/**
workflow_dispatch:

jobs:
Expand All @@ -11,7 +13,7 @@ jobs:
name: testnet
url: https://testnet-api.explorer.rgbpp.io/graphql
runs-on: ubuntu-latest

steps:
- name: Deploy to testnet
uses: appleboy/[email protected]
Expand All @@ -22,8 +24,8 @@ jobs:
script: |
cd ${{ secrets.SSH_WORK_DIR }}
git status
git fetch origin main
git checkout origin/main
git fetch origin
git checkout ${{ github.sha }}
git status
echo ${{ secrets.SSH_PASSWORD }} | sudo -S docker compose ps
echo ${{ secrets.SSH_PASSWORD }} | sudo -S docker image prune -f
Expand Down
63 changes: 63 additions & 0 deletions .github/workflows/backend-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Backend Test

on:
pull_request:
paths:
- backend/**
push:
branches: [main, develop]
paths:
- backend/**

jobs:
build:
runs-on: ubuntu-latest

services:
redis:
image: redis
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: 'true'

- name: Install PNPM
uses: pnpm/action-setup@v3
with:
version: 8

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '21'
cache: 'pnpm'

- uses: pnpm/action-setup@v4
- name: Install dependency
run: pnpm install

- name: Run Build
run: pnpm run build
working-directory: backend

- name: Run Test
run: |
touch .env
echo BITCOIN_PRIMARY_DATA_PROVIDER="${{ secrets.BITCOIN_PRIMARY_DATA_PROVIDER }}" >> .env
echo BITCOIN_MEMPOOL_SPACE_API_URL="${{ secrets.BITCOIN_MEMPOOL_SPACE_API_URL }}" >> .env
echo BITCOIN_ELECTRS_API_URL="{{ secrets.BITCOIN_ELECTRS_API_URL }}" >> .env
echo CKB_EXPLORER_API_URL="${{ secrets.CKB_EXPLORER_API_URL }}" >> .env
echo CKB_RPC_WEBSOCKET_URL="${{ secrets.CKB_RPC_WEBSOCKET_URL }}" >> .env
echo REDIS_URL="redis://localhost:6379" >> .env
cat .env
pnpm run test
working-directory: backend
9 changes: 7 additions & 2 deletions .github/workflows/frontend-lint.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
name: Frontend Linter

on: [pull_request, push]

on:
pull_request:
paths:
- frontend/**
push:
paths:
- frontend/**

jobs:
build:
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/frontend-spell-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: Frontend Spell Check

on:
push:
paths:
- frontend/**

jobs:
spellcheck:
Expand All @@ -26,4 +28,4 @@ jobs:

- name: Run Check
run: npx cspell "**/*"
working-directory: frontend
working-directory: frontend
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ COPY . /app
WORKDIR /app

FROM base AS prod-deps
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile --ignore-scripts
RUN pnpm run --filter backend postinstall

FROM base as build
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
RUN pnpm run --filter backend build
RUN pnpm run --filter backend build

FROM base
ENV NODE_ENV production
Expand Down
15 changes: 10 additions & 5 deletions backend/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ module.exports = {
tsconfigRootDir: __dirname,
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
plugins: ['@typescript-eslint/eslint-plugin', 'import'],
extends: ['plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended'],
root: true,
env: {
node: true,
Expand All @@ -21,5 +18,13 @@ module.exports = {
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'no-restricted-imports': [
'error',
{
name: 'nestjs-cacheable',
importNames: ['Cacheable'],
message: "Please use 'src/decorators/cacheable.decorator' instead",
},
],
},
};
1 change: 1 addition & 0 deletions backend/.husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npm
28 changes: 20 additions & 8 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,20 @@
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json",
"postinstall": "npx prisma generate"
"postinstall": "npx prisma generate",
"precommit": "lint-staged",
"prepare": "husky"
},
"lint-staged": {
"*.ts": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix"
},
"dependencies": {
"@applifting-io/nestjs-dataloader": "^1.1.5",
"@cell-studio/mempool.js": "^2.4.0",
"@ckb-lumos/bi": "^0.23.0",
"@ckb-lumos/lumos": "^0.23.0",
"@ckb-lumos/rpc": "^0.23.0",
"@nestjs/bullmq": "^10.2.0",
"@nestjs/cache-manager": "^2.2.2",
"@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.2.3",
Expand All @@ -37,12 +43,13 @@
"@nestjs/schedule": "^4.1.0",
"@ntegral/nestjs-sentry": "^4.0.1",
"@prisma/client": "^5.16.2",
"@rgbpp-sdk/btc": "^0.0.0-snap-20240727021715",
"@rgbpp-sdk/ckb": "^0.0.0-snap-20240727021715",
"@sentry/node": "^8.17.0",
"@sentry/profiling-node": "^8.17.0",
"@rgbpp-sdk/btc": "^0.5.0",
"@rgbpp-sdk/ckb": "^0.5.0",
"@sentry/node": "^7.116.0",
"@sentry/profiling-node": "^7.116.0",
"@types/ws": "^8.5.11",
"axios": "^1.7.2",
"bullmq": "^5.11.0",
"cache-manager": "^5.2.3",
"cache-manager-redis-yet": "^4.1.2",
"dataloader": "^2.2.2",
Expand All @@ -63,18 +70,21 @@
"devDependencies": {
"@nestjs/cli": "^10.0.0",
"@nestjs/schematics": "^10.0.0",
"@nestjs/testing": "^10.0.0",
"@nestjs/testing": "^10.3.10",
"@types/express": "^4.17.17",
"@types/jest": "^29.5.2",
"@types/lodash": "^4.17.7",
"@types/node": "^20.3.1",
"@types/serialize-javascript": "^5.0.4",
"@types/supertest": "^6.0.0",
"@typescript-eslint/eslint-plugin": "^7.0.0",
"@typescript-eslint/parser": "^7.0.0",
"eslint": "^8.42.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"husky": "^9.1.4",
"jest": "^29.5.0",
"lint-staged": "^15.2.7",
"prettier": "^3.0.0",
"prisma": "^5.16.2",
"source-map-support": "^0.5.21",
Expand All @@ -92,8 +102,10 @@
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"modulePaths": [
"."
],
"testRegex": ".*\\.(spec|test)\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
Expand Down
36 changes: 23 additions & 13 deletions backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,24 @@ import { SentryInterceptor, SentryModule } from '@ntegral/nestjs-sentry';
import { nodeProfilingIntegration } from '@sentry/profiling-node';
import type { RedisClientOptions } from 'redis';
import { redisStore } from 'cache-manager-redis-yet';
import { Env, envSchema } from './env';
import { Env } from './env';
import { CoreModule } from './core/core.module';
import { ApiModule } from './modules/api.module';
import { CacheableModule } from 'nestjs-cacheable';
import { ScheduleModule } from '@nestjs/schedule';
import { BullModule } from '@nestjs/bullmq';
import configModule from './config';

@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true,
envFilePath:
process.env.NODE_ENV === 'production'
? ['.env.production.local', '.env.production', '.env']
: ['.env.development.local', '.env.development', '.env'],
validate: envSchema.parse,
}),
configModule,
SentryModule.forRootAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService<Env>) => ({
dsn: configService.get('SENTRY_DSN'),
environment: configService.get('NODE_ENV'),
tracesSampleRate: 0.1,
profilesSampleRate: 0.1,
tracesSampleRate: 0.5,
profilesSampleRate: 0.5,
integrations: [nodeProfilingIntegration()],
logLevels:
configService.get('NODE_ENV') === 'production'
Expand All @@ -42,15 +37,30 @@ import { ScheduleModule } from '@nestjs/schedule';
isGlobal: true,
imports: [ConfigModule],
useFactory: async (configService: ConfigService<Env>) => {
const store = await redisStore({
const store = (await redisStore({
url: configService.get('REDIS_URL'),
}) as unknown as CacheStore;
})) as unknown as CacheStore;
return {
store,
};
},
inject: [ConfigService],
}),
BullModule.forRootAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService<Env>) => {
const url = new URL(configService.get('REDIS_URL')!);
return {
connection: {
host: url.hostname,
port: parseInt(url.port),
username: url.username,
password: url.password,
},
};
},
inject: [ConfigService],
}),
ScheduleModule.forRoot(),
CoreModule,
ApiModule,
Expand Down
2 changes: 2 additions & 0 deletions backend/src/common/date.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export const ONE_MONTH_MS = 30 * 24 * 60 * 60 * 1000;
export const ONE_HOUR_MS = 60 * 60 * 1000;
export const TEN_MINUTES_MS = 10 * 60 * 1000;
export const ONE_MINUTE_MS = 60 * 1000;
13 changes: 13 additions & 0 deletions backend/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ConfigModule } from '@nestjs/config';
import { envSchema } from './env';

const configModule = ConfigModule.forRoot({
isGlobal: true,
envFilePath:
process.env.NODE_ENV === 'production'
? ['.env.production.local', '.env.production', '.env']
: ['.env.development.local', '.env.development', '.env'],
validate: envSchema.parse,
});

export default configModule;
2 changes: 2 additions & 0 deletions backend/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ export const BtcTestnetTypeMap: Record<NetworkType.testnet | NetworkType.signet,
[NetworkType.testnet]: 'Testnet3',
[NetworkType.signet]: 'Signet',
};

export const CKB_MIN_SAFE_CONFIRMATIONS = 24;
4 changes: 3 additions & 1 deletion backend/src/core/bitcoin-api/bitcoin-api.interface.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Address, Block, OutSpend, RecommendedFees, Transaction, UTXO } from './bitcoin-api.schema';

export { Address, Block, OutSpend, RecommendedFees, Transaction, UTXO };

export interface IBitcoinDataProvider {
getFeesRecommended(): Promise<RecommendedFees>;
getAddress(props: { address: string }): Promise<Address>;
Expand All @@ -10,7 +12,7 @@ export interface IBitcoinDataProvider {
getTxOutSpend(props: { txid: string; vout: number }): Promise<OutSpend>;
getTxOutSpends(props: { txid: string }): Promise<OutSpend[]>;
getBlock(props: { hash: string }): Promise<Block>;
getBlockTxs(props: { hash: string; startIndex: number }): Promise<Transaction[]>;
getBlockTxs(props: { hash: string; startIndex?: number }): Promise<Transaction[]>;
getBlockHeight(props: { height: number }): Promise<string>;
getBlockHeader(props: { hash: string }): Promise<string>;
getBlockTxids(props: { hash: string }): Promise<string[]>;
Expand Down
Loading

1 comment on commit a8d1ace

@vercel
Copy link

@vercel vercel bot commented on a8d1ace Aug 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.