Skip to content

Commit 0948ef6

Browse files
authored
Merge pull request #195 from ckb-cell/release/0.2.0
Merge release/0.2.0 to main branch
2 parents 3606ce2 + ef597c1 commit 0948ef6

File tree

121 files changed

+2740
-2139
lines changed

Some content is hidden

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

121 files changed

+2740
-2139
lines changed

.changeset/changelog-format.cjs

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
// @ts-check
2+
/**
3+
* Based on the following format:
4+
* - https://github.com/changesets/changesets/blob/main/packages/changelog-github/src/index.ts
5+
* - https://github.com/stylelint/stylelint/blob/main/.changeset/changelog-stylelint.cjs
6+
*/
7+
8+
const { getInfo, getInfoFromPullRequest } = require('@changesets/get-github-info');
9+
10+
/**
11+
* @type {import('@changesets/types').ChangelogFunctions}
12+
*/
13+
const changelogFunctions = {
14+
async getReleaseLine(changeset, _type, options) {
15+
if (!options || !options.repo) {
16+
throw new Error(
17+
'Please provide a repo to this changelog generator like this:\n"changelog": ["@changesets/changelog-github", { "repo": "org/repo" }]',
18+
);
19+
}
20+
21+
/**
22+
* @type {number | undefined}
23+
*/
24+
let prFromSummary;
25+
/**
26+
* @type {string | undefined}
27+
*/
28+
let commitFromSummary;
29+
/**
30+
* @type {string[]}
31+
*/
32+
let usersFromSummary = [];
33+
34+
const replacedChangelog = changeset.summary
35+
.replace(/^\s*(?:pr|pull|pull\s+request):\s*#?(\d+)/im, (_, pr) => {
36+
let num = Number(pr);
37+
if (!isNaN(num)) {
38+
prFromSummary = num;
39+
}
40+
return '';
41+
})
42+
.replace(/^\s*commit:\s*([^\s]+)/im, (_, commit) => {
43+
commitFromSummary = commit;
44+
return '';
45+
})
46+
.replace(/^\s*(?:author|user):\s*@?([^\s]+)/gim, (_, user) => {
47+
usersFromSummary.push(user);
48+
return '';
49+
})
50+
.trim();
51+
52+
const [firstLine, ...futureLines] = replacedChangelog
53+
.split('\n')
54+
.map((l) => l.trimRight());
55+
56+
const links = await (async () => {
57+
if (prFromSummary !== undefined) {
58+
let { links } = await getInfoFromPullRequest({
59+
repo: options.repo,
60+
pull: prFromSummary,
61+
});
62+
if (commitFromSummary) {
63+
const shortCommitId = commitFromSummary.slice(0, 7);
64+
links = {
65+
...links,
66+
commit: `[\`${shortCommitId}\`](https://github.com/${options.repo}/commit/${commitFromSummary})`,
67+
};
68+
}
69+
return links;
70+
}
71+
const commitToFetchFrom = commitFromSummary || changeset.commit;
72+
if (commitToFetchFrom) {
73+
let { links } = await getInfo({
74+
repo: options.repo,
75+
commit: commitToFetchFrom,
76+
});
77+
return links;
78+
}
79+
return {
80+
commit: null,
81+
pull: null,
82+
user: null,
83+
};
84+
})();
85+
86+
const users = usersFromSummary.length
87+
? usersFromSummary
88+
.map((userFromSummary) => `[@${userFromSummary}](https://github.com/${userFromSummary})`)
89+
.join(', ')
90+
: links.user;
91+
92+
const pull = links.pull !== null ? links.pull : '';
93+
const commit = links.commit !== null ? links.commit : '';
94+
const prefix = pull || commit ? `${pull || commit}:` : '';
95+
const mention = users !== null ? `(${users})` : users;
96+
const fullFirstLine = `${prefix} ${firstLine} ${mention}`;
97+
const futureLinesText = futureLines.map((l) => ` ${l}`).join('\n');
98+
99+
return `\n\n - ${fullFirstLine}\n${futureLinesText}`;
100+
},
101+
async getDependencyReleaseLine(changesets, deps, options) {
102+
if (!options.repo) {
103+
throw new Error(
104+
'Please provide a repo to this changelog generator like this:\n"changelog": ["@changesets/changelog-github", { "repo": "org/repo" }]',
105+
);
106+
}
107+
if (deps.length === 0) {
108+
return '';
109+
}
110+
111+
const commits = await Promise.all(
112+
changesets.map(async (cs) => {
113+
if (cs.commit) {
114+
let { links } = await getInfo({
115+
repo: options.repo,
116+
commit: cs.commit,
117+
});
118+
return links.commit;
119+
}
120+
}),
121+
);
122+
123+
const changesetLink = `- Updated dependencies [${commits.join(', ')}]:`;
124+
const updatedDeps = deps.map((dep) => ` - ${dep.name}@${dep.newVersion}`);
125+
126+
return [changesetLink, ...updatedDeps].join('\n');
127+
},
128+
};
129+
130+
module.exports = changelogFunctions;

.changeset/config.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
3-
"changelog": ["@changesets/changelog-github", { "repo": "ckb-cell/rgbpp-sdk" }],
3+
"changelog": ["./changelog-format.cjs", { "repo": "ckb-cell/rgbpp-sdk" }],
44
"commit": false,
5-
"fixed": [["@rgbpp-sdk/*"]],
5+
"fixed": [["@rgbpp-sdk/*", "rgbpp"]],
66
"linked": [],
77
"access": "public",
8-
"baseBranch": "main",
8+
"baseBranch": "origin/main",
99
"updateInternalDependencies": "patch",
1010
"ignore": []
1111
}
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Test the entire process of RGBPP to ensure the proper functioning of the rgbpp-sdk package.
2+
3+
name: Integration Tests
4+
5+
on:
6+
workflow_dispatch:
7+
pull_request:
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
12+
jobs:
13+
test:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout rgbpp-sdk
17+
uses: actions/checkout@v4
18+
19+
- name: Install Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: 20.x
23+
24+
- uses: pnpm/action-setup@v3
25+
name: Install -g pnpm
26+
with:
27+
version: 8
28+
run_install: false
29+
30+
- name: Install dependencies
31+
run: pnpm i
32+
33+
- name: Build packages
34+
run: pnpm run build:packages
35+
36+
- name: Run integration:xudt script
37+
working-directory: ./tests/rgbpp
38+
run: pnpm run integration:xudt
39+
env:
40+
VITE_SERVICE_URL: ${{ secrets.SERVICE_URL }}
41+
VITE_SERVICE_TOKEN: ${{ secrets.SERVICE_TOKEN }}
42+
VITE_SERVICE_ORIGIN: ${{ secrets.SERVICE_ORIGIN }}
43+
INTEGRATION_CKB_PRIVATE_KEY: ${{ secrets.INTEGRATION_CKB_PRIVATE_KEY }}
44+
INTEGRATION_BTC_PRIVATE_KEY: ${{ secrets.INTEGRATION_BTC_PRIVATE_KEY }}

.github/workflows/snapshot.yml

+12-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ on:
66
workflow_dispatch:
77
push:
88
branches:
9-
- main
109
- develop
1110

1211
concurrency: ${{ github.workflow }}-${{ github.ref }}
@@ -47,22 +46,28 @@ jobs:
4746
- name: Install dependencies
4847
run: pnpm i
4948

50-
- name: Clear cache
51-
run: pnpm run clean:packages
52-
5349
- name: Build packages
5450
run: pnpm run build:packages
5551

56-
- name: Version packages
52+
- name: Add snapshot changeset (ensure at least has a changeset)
53+
run: |
54+
cat << EOF > ".changeset/snap-release-changeset.md"
55+
---
56+
"@rgbpp-sdk/btc": patch
57+
---
58+
Add temp changeset for snapshot releases
59+
EOF
60+
61+
- name: Version packages to "0.0.0-snap-{timestamp}"
5762
run: npx changeset version --snapshot snap
5863
env:
5964
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6065

61-
- name: Publish to npm (ignore GitHub)
66+
- name: Publish to npm
6267
id: changesets
6368
uses: changesets/action@v1
6469
with:
65-
publish: npx changeset publish --snapshot --tag snap
70+
publish: npx changeset publish --no-git-tag --snapshot --tag snap
6671
createGithubReleases: false
6772
env:
6873
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/test.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ jobs:
5252
- name: Run tests for packages
5353
run: pnpm run test:packages
5454
env:
55-
VITE_SERVICE_URL: ${{ secrets.SERVICE_URL }}
56-
VITE_SERVICE_TOKEN: ${{ secrets.SERVICE_TOKEN }}
57-
VITE_SERVICE_ORIGIN: ${{ secrets.SERVICE_ORIGIN }}
55+
VITE_BTC_SERVICE_URL: ${{ secrets.SERVICE_URL }}
56+
VITE_BTC_SERVICE_TOKEN: ${{ secrets.SERVICE_TOKEN }}
57+
VITE_BTC_SERVICE_ORIGIN: ${{ secrets.SERVICE_ORIGIN }}

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
.env.development.local
3131
.env.production.local
3232
.env.test.local
33+
.env
3334
**/.npmrc
3435

3536
# logs
@@ -40,3 +41,4 @@ yarn-error.log*
4041
devbox.json
4142
devbox.lock
4243
.envrc
44+

README.md

+17-11
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This repository offers utilities for Bitcoin and RGB++ asset integration.
66

77
- [@rgbpp-sdk/btc](./packages/btc): Bitcoin part of the SDK
88
- [@rgbpp-sdk/ckb](./packages/ckb): Nervos CKB part of the SDK
9-
- [@rgbpp-sdk/service](./packages/service): A wrapped class to interact with `Bitcoin/RGB++ Assets Service`
9+
- [@rgbpp-sdk/service](./packages/service): Wrapped interfaces of `Bitcoin/RGB++ Assets Service`
1010

1111
## RGB++ Code Examples
1212

@@ -15,7 +15,7 @@ This repository offers utilities for Bitcoin and RGB++ asset integration.
1515
## Related CKB Scripts (Contracts)
1616
- [CKB Bitcoin SPV Type Script](https://github.com/ckb-cell/ckb-bitcoin-spv-contracts/tree/master/contracts/ckb-bitcoin-spv-type-lock): A [type script](https://docs.nervos.org/docs/basics/glossary#type-script) for [Bitcoin SPV](https://bitcoinwiki.org/wiki/simplified-payment-verification) clients which synchronize [Bitcoin](https://bitcoin.org) state into [CKB](https://github.com/nervosnetwork/ckb)
1717

18-
- [RgbppLockScript and BtcTimeLockScript](https://github.com/ckb-cell/rgbpp-sdk/blob/cf25ea014d4e0fc24723df8eea8bd61f59e1060a/packages/ckb/src/constants/index.ts#L11-L121)
18+
- [RgbppLockScript and BtcTimeLockScript](https://github.com/ckb-cell/rgbpp-sdk/blob/63df2dcd95b1b735b5d235e156e4361a3c87b0ac/packages/ckb/src/constants/index.ts#L12-L206)
1919
* design: https://github.com/ckb-cell/RGBPlusPlus-design/blob/main/docs/light-paper-en.md
2020
* testnet: https://pudge.explorer.nervos.org/scripts#RGB++
2121
* mainnet: https://explorer.nervos.org/scripts#RGB++
@@ -36,29 +36,35 @@ This repository offers utilities for Bitcoin and RGB++ asset integration.
3636
2. **[BTC → CKB](https://github.com/ckb-cell/rgbpp-sdk/blob/develop/packages/ckb/README.md#rgb-spore-leap-from-btc-to-ckb)**
3737
3. **[CKB → BTC](https://github.com/ckb-cell/rgbpp-sdk/blob/develop/packages/ckb/README.md#rgb-spore-leap-from-ckb-to-btc)** *(isomorphic rgbpp_btc_tx is not required in this workflow)*
3838

39-
> [!IMPORTANT]
39+
> [!IMPORTANT]
4040
> It's recommended to save the `rgbpp_ckb_tx_virtual` locally in case you need it in the future.
4141
4242
2. **Creation of `rgbpp_btc_tx` through [@rgbpp-sdk/btc](https://github.com/ckb-cell/rgbpp-sdk/tree/develop/packages/btc)**
43-
1. construct isomorphic rgbpp_btc_tx based on rgbpp_ckb_tx_virtual and rgbpp commitment
44-
2. sign and broadcast rgbpp_btc_tx to obtain `rgbpp_btc_txid`
43+
1. construct isomorphic `rgbpp_btc_tx` based on `rgbpp_ckb_tx_virtual` and rgbpp commitment
44+
2. sign and broadcast `rgbpp_btc_tx` to obtain `rgbpp_btc_txid`
4545

4646
3. JoyID or dApp sends `rgbpp_btc_txid` and `rgbpp_ckb_tx_virtual` to RGB++ CKB transaction Queue (API Endpoint: `/rgbpp/v1/transaction/ckb-tx`)
4747

4848
4. `RGB++ CKB transaction Queue` will process the following things:
4949
1. **verify** the received requests
5050
2. continuously fetch request from the queue through a **cron job**
51-
3. check whether the **confirmations** of req.rgbpp_btc_txid is sufficient
52-
4. generate the **witnesses for RgbppLocks** in the rgbpp_ckb_tx_virtual
53-
5. add a **paymaster cell** into rgbpp_ckb_tx_virtual.inputs if the CKB capacity is insufficient
51+
3. check whether the **confirmations** of `req.rgbpp_btc_txid` is sufficient
52+
4. generate the **witnesses for RgbppLocks** in the `rgbpp_ckb_tx_virtual`
53+
5. add a **paymaster cell** into `rgbpp_ckb_tx_virtual`.inputs if the CKB capacity is insufficient
5454
1. need to **verify the existence of paymaster UTXO** in the rgbpp_btc_tx
5555
2. sign the paymaster cell and the entire transaction if needed
56-
6. **finalize** the rgbpp_ckb_tx_virtual to a rgbpp_ckb_tx
57-
7. **broadcast** rgbpp_ckb_tx and mark the job as completed upon tx-confirmation
56+
6. **finalize** the `rgbpp_ckb_tx_virtual` to a `rgbpp_ckb_tx`
57+
7. **broadcast** `rgbpp_ckb_tx` and mark the job as completed upon tx-confirmation
5858

5959
### Notes
6060

61-
- The RGB++ CKB transaction Queue is designed to streamline the transaction workflow. Developers have the option to implement its features by themselves without limitation.
61+
- `Bitcoin/RGB++ Assets Service` is designed to streamline the transaction workflow. Developers have the option to implement its features by themselves without limitation.
62+
63+
64+
## FAQ
65+
66+
### How to get an access token of Bitcoin/RGB++ Assets Service?
67+
See [Generate a JSON Web Token (JWT) for Bitcoin/RGB++ Assets Service](./packages/service/README.md#get-an-access-token)
6268

6369

6470
## License

apps/next/.env.example

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
NEXT_PUBLIC_SERVICE_URL=
2-
NEXT_PUBLIC_SERVICE_TOKEN=
1+
NEXT_PUBLIC_BTC_SERVICE_URL=
2+
NEXT_PUBLIC_BTC_SERVICE_TOKEN=

apps/next/src/app/page.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ export default function Home() {
77
const networkType = NetworkType.TESTNET;
88

99
const service = BtcAssetsApi.fromToken(
10-
process.env.NEXT_PUBLIC_SERVICE_URL!,
11-
process.env.NEXT_PUBLIC_SERVICE_TOKEN!,
10+
process.env.NEXT_PUBLIC_BTC_SERVICE_URL!,
11+
process.env.NEXT_PUBLIC_BTC_SERVICE_TOKEN!,
1212
);
1313
const source = new DataSource(service, networkType);
1414

apps/vite/.env.example

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
VITE_SERVICE_URL=
2-
VITE_SERVICE_TOKEN=
1+
VITE_BTC_SERVICE_URL=
2+
VITE_BTC_SERVICE_TOKEN=

apps/vite/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"eslint-plugin-react-hooks": "^4.6.0",
2828
"eslint-plugin-react-refresh": "^0.4.5",
2929
"typescript": "^5.2.2",
30-
"vite": "^5.1.4",
30+
"vite": "^5.2.11",
3131
"vite-plugin-node-polyfills": "^0.21.0"
3232
}
3333
}

apps/vite/src/App.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ function App() {
66
async function send() {
77
const networkType = NetworkType.TESTNET;
88

9-
const service = BtcAssetsApi.fromToken(import.meta.env.VITE_SERVICE_URL!, import.meta.env.VITE_SERVICE_TOKEN!);
9+
const service = BtcAssetsApi.fromToken(
10+
import.meta.env.VITE_BTC_SERVICE_URL!,
11+
import.meta.env.VITE_BTC_SERVICE_TOKEN!,
12+
);
1013
const source = new DataSource(service, networkType);
1114

1215
const psbt = await sendBtc({

examples/rgbpp/.env.example

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# True for CKB and BTC Mainnet and false for CKB and BTC Testnet, the default value is false
2+
IS_MAINNET=false
3+
4+
# CKB Variables
5+
6+
# The CKB secp256k1 private key whose format is 32bytes hex string with 0x prefix
7+
CKB_SECP256K1_PRIVATE_KEY=0x-private-key
8+
9+
# CKB node url which should be matched with IS_MAINNET
10+
CKB_NODE_URL=https://testnet.ckb.dev/rpc
11+
12+
# CKB indexer url which should be matched with IS_MAINNET
13+
CKB_INDEXER_URL=https://testnet.ckb.dev/indexer
14+
15+
16+
# BTC Variables
17+
18+
# The BTC private key whose format is 32bytes hex string without 0x prefix
19+
BTC_PRIVATE_KEY=private-key
20+
21+
# The BTC assets api url which should be matched with IS_MAINNET
22+
VITE_BTC_SERVICE_URL=https://btc-assets-api.testnet.mibao.pro
23+
24+
# The BTC assets api token which should be matched with IS_MAINNET
25+
# To get an access token, please refer to https://github.com/ckb-cell/rgbpp-sdk/tree/develop/packages/service#get-an-access-token
26+
VITE_BTC_SERVICE_TOKEN=
27+
28+
# The BTC assets api origin which should be matched with IS_MAINNET
29+
VITE_BTC_SERVICE_ORIGIN=https://btc-test.app

0 commit comments

Comments
 (0)