Skip to content

Commit 4219f0e

Browse files
authored
Merge pull request #125 from ckb-cell/develop
Merge develop to main branch (release v2.0.0)
2 parents c4549aa + 9e29e01 commit 4219f0e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1293
-823
lines changed

.env.example

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,15 @@ JWT_SECRET=<your_secret>
3030
# JWT token denylist
3131
# JWT_DENYLIST=
3232

33-
# Bitcoin JSON-RPC URL and credentials
34-
BITCOIN_JSON_RPC_URL=<http://bitcoin:8332>
35-
BITCOIN_JSON_RPC_USERNAME=<rpc_username>
36-
BITCOIN_JSON_RPC_PASSWORD=<rpc_password>
37-
33+
# 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
37+
# Bitcoin Mempool.space API URL
38+
# optinal when BITCOIN_DATA_PROVIDER=electrs
39+
BITCOIN_MEMPOOL_SPACE_API_URL=https://mempool.space
3840
# Electrs API URL
41+
# optinal when BITCOIN_DATA_PROVIDER=mempool
3942
BITCOIN_ELECTRS_API_URL=<http://electrs:3002>
4043

4144
# SPV Service URL
@@ -52,18 +55,24 @@ PAYMASTER_CELL_CAPACITY=31600000000
5255
PAYMASTER_CELL_PRESET_COUNT=500
5356
# Paymaster cell refill threshold, refill paymaster cell when the balance is less than this threshold.
5457
PAYMASTER_CELL_REFILL_THRESHOLD=0.3
58+
# Check the paymaster BTC UTXO when processing rgb++ ckb transaction
59+
PAYMASTER_RECEIVE_UTXO_CHECK=false
5560
# Paymaster bitcoin address, used to receive BTC from users
5661
PAYMASTER_RECEIVE_BTC_ADDRESS=<paymaster_btc_address>
5762
# Paymaster receives BTC UTXO size in sats
5863
PAYMASTER_BTC_CONTAINER_FEE_SATS=7000
5964

60-
# BTCTimeLock cell unlock batch size
61-
UNLOCKER_CELL_BATCH_SIZE=100
6265
# BTCTimeLock cell unlock cron job schedule, default is every 5 minutes
6366
UNLOCKER_CRON_SCHEDULE='*/5 * * * *'
67+
# BTCTimeLock cell unlock batch size
68+
UNLOCKER_CELL_BATCH_SIZE=100
6469
# BTCTimeLock cell unlocker monitor slug, used for monitoring unlocker status on sentry
6570
UNLOCKER_MONITOR_SLUG=btctimelock-cells-unlocker
6671

6772
# RGB++ CKB transaction Queue cron job delay in milliseconds
6873
# the /rgbpp/v1/transaction/ckb-tx endpoint is called, the transaction will be added to the queue
69-
TRANSACTION_QUEUE_JOB_DELAY=12000
74+
TRANSACTION_QUEUE_JOB_DELAY=120000
75+
# RGB++ CKB transaction Queue cron job attempts
76+
TRANSACTION_QUEUE_JOB_ATTEMPTS=6
77+
# Pay fee for transaction with pool reject by min fee rate, false by default
78+
TRANSACTION_PAY_FOR_MIN_FEE_RATE_REJECT=false

.github/workflows/test.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ name: Unit Tests
44
on:
55
workflow_dispatch:
66
push:
7-
branches:
7+
branches:
88
- main
99
- develop
1010
pull_request:
@@ -15,6 +15,9 @@ on:
1515
jobs:
1616
test:
1717
runs-on: ubuntu-latest
18+
strategy:
19+
matrix:
20+
BITCOIN_DATA_PROVIDER: [mempool, electrs]
1821

1922
services:
2023
redis:
@@ -48,9 +51,8 @@ jobs:
4851
- name: Run Unit Tests
4952
env:
5053
JWT_SECRET: ${{ secrets.JWT_SECRET }}
51-
BITCOIN_JSON_RPC_URL: ${{ secrets.BITCOIN_JSON_RPC_URL }}
52-
BITCOIN_JSON_RPC_USERNAME: ${{ secrets.BITCOIN_JSON_RPC_USERNAME }}
53-
BITCOIN_JSON_RPC_PASSWORD: ${{ secrets.BITCOIN_JSON_RPC_PASSWORD }}
54+
BITCOIN_DATA_PROVIDER: ${{ matrix.BITCOIN_DATA_PROVIDER }}
55+
BITCOIN_MEMPOOL_SPACE_API_URL: ${{ secrets.BITCOIN_MEMPOOL_SPACE_API_URL }}
5456
BITCOIN_ELECTRS_API_URL: ${{ secrets.BITCOIN_ELECTRS_API_URL }}
5557
BITCOIN_SPV_SERVICE_URL: ${{ secrets.BITCOIN_SPV_SERVICE_URL }}
5658
PAYMASTER_RECEIVE_BTC_ADDRESS: ${{ secrets.PAYMASTER_RECEIVE_BTC_ADDRESS }}

README.md

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
A service for Retrieving BTC/RGB++ information/assets and processing transactions with these assets
44

55
### Features
6+
67
- Retrieving Blockchain Information such as Bitcoin chain info, blocks, headers, transactions, addresses and RGB++ assets
78
- Transaction Handling by posting transactions to the /bitcoin/v1/transaction or /rgbpp/v1/transaction/ckb-tx endpoint
89
- RGB++ CKB transaction Queue simplifies the RGB++ assets workflows by some cron jobs
@@ -11,13 +12,14 @@ A service for Retrieving BTC/RGB++ information/assets and processing transaction
1112

1213
#### Requirements
1314

14-
- [bitcoind](https://github.com/bitcoin/bitcoin): Running a Bitcoin full node
15-
- [mempool/electrs](https://github.com/mempool/electrs): Electrum Rust Server (Electrs) indexes Bitcoin chain data
15+
- [mempool.space](https://mempool.space/docs) or [mempool/electrs](https://github.com/mempool/electrs): provides data about the Bitcoin network.
16+
- We can use either of them as data provider
17+
- Or use both, designating one as the primary provider and the other as the fallback
1618
- [ckb-cell/ckb-bitcoin-spv-service](https://github.com/ckb-cell/ckb-bitcoin-spv-service): CKB Bitcoin SPV Service
1719

1820
#### Configuration
1921

20-
Copy the `.env.example` file to `.env`:
22+
Copy the `.env.example` file to `.env`:
2123

2224
```bash
2325
cp .env.example .env
@@ -58,12 +60,15 @@ JWT_SECRET=<your_secret>
5860
# JWT token denylist
5961
# JWT_DENYLIST=
6062
61-
# Bitcoin JSON-RPC URL and credentials
62-
BITCOIN_JSON_RPC_URL=<http://bitcoin:8332>
63-
BITCOIN_JSON_RPC_USERNAME=<rpc_username>
64-
BITCOIN_JSON_RPC_PASSWORD=<rpc_password>
65-
63+
# 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
67+
# Bitcoin Mempool.space API URL
68+
# optinal when BITCOIN_DATA_PROVIDER=electrs
69+
BITCOIN_MEMPOOL_SPACE_API_URL=https://mempool.space
6670
# Electrs API URL
71+
# optinal when BITCOIN_DATA_PROVIDER=mempool
6772
BITCOIN_ELECTRS_API_URL=<http://electrs:3002>
6873
6974
# SPV Service URL
@@ -80,21 +85,27 @@ PAYMASTER_CELL_CAPACITY=31600000000
8085
PAYMASTER_CELL_PRESET_COUNT=500
8186
# Paymaster cell refill threshold, refill paymaster cell when the balance is less than this threshold.
8287
PAYMASTER_CELL_REFILL_THRESHOLD=0.3
88+
# Check the paymaster BTC UTXO when processing rgb++ ckb transaction
89+
PAYMASTER_RECEIVE_UTXO_CHECK=false
8390
# Paymaster bitcoin address, used to receive BTC from users
8491
PAYMASTER_RECEIVE_BTC_ADDRESS=<paymaster_btc_address>
8592
# Paymaster receives BTC UTXO size in sats
8693
PAYMASTER_BTC_CONTAINER_FEE_SATS=7000
8794
88-
# BTCTimeLock cell unlock batch size
89-
UNLOCKER_CELL_BATCH_SIZE=100
9095
# BTCTimeLock cell unlock cron job schedule, default is every 5 minutes
9196
UNLOCKER_CRON_SCHEDULE='*/5 * * * *'
97+
# BTCTimeLock cell unlock batch size
98+
UNLOCKER_CELL_BATCH_SIZE=100
9299
# BTCTimeLock cell unlocker monitor slug, used for monitoring unlocker status on sentry
93100
UNLOCKER_MONITOR_SLUG=btctimelock-cells-unlocker
94101
95102
# RGB++ CKB transaction Queue cron job delay in milliseconds
96103
# the /rgbpp/v1/transaction/ckb-tx endpoint is called, the transaction will be added to the queue
97-
TRANSACTION_QUEUE_JOB_DELAY=12000
104+
TRANSACTION_QUEUE_JOB_DELAY=120000
105+
# RGB++ CKB transaction Queue cron job attempts
106+
TRANSACTION_QUEUE_JOB_ATTEMPTS=6
107+
# Pay fee for transaction with pool reject by min fee rate, false by default
108+
TRANSACTION_PAY_FOR_MIN_FEE_RATE_REJECT=false
98109
```
99110

100111
More configuration options can be found in the `src/env.ts` file.

docs/upgrading-to-v2.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
## Upgrading to V2
2+
3+
We have released v2.0.0 for support `mempool.space` API as a Bitcoin data provider, and it
4+
provides a set of [IBitcoinDataProvider](https://github.com/ckb-cell/btc-assets-api/blob/8fb495576c957e9006ef648d6c24312a3f10e34f/src/services/bitcoin/interface.ts#L3) interfaces. Note that it is still compatible with the `electrs` used previously.
5+
6+
There are two ways to upgrade:
7+
8+
### Upgrading from v1.x.x and use electrs (**compatible, by default**)
9+
Suppose you do not want to use the mempool.space API as the main data provider, **you do not need to make any changes**.
10+
11+
But we recommend you remove the following env vars for safety:
12+
13+
```env
14+
BITCOIN_JSON_RPC_URL=<http://bitcoin:8332>
15+
BITCOIN_JSON_RPC_USERNAME=<rpc_username>
16+
BITCOIN_JSON_RPC_PASSWORD=<rpc_password>
17+
```
18+
19+
and add the following env vars to make sure to use electrs as the primary data provider, and add mempool.space API as a fallback:
20+
21+
```env
22+
BITCOIN_DATA_PROVIDER=electrs # recommend, electrs by default
23+
BITCOIN_MEMPOOL_SPACE_API_URL=https://mempool.space # optional, mempool.space as the fallback
24+
```
25+
26+
### Upgrading from v1.x.x and using mempool.space API (**new feature**)
27+
The new feature in v2.0.0, we can use mempool.space API as the primary data provider, and use electrs as a fallback.
28+
29+
Add the following env vars:
30+
31+
```env
32+
BITCOIN_DATA_PROVIDER=mempool
33+
BITCOIN_MEMPOOL_SPACE_API_URL=https://mempool.space
34+
```
35+
36+
If you want to use the previous electrs as a fallback, keep the original `BITCOIN_ELECTRS_API_URL` env var. Otherwise, remove this var to avoid using electrs.
37+
38+
```env
39+
BITCOIN_ELECTRS_API_URL=<http://electrs:3002> # optional, electrs as fallback
40+
```
41+
42+
#### Recommended Fees API
43+
If use mempool.space API as the primary data provider, then we can use `/bitcoin/v1/fees/recommended` to get the bitcoin fees. and we will calculate fees when mempool.space recommend fees API unavailable (see https://github.com/ckb-cell/btc-assets-api/pull/114).
44+
45+
**use electrs as the primary data provider and dosen't set `BITCOIN_MEMPOOL_SPACE_API_URL` as a fallback, then recommended fees API will be unavailable**
46+
47+
48+
49+

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "btc-assets-api",
3-
"version": "1.5.0",
3+
"version": "2.0.0",
44
"title": "Bitcoin/RGB++ Assets API",
55
"description": "",
66
"main": "index.js",
@@ -25,6 +25,7 @@
2525
]
2626
},
2727
"dependencies": {
28+
"@cell-studio/mempool.js": "^2.4.0",
2829
"@ckb-lumos/base": "^0.22.2 ",
2930
"@ckb-lumos/ckb-indexer": "^0.22.2",
3031
"@ckb-lumos/codec": "^0.22.2",
@@ -40,9 +41,9 @@
4041
"@fastify/swagger-ui": "^3.0.0",
4142
"@immobiliarelabs/fastify-sentry": "^8.0.1",
4243
"@nervosnetwork/ckb-sdk-utils": "^0.109.1",
43-
"@rgbpp-sdk/btc": "0.0.0-snap-20240423144119",
44-
"@rgbpp-sdk/ckb": "0.0.0-snap-20240423144119",
45-
"@rgbpp-sdk/service": "0.0.0-snap-20240423144119",
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",
4647
"@sentry/node": "^7.102.1",
4748
"@sentry/profiling-node": "^7.102.1",
4849
"awilix": "^10.0.1",

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)