Skip to content

RGB++ core#368

Open
fghdotio wants to merge 53 commits intockb-devrel:releases/nextfrom
fghdotio:feat/rgbpp-core
Open

RGB++ core#368
fghdotio wants to merge 53 commits intockb-devrel:releases/nextfrom
fghdotio:feat/rgbpp-core

Conversation

@fghdotio
Copy link
Copy Markdown
Contributor

No description provided.

fghdotio and others added 30 commits April 17, 2026 14:17
* Simplify MapLru, while improving Complexity

Closes ckb-devrel#243

* Apply suggestions from code %2

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

* Allow nullable Values

* Switch from non-null assertion to type assertion

* Create six-steaks-grab.md

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Hanssen <hanssen0@hanssen0.com>
* Improve performance of Script & OutPoint eq %143

* Fix typedoc copy-paste mishap

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

* Dedupe strings in an interleaved way %27

* Revert manual interning

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
It's definitely a mistake to name `CellOnChain` `Cell`, but there is nothing we can do with that right now. To avoid more duplicate code, `CellAny` was added to represent a cell that's on-chain or off-chain.
This reverts commit 4393803.

It will be moved to a new branch `feat/udt`
This reverts commit 507c6e8.

This information is outdated
* feat(core): `hexFrom` passthru normalized hex and `numToHex` enforce hex normalization

* feat(core): improve `isHex`

* feat(core): improve `isHex` parameter
…lock args parsing, and update `btcTxid` type.
…gtest` address type detection, update JSDoc comments
…ctions directly and fix BigInt exponentiation for token decimals.
fghdotio added 19 commits April 17, 2026 14:29
…es and leverage ccc utilities for hashing and byte conversions.
…ons and UDT issuance, and remove Lumos dependencies
…rsing compatibility and remove Buffer dependencies
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 18, 2026

🦋 Changeset detected

Latest commit: dc72c80

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 21 packages
Name Type
@ckb-ccc/core Major
@ckb-ccc/ssri Patch
@ckb-ccc/did-ckb Patch
@ckb-ccc/eip6963 Patch
@ckb-ccc/joy-id Patch
@ckb-ccc/lumos-patches Patch
@ckb-ccc/nip07 Patch
@ckb-ccc/okx Patch
@ckb-ccc/rei Patch
@ckb-ccc/rgbpp Patch
@ckb-ccc/shell Patch
@ckb-ccc/spore Patch
@ckb-ccc/type-id Patch
@ckb-ccc/udt Patch
@ckb-ccc/uni-sat Patch
@ckb-ccc/utxo-global Patch
@ckb-ccc/xverse Patch
@ckb-ccc/ccc Patch
ckb-ccc Patch
@ckb-ccc/connector Patch
@ckb-ccc/connector-react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 18, 2026

Deploy Preview for appccc ready!

Name Link
🔨 Latest commit dc72c80
🔍 Latest deploy log https://app.netlify.com/projects/appccc/deploys/69fb466f0c98860008a37b9f
😎 Deploy Preview https://deploy-preview-368--appccc.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 67 (🔴 down 19 from production)
Accessibility: 89 (🟢 up 1 from production)
Best Practices: 92 (🔴 down 8 from production)
SEO: 100 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 18, 2026

Deploy Preview for docsccc ready!

Name Link
🔨 Latest commit dc72c80
🔍 Latest deploy log https://app.netlify.com/projects/docsccc/deploys/69fb466f8334bd0008f44077
😎 Deploy Preview https://deploy-preview-368--docsccc.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 76 (🟢 up 9 from production)
Accessibility: 88 (no change from production)
Best Practices: 92 (no change from production)
SEO: 92 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 18, 2026

Deploy Preview for liveccc ready!

Name Link
🔨 Latest commit dc72c80
🔍 Latest deploy log https://app.netlify.com/projects/liveccc/deploys/69fb466fbdefde0008c33543
😎 Deploy Preview https://deploy-preview-368--liveccc.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 35 (🔴 down 2 from production)
Accessibility: 88 (no change from production)
Best Practices: 92 (🔴 down 8 from production)
SEO: 100 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 18, 2026

Deploy Preview for apiccc ready!

Name Link
🔨 Latest commit dc72c80
🔍 Latest deploy log https://app.netlify.com/projects/apiccc/deploys/69fb466f48f506000839dc02
😎 Deploy Preview https://deploy-preview-368--apiccc.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 84 (🟢 up 2 from production)
Accessibility: 100 (no change from production)
Best Practices: 100 (no change from production)
SEO: 95 (🟢 up 1 from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the @ckb-ccc/rgbpp package, providing RGB++ protocol support including Bitcoin account management, transaction construction, and SPV proof integration. It also enhances the core package with reduce and reduceAsync utilities for iterables, hex normalization optimizations, and updated script configurations. Review feedback recommends several refinements for the new package: parallelizing UTXO processing to improve performance, removing redundant nullish coalescing in fee calculations, replacing console.log with a configurable logger, optimizing redundant byte conversions in commitment logic, and calling .unref() on timers to ensure the library doesn't block process exits.

Comment on lines +58 to +93
const inputs: TxInputData[] = [];
// TODO: parallel
for (const utxoSeal of uniqueSeals) {
const tx = await this.dataSource.getTransaction(utxoSeal.txid);
if (!tx) {
throw new ErrorBtcTransactionNotFound(utxoSeal.txid);
}
const vout = tx.vout[utxoSeal.vout];
if (!vout) {
throw new ErrorBtcUtxoNotFound(
utxoSeal.txid,
utxoSeal.vout,
tx.vout.length,
);
}

const scriptBuffer = ccc.bytesFrom(vout.scriptpubkey);
if (isOpReturnScriptPubkey(scriptBuffer)) {
throw new ErrorBtcOpReturnUtxo(utxoSeal.txid, utxoSeal.vout);
}

inputs.push(
await utxoToInputData(
{
txid: utxoSeal.txid,
vout: utxoSeal.vout,
value: vout.value,
scriptPk: vout.scriptpubkey,
address: vout.scriptpubkey_address,
addressType: getAddressType(vout.scriptpubkey_address),
} as Utxo,
this.publicKeyProvider,
),
);
}
return inputs;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The loop to build inputs makes sequential await calls inside for...of. This can be inefficient if there are many UTXOs to process. You can improve performance by processing them in parallel using Promise.all. The existing // TODO: parallel comment indicates this was intended.

    const inputs: TxInputData[] = await Promise.all(
      uniqueSeals.map(async (utxoSeal) => {
        const tx = await this.dataSource.getTransaction(utxoSeal.txid);
        if (!tx) {
          throw new ErrorBtcTransactionNotFound(utxoSeal.txid);
        }
        const vout = tx.vout[utxoSeal.vout];
        if (!vout) {
          throw new ErrorBtcUtxoNotFound(
            utxoSeal.txid,
            utxoSeal.vout,
            tx.vout.length,
          );
        }

        const scriptBuffer = ccc.bytesFrom(vout.scriptpubkey);
        if (isOpReturnScriptPubkey(scriptBuffer)) {
          throw new ErrorBtcOpReturnUtxo(utxoSeal.txid, utxoSeal.vout);
        }

        return utxoToInputData(
          {
            txid: utxoSeal.txid,
            vout: utxoSeal.vout,
            value: vout.value,
            scriptPk: vout.scriptpubkey,
            address: vout.scriptpubkey_address,
            addressType: getAddressType(vout.scriptpubkey_address),
          } as Utxo,
          this.publicKeyProvider,
        );
      }),
    );
    return inputs;

Copy link
Copy Markdown
Contributor Author

@fghdotio fghdotio Apr 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in d70ac9e.

Comment on lines +283 to +285
return Math.ceil(
bufferedVirtualSize * (feeRate ?? this.networkConfig.btcFeeRate),
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The feeRate variable is guaranteed to be a number at this point due to the preceding logic that assigns a value in all branches. The nullish coalescing operator ?? is therefore redundant.

    return Math.ceil(bufferedVirtualSize * feeRate);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 13bd255.

Comment thread packages/rgbpp/src/bitcoin/wallet.ts Outdated
Comment on lines +430 to +432
console.log(
`[prepareUtxoSeal] Transaction ${txId} not confirmed, waiting ${intervalSeconds} seconds...`,
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using console.log for logging in a library is generally discouraged as it can create unwanted output in consuming applications and is not configurable. Consider using a dedicated, configurable logger or providing an option to suppress these logs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 956e3f5.

Comment thread packages/rgbpp/src/bitcoin/wallet.ts Outdated
Comment on lines +732 to +735
const outputDataLen = ccc.numLeToBytes(ccc.bytesFrom(outputData).length, 4);
const od = ccc.bytesFrom(outputData);
hash.update(outputDataLen);
hash.update(od);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The expression ccc.bytesFrom(outputData) is evaluated twice. To improve performance and readability, store its result in a variable. Additionally, ensure the function accepts generic types like HexLike for outputData and performs this conversion internally, consistent with repository standards.

Suggested change
const outputDataLen = ccc.numLeToBytes(ccc.bytesFrom(outputData).length, 4);
const od = ccc.bytesFrom(outputData);
hash.update(outputDataLen);
hash.update(od);
const od = ccc.bytesFrom(outputData);
const outputDataLen = ccc.numLeToBytes(od.length, 4);
hash.update(outputDataLen);
hash.update(od);
References
  1. Functions should accept more generic types like HexLike and perform necessary type conversions internally, rather than requiring the caller to do so.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 13bd255.

Comment thread packages/rgbpp/src/signer/index.ts Outdated
Comment on lines +290 to +294
setTimeout(() => {
if (this.spvProofCache.get(btcTxId) === proofPromise) {
this.spvProofCache.delete(btcTxId);
}
}, this.cacheExpiryTime);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The timer created with setTimeout can prevent a Node.js process from exiting if it is the only thing left in the event loop. For a library, it is good practice to call .unref() on the timer handle to allow the process to exit gracefully even if the timer is still pending.

Suggested change
setTimeout(() => {
if (this.spvProofCache.get(btcTxId) === proofPromise) {
this.spvProofCache.delete(btcTxId);
}
}, this.cacheExpiryTime);
setTimeout(() => {
if (this.spvProofCache.get(btcTxId) === proofPromise) {
this.spvProofCache.delete(btcTxId);
}
}, this.cacheExpiryTime).unref();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 13bd255.

@fghdotio fghdotio force-pushed the feat/rgbpp-core branch from ae815b4 to dc72c80 Compare May 6, 2026 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants