Skip to content

Commit

Permalink
Merge pull request #195 from ckb-cell/release/0.2.0
Browse files Browse the repository at this point in the history
Merge release/0.2.0 to main branch
  • Loading branch information
Flouse authored May 28, 2024
2 parents 3606ce2 + ef597c1 commit 0948ef6
Show file tree
Hide file tree
Showing 121 changed files with 2,740 additions and 2,139 deletions.
130 changes: 130 additions & 0 deletions .changeset/changelog-format.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
// @ts-check
/**
* Based on the following format:
* - https://github.com/changesets/changesets/blob/main/packages/changelog-github/src/index.ts
* - https://github.com/stylelint/stylelint/blob/main/.changeset/changelog-stylelint.cjs
*/

const { getInfo, getInfoFromPullRequest } = require('@changesets/get-github-info');

/**
* @type {import('@changesets/types').ChangelogFunctions}
*/
const changelogFunctions = {
async getReleaseLine(changeset, _type, options) {
if (!options || !options.repo) {
throw new Error(
'Please provide a repo to this changelog generator like this:\n"changelog": ["@changesets/changelog-github", { "repo": "org/repo" }]',
);
}

/**
* @type {number | undefined}
*/
let prFromSummary;
/**
* @type {string | undefined}
*/
let commitFromSummary;
/**
* @type {string[]}
*/
let usersFromSummary = [];

const replacedChangelog = changeset.summary
.replace(/^\s*(?:pr|pull|pull\s+request):\s*#?(\d+)/im, (_, pr) => {
let num = Number(pr);
if (!isNaN(num)) {
prFromSummary = num;
}
return '';
})
.replace(/^\s*commit:\s*([^\s]+)/im, (_, commit) => {
commitFromSummary = commit;
return '';
})
.replace(/^\s*(?:author|user):\s*@?([^\s]+)/gim, (_, user) => {
usersFromSummary.push(user);
return '';
})
.trim();

const [firstLine, ...futureLines] = replacedChangelog
.split('\n')
.map((l) => l.trimRight());

const links = await (async () => {
if (prFromSummary !== undefined) {
let { links } = await getInfoFromPullRequest({
repo: options.repo,
pull: prFromSummary,
});
if (commitFromSummary) {
const shortCommitId = commitFromSummary.slice(0, 7);
links = {
...links,
commit: `[\`${shortCommitId}\`](https://github.com/${options.repo}/commit/${commitFromSummary})`,
};
}
return links;
}
const commitToFetchFrom = commitFromSummary || changeset.commit;
if (commitToFetchFrom) {
let { links } = await getInfo({
repo: options.repo,
commit: commitToFetchFrom,
});
return links;
}
return {
commit: null,
pull: null,
user: null,
};
})();

const users = usersFromSummary.length
? usersFromSummary
.map((userFromSummary) => `[@${userFromSummary}](https://github.com/${userFromSummary})`)
.join(', ')
: links.user;

const pull = links.pull !== null ? links.pull : '';
const commit = links.commit !== null ? links.commit : '';
const prefix = pull || commit ? `${pull || commit}:` : '';
const mention = users !== null ? `(${users})` : users;
const fullFirstLine = `${prefix} ${firstLine} ${mention}`;
const futureLinesText = futureLines.map((l) => ` ${l}`).join('\n');

return `\n\n - ${fullFirstLine}\n${futureLinesText}`;
},
async getDependencyReleaseLine(changesets, deps, options) {
if (!options.repo) {
throw new Error(
'Please provide a repo to this changelog generator like this:\n"changelog": ["@changesets/changelog-github", { "repo": "org/repo" }]',
);
}
if (deps.length === 0) {
return '';
}

const commits = await Promise.all(
changesets.map(async (cs) => {
if (cs.commit) {
let { links } = await getInfo({
repo: options.repo,
commit: cs.commit,
});
return links.commit;
}
}),
);

const changesetLink = `- Updated dependencies [${commits.join(', ')}]:`;
const updatedDeps = deps.map((dep) => ` - ${dep.name}@${dep.newVersion}`);

return [changesetLink, ...updatedDeps].join('\n');
},
};

module.exports = changelogFunctions;
6 changes: 3 additions & 3 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/config@3.0.0/schema.json",
"changelog": ["@changesets/changelog-github", { "repo": "ckb-cell/rgbpp-sdk" }],
"changelog": ["./changelog-format.cjs", { "repo": "ckb-cell/rgbpp-sdk" }],
"commit": false,
"fixed": [["@rgbpp-sdk/*"]],
"fixed": [["@rgbpp-sdk/*", "rgbpp"]],
"linked": [],
"access": "public",
"baseBranch": "main",
"baseBranch": "origin/main",
"updateInternalDependencies": "patch",
"ignore": []
}
44 changes: 44 additions & 0 deletions .github/workflows/integration-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Test the entire process of RGBPP to ensure the proper functioning of the rgbpp-sdk package.

name: Integration Tests

on:
workflow_dispatch:
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout rgbpp-sdk
uses: actions/checkout@v4

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x

- uses: pnpm/action-setup@v3
name: Install -g pnpm
with:
version: 8
run_install: false

- name: Install dependencies
run: pnpm i

- name: Build packages
run: pnpm run build:packages

- name: Run integration:xudt script
working-directory: ./tests/rgbpp
run: pnpm run integration:xudt
env:
VITE_SERVICE_URL: ${{ secrets.SERVICE_URL }}
VITE_SERVICE_TOKEN: ${{ secrets.SERVICE_TOKEN }}
VITE_SERVICE_ORIGIN: ${{ secrets.SERVICE_ORIGIN }}
INTEGRATION_CKB_PRIVATE_KEY: ${{ secrets.INTEGRATION_CKB_PRIVATE_KEY }}
INTEGRATION_BTC_PRIVATE_KEY: ${{ secrets.INTEGRATION_BTC_PRIVATE_KEY }}
19 changes: 12 additions & 7 deletions .github/workflows/snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ on:
workflow_dispatch:
push:
branches:
- main
- develop

concurrency: ${{ github.workflow }}-${{ github.ref }}
Expand Down Expand Up @@ -47,22 +46,28 @@ jobs:
- name: Install dependencies
run: pnpm i

- name: Clear cache
run: pnpm run clean:packages

- name: Build packages
run: pnpm run build:packages

- name: Version packages
- name: Add snapshot changeset (ensure at least has a changeset)
run: |
cat << EOF > ".changeset/snap-release-changeset.md"
---
"@rgbpp-sdk/btc": patch
---
Add temp changeset for snapshot releases
EOF
- name: Version packages to "0.0.0-snap-{timestamp}"
run: npx changeset version --snapshot snap
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Publish to npm (ignore GitHub)
- name: Publish to npm
id: changesets
uses: changesets/action@v1
with:
publish: npx changeset publish --snapshot --tag snap
publish: npx changeset publish --no-git-tag --snapshot --tag snap
createGithubReleases: false
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ jobs:
- name: Run tests for packages
run: pnpm run test:packages
env:
VITE_SERVICE_URL: ${{ secrets.SERVICE_URL }}
VITE_SERVICE_TOKEN: ${{ secrets.SERVICE_TOKEN }}
VITE_SERVICE_ORIGIN: ${{ secrets.SERVICE_ORIGIN }}
VITE_BTC_SERVICE_URL: ${{ secrets.SERVICE_URL }}
VITE_BTC_SERVICE_TOKEN: ${{ secrets.SERVICE_TOKEN }}
VITE_BTC_SERVICE_ORIGIN: ${{ secrets.SERVICE_ORIGIN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
.env.development.local
.env.production.local
.env.test.local
.env
**/.npmrc

# logs
Expand All @@ -40,3 +41,4 @@ yarn-error.log*
devbox.json
devbox.lock
.envrc

28 changes: 17 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This repository offers utilities for Bitcoin and RGB++ asset integration.

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

## RGB++ Code Examples

Expand All @@ -15,7 +15,7 @@ This repository offers utilities for Bitcoin and RGB++ asset integration.
## Related CKB Scripts (Contracts)
- [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)

- [RgbppLockScript and BtcTimeLockScript](https://github.com/ckb-cell/rgbpp-sdk/blob/cf25ea014d4e0fc24723df8eea8bd61f59e1060a/packages/ckb/src/constants/index.ts#L11-L121)
- [RgbppLockScript and BtcTimeLockScript](https://github.com/ckb-cell/rgbpp-sdk/blob/63df2dcd95b1b735b5d235e156e4361a3c87b0ac/packages/ckb/src/constants/index.ts#L12-L206)
* design: https://github.com/ckb-cell/RGBPlusPlus-design/blob/main/docs/light-paper-en.md
* testnet: https://pudge.explorer.nervos.org/scripts#RGB++
* mainnet: https://explorer.nervos.org/scripts#RGB++
Expand All @@ -36,29 +36,35 @@ This repository offers utilities for Bitcoin and RGB++ asset integration.
2. **[BTC → CKB](https://github.com/ckb-cell/rgbpp-sdk/blob/develop/packages/ckb/README.md#rgb-spore-leap-from-btc-to-ckb)**
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)*

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

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`)

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

### Notes

- The RGB++ CKB transaction Queue is designed to streamline the transaction workflow. Developers have the option to implement its features by themselves without limitation.
- `Bitcoin/RGB++ Assets Service` is designed to streamline the transaction workflow. Developers have the option to implement its features by themselves without limitation.


## FAQ

### How to get an access token of Bitcoin/RGB++ Assets Service?
See [Generate a JSON Web Token (JWT) for Bitcoin/RGB++ Assets Service](./packages/service/README.md#get-an-access-token)


## License
Expand Down
4 changes: 2 additions & 2 deletions apps/next/.env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
NEXT_PUBLIC_SERVICE_URL=
NEXT_PUBLIC_SERVICE_TOKEN=
NEXT_PUBLIC_BTC_SERVICE_URL=
NEXT_PUBLIC_BTC_SERVICE_TOKEN=
4 changes: 2 additions & 2 deletions apps/next/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export default function Home() {
const networkType = NetworkType.TESTNET;

const service = BtcAssetsApi.fromToken(
process.env.NEXT_PUBLIC_SERVICE_URL!,
process.env.NEXT_PUBLIC_SERVICE_TOKEN!,
process.env.NEXT_PUBLIC_BTC_SERVICE_URL!,
process.env.NEXT_PUBLIC_BTC_SERVICE_TOKEN!,
);
const source = new DataSource(service, networkType);

Expand Down
4 changes: 2 additions & 2 deletions apps/vite/.env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
VITE_SERVICE_URL=
VITE_SERVICE_TOKEN=
VITE_BTC_SERVICE_URL=
VITE_BTC_SERVICE_TOKEN=
2 changes: 1 addition & 1 deletion apps/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.5",
"typescript": "^5.2.2",
"vite": "^5.1.4",
"vite": "^5.2.11",
"vite-plugin-node-polyfills": "^0.21.0"
}
}
5 changes: 4 additions & 1 deletion apps/vite/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ function App() {
async function send() {
const networkType = NetworkType.TESTNET;

const service = BtcAssetsApi.fromToken(import.meta.env.VITE_SERVICE_URL!, import.meta.env.VITE_SERVICE_TOKEN!);
const service = BtcAssetsApi.fromToken(
import.meta.env.VITE_BTC_SERVICE_URL!,
import.meta.env.VITE_BTC_SERVICE_TOKEN!,
);
const source = new DataSource(service, networkType);

const psbt = await sendBtc({
Expand Down
29 changes: 29 additions & 0 deletions examples/rgbpp/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# True for CKB and BTC Mainnet and false for CKB and BTC Testnet, the default value is false
IS_MAINNET=false

# CKB Variables

# The CKB secp256k1 private key whose format is 32bytes hex string with 0x prefix
CKB_SECP256K1_PRIVATE_KEY=0x-private-key

# CKB node url which should be matched with IS_MAINNET
CKB_NODE_URL=https://testnet.ckb.dev/rpc

# CKB indexer url which should be matched with IS_MAINNET
CKB_INDEXER_URL=https://testnet.ckb.dev/indexer


# BTC Variables

# The BTC private key whose format is 32bytes hex string without 0x prefix
BTC_PRIVATE_KEY=private-key

# The BTC assets api url which should be matched with IS_MAINNET
VITE_BTC_SERVICE_URL=https://btc-assets-api.testnet.mibao.pro

# The BTC assets api token which should be matched with IS_MAINNET
# To get an access token, please refer to https://github.com/ckb-cell/rgbpp-sdk/tree/develop/packages/service#get-an-access-token
VITE_BTC_SERVICE_TOKEN=

# The BTC assets api origin which should be matched with IS_MAINNET
VITE_BTC_SERVICE_ORIGIN=https://btc-test.app
Loading

0 comments on commit 0948ef6

Please sign in to comment.