Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge develop to main branch (release v2.0.0) #125

Merged
merged 63 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
3de6d82
fix: refactor global error handler to fix inaccurate error message
ahonn Apr 29, 2024
380a4b1
Merge pull request #111 from ckb-cell/110-error-message-inaccurate
ahonn Apr 29, 2024
a9ebdff
refactor: use mempool.space API instead of bitcoind and electrs
ahonn Apr 22, 2024
c09843a
refactor: update transaction processing mempool error handle
ahonn Apr 23, 2024
884adeb
test: add BITCOIN_MEMPOOL_SPACE_API_URL to test env
ahonn Apr 23, 2024
962202a
test: update test cases
ahonn Apr 23, 2024
7dd33cc
refactor: refactor bitcoin mempool api error handle and test cases
ahonn Apr 23, 2024
aa95fc8
refactor: useing electrs as a fallback for the mempool.space API
ahonn Apr 24, 2024
6ca04a7
refactor: rename ckb/bitcoin/spv/transaction services
ahonn Apr 24, 2024
fc4d030
refactor: rename Electrs to ElectrsClient
ahonn Apr 24, 2024
cb7dd0c
feat: add after_txid query params to /bitcoin/v1/address/:address/txs
ahonn Apr 25, 2024
b59a2c9
feat: add new bitcoin route for get recommanded fees
ahonn Apr 25, 2024
ddd1fbc
test: update app test
ahonn Apr 25, 2024
0bb9eeb
test: add BITCOIN_ELECTRS_API_URL back
ahonn Apr 25, 2024
6a99451
refactor: update healthcheck
ahonn Apr 25, 2024
3b6168e
chore: update env
ahonn Apr 26, 2024
3a07f4d
refactor: add bitcoin client electrs fallback
ahonn Apr 26, 2024
a49c894
chore: update .example.env
ahonn Apr 26, 2024
1f7c52d
docs: update README.md
ahonn Apr 26, 2024
7347a35
refactor: support electrs as main data provider and mempool.space as …
ahonn Apr 27, 2024
15bcd97
fix: fix elelctrs & mempool client type issues
ahonn Apr 27, 2024
519ca0f
test: fix transaction processor test case
ahonn Apr 27, 2024
649df0f
feat: server cache bitcoin recommended fees 10 seconds
ahonn Apr 28, 2024
b341667
test: add matrix data providers and fix test cases
ahonn Apr 28, 2024
abb5e91
test: add bitcoin client data providers test
ahonn Apr 28, 2024
0acfc7f
docs: update README.md and .env.example
ahonn Apr 28, 2024
29075ed
fix: fix error handler
ahonn Apr 29, 2024
80ecb8b
feat: use @cell-studio/mempool.js instead of @mempool/mempool.js
ahonn Apr 29, 2024
d2607ff
test: update test case snapshots
ahonn Apr 29, 2024
ce507f7
Merge pull request #96 from ckb-cell/feat/mempool-space-api
ahonn Apr 29, 2024
ce0f1f9
chore: add filled count to sentry context when throw PaymasterCellNot…
ahonn Apr 29, 2024
3b187ac
Merge pull request #113 from ckb-cell/chore/add-filled-count-to-sentry
ahonn Apr 29, 2024
58d6230
feat: calculate fees when mempool.space recommend fees api failed
ahonn Apr 29, 2024
5626b13
Merge pull request #114 from ckb-cell/feat/calculate-fees
ahonn Apr 29, 2024
3e6c11c
fix: fix the state issue of inactive paymaster cell job (#118)
ahonn Apr 30, 2024
060229b
docs: update .env.example and README.md
ahonn Apr 30, 2024
df1694a
docs: update TRANSACTION_QUEUE_JOB_DELAY
ahonn Apr 30, 2024
288c920
Merge pull request #119 from ckb-cell/docs/update-env-vars
ahonn Apr 30, 2024
d5fb5f2
feat(unlock): add spore BTCTimeLock cells unlock support
ahonn May 2, 2024
1cf58ea
fix: upgrade generateSporeTransferCoBuild
ahonn May 2, 2024
54908d4
feat(bitcoin): add /bitcoin/v1/transactiona/:btc_txid/hex route
ahonn May 3, 2024
f1e1167
fix: pass all spore cells to generateSporeTransferCoBuild when transf…
ahonn May 6, 2024
0151627
fix: rename test/route/bitcoind to test/route/bitcoin
ahonn May 6, 2024
d4a6493
test: add testTimeout
ahonn May 6, 2024
f1d444a
ci: remove concurrency to avoid action cancel
ahonn May 6, 2024
12f6c9b
Merge pull request #120 from ckb-cell/115-add-spore-btc-time-cells-un…
ahonn May 6, 2024
8fb4955
Merge pull request #123 from ckb-cell/121-discussion-support-get-btc-…
ahonn May 6, 2024
7ce2feb
fix(env): set BITCOIN_DATA_PROVIDER=electrs by default
ahonn May 6, 2024
af55c72
docs: add upgrading to v2 docs
ahonn May 6, 2024
057f687
bump: v2.0.0
ahonn May 6, 2024
fbeea7b
feat: post bitcoin transaction to multi electrs nodes
ahonn May 6, 2024
d780c08
refactor: add IBitcoinBroadcastBackuper interface
ahonn May 6, 2024
7e15364
fix: bITCOIN_ADDITIONAL_BROADCAST_ELECTRS_URL_LIST optional, check ur…
ahonn May 6, 2024
84fe0c6
docs: update docs/upgrading-to-v2.md
ahonn May 6, 2024
a3b7fda
fix: fix bitcoin client backupers initial and remove unnecessary erro…
ahonn May 7, 2024
b1840ad
docs: update docs/upgrading-to-v2.md
ahonn May 6, 2024
063dd4b
fix: fix CKBComponents is not defined
ahonn May 7, 2024
5bea1e0
Merge pull request #126 from ckb-cell/bump/v2.0.0
ahonn May 7, 2024
c6c53e0
Merge pull request #127 from ckb-cell/122-post-btc-transaction-to-mul…
Flouse May 7, 2024
bb5be9f
fix: fix bitcoin client error message handle
ahonn May 7, 2024
7d1e3a4
test: update test cases & snapshot
ahonn May 7, 2024
7356146
fix: use isAxiosError to get axios error type
ahonn May 7, 2024
9e29e01
Merge pull request #129 from ckb-cell/fix/catch-bitcoin-client-error-…
ahonn May 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ JWT_SECRET=<your_secret>
# JWT token denylist
# JWT_DENYLIST=

# Bitcoin JSON-RPC URL and credentials
BITCOIN_JSON_RPC_URL=<http://bitcoin:8332>
BITCOIN_JSON_RPC_USERNAME=<rpc_username>
BITCOIN_JSON_RPC_PASSWORD=<rpc_password>

# Bitcoin data provider, support mempool and electrs
# use mempool.space as default, electrs as fallback
# change to electrs if you want to use electrs as default and mempool.space as fallback
BITCOIN_DATA_PROVIDER=mempool
# Bitcoin Mempool.space API URL
# optinal when BITCOIN_DATA_PROVIDER=electrs
BITCOIN_MEMPOOL_SPACE_API_URL=https://mempool.space
# Electrs API URL
# optinal when BITCOIN_DATA_PROVIDER=mempool
BITCOIN_ELECTRS_API_URL=<http://electrs:3002>

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

# BTCTimeLock cell unlock batch size
UNLOCKER_CELL_BATCH_SIZE=100
# BTCTimeLock cell unlock cron job schedule, default is every 5 minutes
UNLOCKER_CRON_SCHEDULE='*/5 * * * *'
# BTCTimeLock cell unlock batch size
UNLOCKER_CELL_BATCH_SIZE=100
# BTCTimeLock cell unlocker monitor slug, used for monitoring unlocker status on sentry
UNLOCKER_MONITOR_SLUG=btctimelock-cells-unlocker

# RGB++ CKB transaction Queue cron job delay in milliseconds
# the /rgbpp/v1/transaction/ckb-tx endpoint is called, the transaction will be added to the queue
TRANSACTION_QUEUE_JOB_DELAY=12000
TRANSACTION_QUEUE_JOB_DELAY=120000
# RGB++ CKB transaction Queue cron job attempts
TRANSACTION_QUEUE_JOB_ATTEMPTS=6
# Pay fee for transaction with pool reject by min fee rate, false by default
TRANSACTION_PAY_FOR_MIN_FEE_RATE_REJECT=false
10 changes: 6 additions & 4 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: Unit Tests
on:
workflow_dispatch:
push:
branches:
branches:
- main
- develop
pull_request:
Expand All @@ -15,6 +15,9 @@ on:
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
BITCOIN_DATA_PROVIDER: [mempool, electrs]

services:
redis:
Expand Down Expand Up @@ -48,9 +51,8 @@ jobs:
- name: Run Unit Tests
env:
JWT_SECRET: ${{ secrets.JWT_SECRET }}
BITCOIN_JSON_RPC_URL: ${{ secrets.BITCOIN_JSON_RPC_URL }}
BITCOIN_JSON_RPC_USERNAME: ${{ secrets.BITCOIN_JSON_RPC_USERNAME }}
BITCOIN_JSON_RPC_PASSWORD: ${{ secrets.BITCOIN_JSON_RPC_PASSWORD }}
BITCOIN_DATA_PROVIDER: ${{ matrix.BITCOIN_DATA_PROVIDER }}
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_RECEIVE_BTC_ADDRESS: ${{ secrets.PAYMASTER_RECEIVE_BTC_ADDRESS }}
Expand Down
33 changes: 22 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
A service for Retrieving BTC/RGB++ information/assets and processing transactions with these assets

### Features

- Retrieving Blockchain Information such as Bitcoin chain info, blocks, headers, transactions, addresses and RGB++ assets
- 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
Expand All @@ -11,13 +12,14 @@ A service for Retrieving BTC/RGB++ information/assets and processing transaction

#### Requirements

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

#### Configuration

Copy the `.env.example` file to `.env`:
Copy the `.env.example` file to `.env`:

```bash
cp .env.example .env
Expand Down Expand Up @@ -58,12 +60,15 @@ JWT_SECRET=<your_secret>
# JWT token denylist
# JWT_DENYLIST=

# Bitcoin JSON-RPC URL and credentials
BITCOIN_JSON_RPC_URL=<http://bitcoin:8332>
BITCOIN_JSON_RPC_USERNAME=<rpc_username>
BITCOIN_JSON_RPC_PASSWORD=<rpc_password>

# Bitcoin data provider, support mempool and electrs
# use mempool.space as default, electrs as fallback
# change to electrs if you want to use electrs as default and mempool.space as fallback
BITCOIN_DATA_PROVIDER=mempool
# Bitcoin Mempool.space API URL
# optinal when BITCOIN_DATA_PROVIDER=electrs
BITCOIN_MEMPOOL_SPACE_API_URL=https://mempool.space
# Electrs API URL
# optinal when BITCOIN_DATA_PROVIDER=mempool
BITCOIN_ELECTRS_API_URL=<http://electrs:3002>

# SPV Service URL
Expand All @@ -80,21 +85,27 @@ PAYMASTER_CELL_CAPACITY=31600000000
PAYMASTER_CELL_PRESET_COUNT=500
# Paymaster cell refill threshold, refill paymaster cell when the balance is less than this threshold.
PAYMASTER_CELL_REFILL_THRESHOLD=0.3
# Check the paymaster BTC UTXO when processing rgb++ ckb transaction
PAYMASTER_RECEIVE_UTXO_CHECK=false
# Paymaster bitcoin address, used to receive BTC from users
PAYMASTER_RECEIVE_BTC_ADDRESS=<paymaster_btc_address>
# Paymaster receives BTC UTXO size in sats
PAYMASTER_BTC_CONTAINER_FEE_SATS=7000

# BTCTimeLock cell unlock batch size
UNLOCKER_CELL_BATCH_SIZE=100
# BTCTimeLock cell unlock cron job schedule, default is every 5 minutes
UNLOCKER_CRON_SCHEDULE='*/5 * * * *'
# BTCTimeLock cell unlock batch size
UNLOCKER_CELL_BATCH_SIZE=100
# BTCTimeLock cell unlocker monitor slug, used for monitoring unlocker status on sentry
UNLOCKER_MONITOR_SLUG=btctimelock-cells-unlocker

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

More configuration options can be found in the `src/env.ts` file.
Expand Down
49 changes: 49 additions & 0 deletions docs/upgrading-to-v2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
## Upgrading to V2

We have released v2.0.0 for support `mempool.space` API as a Bitcoin data provider, and it
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.

There are two ways to upgrade:

### Upgrading from v1.x.x and use electrs (**compatible, by default**)
Suppose you do not want to use the mempool.space API as the main data provider, **you do not need to make any changes**.

But we recommend you remove the following env vars for safety:

```env
BITCOIN_JSON_RPC_URL=<http://bitcoin:8332>
BITCOIN_JSON_RPC_USERNAME=<rpc_username>
BITCOIN_JSON_RPC_PASSWORD=<rpc_password>
```

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:

```env
BITCOIN_DATA_PROVIDER=electrs # recommend, electrs by default
BITCOIN_MEMPOOL_SPACE_API_URL=https://mempool.space # optional, mempool.space as the fallback
```

### Upgrading from v1.x.x and using mempool.space API (**new feature**)
The new feature in v2.0.0, we can use mempool.space API as the primary data provider, and use electrs as a fallback.

Add the following env vars:

```env
BITCOIN_DATA_PROVIDER=mempool
BITCOIN_MEMPOOL_SPACE_API_URL=https://mempool.space
```

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.

```env
BITCOIN_ELECTRS_API_URL=<http://electrs:3002> # optional, electrs as fallback
```

#### Recommended Fees API
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).

**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**




9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "btc-assets-api",
"version": "1.5.0",
"version": "2.0.0",
"title": "Bitcoin/RGB++ Assets API",
"description": "",
"main": "index.js",
Expand All @@ -25,6 +25,7 @@
]
},
"dependencies": {
"@cell-studio/mempool.js": "^2.4.0",
"@ckb-lumos/base": "^0.22.2 ",
"@ckb-lumos/ckb-indexer": "^0.22.2",
"@ckb-lumos/codec": "^0.22.2",
Expand All @@ -40,9 +41,9 @@
"@fastify/swagger-ui": "^3.0.0",
"@immobiliarelabs/fastify-sentry": "^8.0.1",
"@nervosnetwork/ckb-sdk-utils": "^0.109.1",
"@rgbpp-sdk/btc": "0.0.0-snap-20240423144119",
"@rgbpp-sdk/ckb": "0.0.0-snap-20240423144119",
"@rgbpp-sdk/service": "0.0.0-snap-20240423144119",
"@rgbpp-sdk/btc": "0.0.0-snap-20240430102443",
"@rgbpp-sdk/ckb": "0.0.0-snap-20240430102443",
"@rgbpp-sdk/service": "0.0.0-snap-20240430102443",
"@sentry/node": "^7.102.1",
"@sentry/profiling-node": "^7.102.1",
"awilix": "^10.0.1",
Expand Down
66 changes: 29 additions & 37 deletions pnpm-lock.yaml

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

Loading
Loading