Skip to content

Commit

Permalink
Merge pull request #198 from ckb-cell/develop
Browse files Browse the repository at this point in the history
Merge develop to main branch (v2.4.0)
  • Loading branch information
Flouse authored Jul 19, 2024
2 parents ac342eb + 2e9609b commit 2794960
Show file tree
Hide file tree
Showing 36 changed files with 10,473 additions and 208 deletions.
19 changes: 17 additions & 2 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ on:
- completed

jobs:
deploy:
deploy-testnet:
runs-on: ubuntu-latest

steps:
- name: Deploy
- name: Deploy Testnet
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.SSH_HOST }}
Expand All @@ -26,3 +26,18 @@ jobs:
cd ${{ secrets.SSH_WORK_DIR }}
echo ${{ secrets.PACKAGE_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin
bash ./update.sh
deploy-signet:
runs-on: ubuntu-latest

steps:
- name: Deploy Signet
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.SSH_HOST_SIGNET }}
username: ${{ secrets.SSH_USERNAME_SIGNET }}
password: ${{ secrets.PASSWORD }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd ${{ secrets.SSH_WORK_DIR_SIGNET }}
echo ${{ secrets.PACKAGE_TOKEN }} | sudo docker login ghcr.io -u ${{ github.actor }} --password-stdin
bash ./update.sh
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ jobs:
BITCOIN_MEMPOOL_SPACE_API_URL: ${{ secrets.BITCOIN_MEMPOOL_SPACE_API_URL }}
BITCOIN_ELECTRS_API_URL: ${{ secrets.BITCOIN_ELECTRS_API_URL }}
BITCOIN_SPV_SERVICE_URL: ${{ secrets.BITCOIN_SPV_SERVICE_URL }}
PAYMASTER_PRIVATE_KEY: ${{ secrets.PAYMASTER_PRIVATE_KEY }}
PAYMASTER_RECEIVE_BTC_ADDRESS: ${{ secrets.PAYMASTER_RECEIVE_BTC_ADDRESS }}
CKB_RPC_URL: ${{ secrets.CKB_RPC_URL }}
CKB_INDEXER_URL: ${{ secrets.CKB_INDEXER_URL }}
PAYMASTER_PRIVATE_KEY: ${{ secrets.PAYMASTER_PRIVATE_KEY }}
REDIS_URL: redis://localhost:6379
CI_REDIS_URL: redis://localhost:6379
run: pnpm test
34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,38 @@ A service for Retrieving BTC/RGB++ information/assets and processing transaction
- Transaction Handling by posting transactions to the /bitcoin/v1/transaction or /rgbpp/v1/transaction/ckb-tx endpoint
- RGB++ CKB transaction Queue simplifies the RGB++ assets workflows by some cron jobs

## Get started

We provide APIs for testnet and signet for use.

- Testnet: [https://api.testnet.rgbpp.io](https://api.testnet.rgbpp.io/docs)
- Signet: [https://api.signet.rgbpp.io](https://api.signet.rgbpp.io/docs)

For mainnet, API is currently limited to verified apps only.
You can also check the [Deployment](#Deployment) section to deploy your own.

### Get an access token

#### Testnet

You can get a testnet access token through the [/token/generate](https://api.testnet.rgbpp.io/docs/static/index.html#/Token/post_token_generate) API directly.

### Signet

And you can get an access token of BTC Signet network through the [/token/generate](https://api.signet.rgbpp.io/docs/static/index.html#/Token/post_token_generate) API directly.

#### Mainnet

The mainnet is currently limited to verified apps only.

When your app development is ready on testnet, and requires a mainnet access token,
please email us at f@cell.studio to request a mainnet JWT token.

In the email, please provide the following information about your app:

- `name`: Your app name, e.g. "rgbpp-app"
- `domain`: Your app domain, e.g. "rgbpp.app" (without protocol prefix and port suffix)

### Deployment

#### Requirements
Expand Down Expand Up @@ -111,4 +143,4 @@ Use the provided `docker-compose.yml` file to run the service:
docker-compose up
```

after the service is running, you can access the API documentation at `http://localhost:3000/docs`
After the service is running, you can access the API documentation at `http://localhost:3000/docs`
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "btc-assets-api",
"version": "2.3.1",
"version": "2.4.0",
"title": "Bitcoin/RGB++ Assets API",
"description": "",
"main": "index.js",
Expand Down Expand Up @@ -42,9 +42,9 @@
"@fastify/swagger-ui": "^3.0.0",
"@immobiliarelabs/fastify-sentry": "^8.0.1",
"@nervosnetwork/ckb-sdk-utils": "^0.109.1",
"@rgbpp-sdk/btc": "^0.1.0",
"@rgbpp-sdk/ckb": "^0.1.0",
"@rgbpp-sdk/service": "^0.1.0",
"@rgbpp-sdk/btc": "^0.4.0",
"@rgbpp-sdk/ckb": "^0.4.0",
"@rgbpp-sdk/service": "^0.4.0",
"@sentry/node": "^7.102.1",
"@sentry/profiling-node": "^7.102.1",
"async-retry": "^1.3.3",
Expand Down
31 changes: 16 additions & 15 deletions pnpm-lock.yaml

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

10 changes: 9 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import { isAdminMode } from './env';
import { BTCTestnetType } from '@rgbpp-sdk/ckb';

export enum NetworkType {
mainnet = 'prod',
mainnet = 'mainnet',
testnet = 'testnet',
signet = 'signet',
}

export const TestnetTypeMap: Record<NetworkType, BTCTestnetType | undefined> = {
[NetworkType.mainnet]: undefined,
[NetworkType.testnet]: 'Testnet3',
[NetworkType.signet]: 'Signet',
};

export const CUSTOM_HEADERS = {
ApiCache: 'x-api-cache',
ResponseCacheable: 'x-response-cacheable',
Expand Down
9 changes: 8 additions & 1 deletion src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const envSchema = z
NODE_ENV: z.string().default('development'),
PORT: z.string().optional(),
ADDRESS: z.string().optional(),
NETWORK: z.enum(['mainnet', 'testnet']).default('testnet'),
NETWORK: z.enum(['mainnet', 'testnet', 'signet']).default('testnet'),
LOGGER_LEVEL: z.enum(['debug', 'info', 'warn', 'error']).default('info'),

/**
Expand Down Expand Up @@ -38,6 +38,13 @@ const envSchema = z
SENTRY_DSN_URL: z.string().optional(),
SENTRY_TRACES_SAMPLE_RATE: z.coerce.number().default(0.5),
SENTRY_PROFILES_SAMPLE_RATE: z.coerce.number().default(0.5),
SENTRY_IGNORE_UTXO_SYNC_ERROR_ADDRESSES: z
.string()
.default('')
.transform((value) => {
const addresses = value.split(',');
return addresses.map((address) => address.trim());
}),

/**
* The rate limit per minute for each IP address.
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import process from 'node:process';
import { env } from './env';
import { buildFastify } from './app';
import * as Sentry from '@sentry/node';

const port = parseInt(env.PORT || '3000', 10);
const host = env.ADDRESS || '0.0.0.0';
Expand All @@ -10,7 +10,7 @@ const app = buildFastify();
app.listen({ port, host }, (err, address) => {
if (err) {
console.error(err);
process.exit(1);
Sentry.captureException(err);
}

// eslint-disable-next-line no-console
Expand Down
28 changes: 14 additions & 14 deletions src/plugins/swagger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,36 @@ export const DOCS_ROUTE_PREFIX = '/docs';
export default fp(async (fastify) => {
fastify.register(swagger, {
hideUntagged: true,
swagger: {
openapi: {
openapi: '3.1.0',
info: {
title: 'Bitcoin/RGB++ Assets API',
version: pkg.version,
},
consumes: ['application/json'],
produces: ['application/json'],
security: [{ apiKey: [] }],
securityDefinitions: {
apiKey: {
type: 'apiKey',
name: 'Authorization',
in: 'header',
description: 'JWT token for authentication. Example: Bearer <token>',
components: {
securitySchemes: {
apiKey: {
type: 'apiKey',
name: 'Authorization',
in: 'header',
description: 'JWT token for authentication. Example: Bearer <token>',
},
},
},
},
transform: jsonSchemaTransform,
transformObject: ({ swaggerObject }) => {
transformObject: ({ openapiObject }) => {
if (env.NODE_ENV === 'production') {
const { paths = {} } = swaggerObject;
const newPaths = Object.entries(paths).reduce((acc, [path, methods]) => {
const { paths = {} } = openapiObject;
openapiObject.paths = Object.entries(paths).reduce((acc, [path, methods]) => {
if (SWAGGER_PROD_IGNORE_URLS.some((ignorePath) => path.startsWith(ignorePath))) {
return acc;
}
return { ...acc, [path]: methods };
}, {});
swaggerObject.paths = newPaths;
}
return swaggerObject;
return openapiObject;
},
});
fastify.register(swaggerUI, {
Expand Down
Loading

0 comments on commit 2794960

Please sign in to comment.