Skip to content
This repository was archived by the owner on Sep 21, 2025. It is now read-only.

Commit fcb4551

Browse files
authored
Merge pull request #147 from ckb-cell/develop
Merge develop to main branch (release v2.2.0)
2 parents 2503793 + 83ffe68 commit fcb4551

29 files changed

+1360
-200
lines changed

.env.example

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Bitcoin network, testnet by default
22
NETWORK=testnet
3-
# LOGGER_LEVEL=info
43

54
# Set /token/generate default domain param
65
# DOMAIN=localhost
@@ -31,9 +30,9 @@ JWT_SECRET=<your_secret>
3130
# JWT_DENYLIST=
3231

3332
# Bitcoin data provider, support mempool and electrs
34-
# use mempool.space as default, electrs as fallback
35-
# change to electrs if you want to use electrs as default and mempool.space as fallback
36-
BITCOIN_DATA_PROVIDER=mempool
33+
# use electrs as default, mempool as fallback
34+
# change to mempool if you want to use mempool.space as default and electrs as fallback
35+
BITCOIN_DATA_PROVIDER=electrs
3736
# Bitcoin Mempool.space API URL
3837
# optinal when BITCOIN_DATA_PROVIDER=electrs
3938
BITCOIN_MEMPOOL_SPACE_API_URL=https://mempool.space
@@ -51,10 +50,6 @@ CKB_RPC_URL=https://testnet.ckb.dev/rpc
5150
PAYMASTER_PRIVATE_KEY=
5251
# Paymaster cell capacity in shannons
5352
PAYMASTER_CELL_CAPACITY=31600000000
54-
# Paymaster cell queue preset count, used to refill paymaster cell.
55-
PAYMASTER_CELL_PRESET_COUNT=500
56-
# Paymaster cell refill threshold, refill paymaster cell when the balance is less than this threshold.
57-
PAYMASTER_CELL_REFILL_THRESHOLD=0.3
5853
# Check the paymaster BTC UTXO when processing rgb++ ckb transaction
5954
PAYMASTER_RECEIVE_UTXO_CHECK=false
6055
# Paymaster bitcoin address, used to receive BTC from users
@@ -66,8 +61,6 @@ PAYMASTER_BTC_CONTAINER_FEE_SATS=7000
6661
UNLOCKER_CRON_SCHEDULE='*/5 * * * *'
6762
# BTCTimeLock cell unlock batch size
6863
UNLOCKER_CELL_BATCH_SIZE=100
69-
# BTCTimeLock cell unlocker monitor slug, used for monitoring unlocker status on sentry
70-
UNLOCKER_MONITOR_SLUG=btctimelock-cells-unlocker
7164

7265
# RGB++ CKB transaction Queue cron job delay in milliseconds
7366
# the /rgbpp/v1/transaction/ckb-tx endpoint is called, the transaction will be added to the queue

README.md

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ Update the configuration values:
3030
```env
3131
# Bitcoin network, testnet by default
3232
NETWORK=testnet
33-
# LOGGER_LEVEL=info
3433
3534
# Set /token/generate default domain param
3635
# DOMAIN=localhost
@@ -61,9 +60,9 @@ JWT_SECRET=<your_secret>
6160
# JWT_DENYLIST=
6261
6362
# Bitcoin data provider, support mempool and electrs
64-
# use mempool.space as default, electrs as fallback
65-
# change to electrs if you want to use electrs as default and mempool.space as fallback
66-
BITCOIN_DATA_PROVIDER=mempool
63+
# use electrs as default, mempool as fallback
64+
# change to mempool if you want to use mempool.space as default and electrs as fallback
65+
BITCOIN_DATA_PROVIDER=electrs
6766
# Bitcoin Mempool.space API URL
6867
# optinal when BITCOIN_DATA_PROVIDER=electrs
6968
BITCOIN_MEMPOOL_SPACE_API_URL=https://mempool.space
@@ -81,10 +80,6 @@ CKB_RPC_URL=https://testnet.ckb.dev/rpc
8180
PAYMASTER_PRIVATE_KEY=
8281
# Paymaster cell capacity in shannons
8382
PAYMASTER_CELL_CAPACITY=31600000000
84-
# Paymaster cell queue preset count, used to refill paymaster cell.
85-
PAYMASTER_CELL_PRESET_COUNT=500
86-
# Paymaster cell refill threshold, refill paymaster cell when the balance is less than this threshold.
87-
PAYMASTER_CELL_REFILL_THRESHOLD=0.3
8883
# Check the paymaster BTC UTXO when processing rgb++ ckb transaction
8984
PAYMASTER_RECEIVE_UTXO_CHECK=false
9085
# Paymaster bitcoin address, used to receive BTC from users
@@ -96,8 +91,6 @@ PAYMASTER_BTC_CONTAINER_FEE_SATS=7000
9691
UNLOCKER_CRON_SCHEDULE='*/5 * * * *'
9792
# BTCTimeLock cell unlock batch size
9893
UNLOCKER_CELL_BATCH_SIZE=100
99-
# BTCTimeLock cell unlocker monitor slug, used for monitoring unlocker status on sentry
100-
UNLOCKER_MONITOR_SLUG=btctimelock-cells-unlocker
10194
10295
# RGB++ CKB transaction Queue cron job delay in milliseconds
10396
# the /rgbpp/v1/transaction/ckb-tx endpoint is called, the transaction will be added to the queue

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "btc-assets-api",
3-
"version": "2.1.0",
3+
"version": "2.2.0",
44
"title": "Bitcoin/RGB++ Assets API",
55
"description": "",
66
"main": "index.js",
@@ -41,9 +41,9 @@
4141
"@fastify/swagger-ui": "^3.0.0",
4242
"@immobiliarelabs/fastify-sentry": "^8.0.1",
4343
"@nervosnetwork/ckb-sdk-utils": "^0.109.1",
44-
"@rgbpp-sdk/btc": "0.0.0-snap-20240430102443",
45-
"@rgbpp-sdk/ckb": "0.0.0-snap-20240430102443",
46-
"@rgbpp-sdk/service": "0.0.0-snap-20240430102443",
44+
"@rgbpp-sdk/btc": "^0.1.0",
45+
"@rgbpp-sdk/ckb": "^0.1.0",
46+
"@rgbpp-sdk/service": "^0.1.0",
4747
"@sentry/node": "^7.102.1",
4848
"@sentry/profiling-node": "^7.102.1",
4949
"async-retry": "^1.3.3",

pnpm-lock.yaml

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/@types/fastify/index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import Paymaster from '../../services/paymaster';
44
import SPVClient from '../../services/spv';
55
import CKBClient from '../../services/ckb';
66
import BitcoinClient from '../../services/bitcoin';
7+
import RgbppCollector from '../../services/rgbpp';
8+
import UTXOSyncer from '../../services/utxo';
79

810
declare module 'fastify' {
911
// eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -15,5 +17,7 @@ declare module 'fastify' {
1517
spv: SPVClient;
1618
paymaster: Paymaster;
1719
transactionProcessor: TransactionProcessor;
20+
rgbppCollector: RgbppCollector;
21+
utxoSyncer: UTXOSyncer;
1822
}
1923
}

src/container.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import Unlocker from './services/unlocker';
88
import SPVClient from './services/spv';
99
import CKBClient from './services/ckb';
1010
import BitcoinClient from './services/bitcoin';
11+
import RgbppCollector from './services/rgbpp';
12+
import UTXOSyncer from './services/utxo';
1113

1214
export interface Cradle {
1315
env: typeof env;
@@ -19,6 +21,8 @@ export interface Cradle {
1921
paymaster: Paymaster;
2022
unlocker: Unlocker;
2123
transactionProcessor: TransactionProcessor;
24+
rgbppCollector: RgbppCollector;
25+
utxoSyncer: UTXOSyncer;
2226
}
2327

2428
const container = createContainer<Cradle>({
@@ -40,6 +44,8 @@ container.register({
4044
paymaster: asClass(Paymaster).singleton(),
4145
transactionProcessor: asClass(TransactionProcessor).singleton(),
4246
unlocker: asClass(Unlocker).singleton(),
47+
rgbppCollector: asClass(RgbppCollector).singleton(),
48+
utxoSyncer: asClass(UTXOSyncer).singleton(),
4349
});
4450

4551
export default container;

src/env.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,48 @@ const envSchema = z
161161
.enum(['true', 'false'])
162162
.default('false')
163163
.transform((value) => value === 'true'),
164+
165+
/**
166+
* UTXO sync data cache enable flag, used to cache the UTXO sync data
167+
* enable by default
168+
*/
169+
UTXO_SYNC_DATA_CACHE_ENABLE: z
170+
.enum(['true', 'false'])
171+
.default('true')
172+
.transform((value) => value === 'true'),
173+
/**
174+
* UTXO sync repeat base duration, used to set the UTXO sync repeat interval
175+
* repeat job start interval is 10 seconds by default
176+
*/
177+
UTXO_SYNC_REPEAT_BASE_DURATION: z.coerce.number().default(10 * 1000),
178+
/**
179+
* UTXO sync repeat max duration, used to maximum the UTXO sync repeat interval
180+
* 1 hour by default
181+
*/
182+
UTXO_SYNC_REPEAT_MAX_DURATION: z.coerce.number().default(60 * 60 * 1000),
183+
/**
184+
* UTXO sync repeat expired duration, used to remove the expired UTXO sync job
185+
* 336 hours by default
186+
*/
187+
UTXO_SYNC_REPEAT_EXPRIED_DURATION: z.coerce.number().default(336 * 60 * 60 * 1000),
188+
/**
189+
* UTXO sync data cache expire duration, used to cache the UTXO sync data
190+
* 30 minutes by default
191+
*/
192+
UTXO_SYNC_DATA_CACHE_EXPIRE: z.coerce.number().default(30 * 60 * 1000),
193+
194+
/**
195+
* RGB++ collect data cache enable flag, used to cache the RGB++ collect data
196+
* enable by default
197+
*/
198+
RGBPP_COLLECT_DATA_CACHE_ENABLE: z
199+
.enum(['true', 'false'])
200+
.default('true')
201+
.transform((value) => value === 'true'),
202+
/**
203+
* RGB++ collect data cache expire duration, used to cache the RGB++ collect data
204+
*/
205+
RGBPP_COLLECT_DATA_CACHE_EXPIRE: z.coerce.number().default(30 * 60 * 1000),
164206
})
165207
.and(
166208
z.union([

src/plugins/cron.ts

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import TransactionProcessor from '../services/transaction';
33
import cron from 'fastify-cron';
44
import { Env } from '../env';
55
import Unlocker from '../services/unlocker';
6+
import RgbppCollector from '../services/rgbpp';
7+
import UTXOSyncer from '../services/utxo';
68

79
export default fp(async (fastify) => {
810
try {
@@ -48,10 +50,10 @@ export default fp(async (fastify) => {
4850
fastify.addHook('onReady', async () => {
4951
transactionProcessor.startProcess({
5052
onActive: (job) => {
51-
fastify.log.info(`Job active: ${job.id}`);
53+
fastify.log.info(`[TransactionProcessor] job active: ${job.id}`);
5254
},
5355
onCompleted: (job) => {
54-
fastify.log.info(`Job completed: ${job.id}`);
56+
fastify.log.info(`[TransactionProcessor] job completed: ${job.id}`);
5557
},
5658
});
5759
});
@@ -78,6 +80,45 @@ export default fp(async (fastify) => {
7880
},
7981
};
8082

83+
if (env.UTXO_SYNC_DATA_CACHE_ENABLE) {
84+
const utxoSyncer: UTXOSyncer = fastify.container.resolve('utxoSyncer');
85+
fastify.addHook('onReady', async () => {
86+
utxoSyncer.startProcess({
87+
onActive: (job) => {
88+
fastify.log.info(`[UTXOSyncer] job active: ${job.id}`);
89+
},
90+
onCompleted: async (job) => {
91+
fastify.log.info(`[UTXOSyncer] job completed: ${job.id}`);
92+
if (env.RGBPP_COLLECT_DATA_CACHE_ENABLE) {
93+
const { btcAddress, utxos } = job.returnvalue;
94+
const rgbppCollector: RgbppCollector = fastify.container.resolve('rgbppCollector');
95+
await rgbppCollector.enqueueCollectJob(btcAddress, utxos, true);
96+
}
97+
},
98+
});
99+
});
100+
fastify.addHook('onClose', async () => {
101+
utxoSyncer.closeProcess();
102+
});
103+
}
104+
105+
if (env.RGBPP_COLLECT_DATA_CACHE_ENABLE) {
106+
const rgbppCollector: RgbppCollector = fastify.container.resolve('rgbppCollector');
107+
fastify.addHook('onReady', async () => {
108+
rgbppCollector.startProcess({
109+
onActive: (job) => {
110+
fastify.log.info(`[RgbppCollector] job active: ${job.id}`);
111+
},
112+
onCompleted: (job) => {
113+
fastify.log.info(`[RgbppCollector] job completed: ${job.id}`);
114+
},
115+
});
116+
});
117+
fastify.addHook('onClose', async () => {
118+
rgbppCollector.closeProcess();
119+
});
120+
}
121+
81122
// processing unlock BTC_TIME_LOCK cells
82123
const unlocker: Unlocker = fastify.container.resolve('unlocker');
83124
const monitorSlug = env.UNLOCKER_MONITOR_SLUG;

0 commit comments

Comments
 (0)