From bc73dc6ead8e88b93713a200d5c25035a0385f8c Mon Sep 17 00:00:00 2001 From: Dylan Duan Date: Tue, 14 Jan 2025 20:56:02 +0800 Subject: [PATCH 1/2] fix: Support UTXO Airdrop Badge type script --- src/routes/rgbpp/address.ts | 16 +++++++++++++--- src/routes/rgbpp/assets.ts | 6 ++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/routes/rgbpp/address.ts b/src/routes/rgbpp/address.ts index 37b6a9cd..43ea8a52 100644 --- a/src/routes/rgbpp/address.ts +++ b/src/routes/rgbpp/address.ts @@ -5,7 +5,13 @@ import { ZodTypeProvider } from 'fastify-type-provider-zod'; import { CKBTransaction, Cell, IsomorphicTransaction, Script, XUDTBalance } from './types'; import z from 'zod'; import { Env } from '../../env'; -import { isScriptEqual, buildPreLockArgs, getXudtTypeScript, isTypeAssetSupported } from '@rgbpp-sdk/ckb'; +import { + isScriptEqual, + buildPreLockArgs, + getXudtTypeScript, + isTypeAssetSupported, + isUtxoAirdropBadgeType, +} from '@rgbpp-sdk/ckb'; import { groupBy, uniq } from 'lodash'; import { BI } from '@ckb-lumos/lumos'; import { UTXO } from '../../services/bitcoin/schema'; @@ -116,7 +122,7 @@ const addressRoutes: FastifyPluginCallback, Server, ZodType { schema: { description: ` - Get RGB++ balance by btc address, support xUDT only for now. + Get RGB++ balance by btc address, support xUDT, compatible-xUDT and Pre-claim UTXO Airdrop Badge for now. An address with more than 50 pending BTC transactions is uncommon. However, if such a situation arises, it potentially affecting the returned total_amount. @@ -155,7 +161,11 @@ const addressRoutes: FastifyPluginCallback, Server, ZodType const { no_cache } = request.query; const typeScript = getTypeScript(request.query.type_script); - if (!typeScript || !isTypeAssetSupported(typeScript, IS_MAINNET)) { + if ( + !typeScript || + !isTypeAssetSupported(typeScript, IS_MAINNET) || + !isUtxoAirdropBadgeType(typeScript, IS_MAINNET) + ) { throw fastify.httpErrors.badRequest('Unsupported type asset'); } diff --git a/src/routes/rgbpp/assets.ts b/src/routes/rgbpp/assets.ts index e4e4a651..6165c363 100644 --- a/src/routes/rgbpp/assets.ts +++ b/src/routes/rgbpp/assets.ts @@ -5,7 +5,7 @@ import z from 'zod'; import { Cell, Script, SporeTypeInfo, XUDTTypeInfo } from './types'; import { UTXO } from '../../services/bitcoin/schema'; import { getTypeScript } from '../../utils/typescript'; -import { IndexerCell, isSporeTypeSupported, isUDTTypeSupported } from '@rgbpp-sdk/ckb'; +import { IndexerCell, isSporeTypeSupported, isUDTTypeSupported, isUtxoAirdropBadgeType } from '@rgbpp-sdk/ckb'; import { computeScriptHash } from '@ckb-lumos/lumos/utils'; import { getSporeConfig, unpackToRawClusterData, unpackToRawSporeData } from '../../utils/spore'; import { SearchKey } from '../../services/rgbpp'; @@ -144,7 +144,9 @@ const assetsRoute: FastifyPluginCallback, Server, ZodTypePr if (!typeScript) { return null; } - if (isUDTTypeSupported(typeScript, IS_MAINNET)) { + // The pre-claimed airdrop badge type is not fully compatible with the standard xUDT type + // and its token info and metadata should be decoded from the info cells. + if (isUDTTypeSupported(typeScript, IS_MAINNET) || isUtxoAirdropBadgeType(typeScript, IS_MAINNET)) { const infoCell = await fastify.ckb.getInfoCellData(typeScript); const typeHash = computeScriptHash(typeScript); if (!infoCell) { From 4addad70b6b85844b0df3c2f7e9bd3f97f0d6c4a Mon Sep 17 00:00:00 2001 From: Dylan Duan Date: Tue, 14 Jan 2025 20:56:46 +0800 Subject: [PATCH 2/2] chore: Bump version to v2.5.3 --- package.json | 2 +- src/routes/rgbpp/address.ts | 3 +-- src/routes/rgbpp/assets.ts | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index c9102256..7f0a2e28 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "btc-assets-api", - "version": "2.5.2", + "version": "2.5.3", "title": "Bitcoin/RGB++ Assets API", "description": "", "main": "index.js", diff --git a/src/routes/rgbpp/address.ts b/src/routes/rgbpp/address.ts index 43ea8a52..a2e09211 100644 --- a/src/routes/rgbpp/address.ts +++ b/src/routes/rgbpp/address.ts @@ -163,8 +163,7 @@ const addressRoutes: FastifyPluginCallback, Server, ZodType const typeScript = getTypeScript(request.query.type_script); if ( !typeScript || - !isTypeAssetSupported(typeScript, IS_MAINNET) || - !isUtxoAirdropBadgeType(typeScript, IS_MAINNET) + !(isTypeAssetSupported(typeScript, IS_MAINNET) || isUtxoAirdropBadgeType(typeScript, IS_MAINNET)) ) { throw fastify.httpErrors.badRequest('Unsupported type asset'); } diff --git a/src/routes/rgbpp/assets.ts b/src/routes/rgbpp/assets.ts index 6165c363..e40b8693 100644 --- a/src/routes/rgbpp/assets.ts +++ b/src/routes/rgbpp/assets.ts @@ -144,8 +144,8 @@ const assetsRoute: FastifyPluginCallback, Server, ZodTypePr if (!typeScript) { return null; } - // The pre-claimed airdrop badge type is not fully compatible with the standard xUDT type - // and its token info and metadata should be decoded from the info cells. + // The pre-claimed airdrop badge type script asset is not fully compatible with the standard xUDT + // type script and its token info and metadata should be decoded from the info cells. if (isUDTTypeSupported(typeScript, IS_MAINNET) || isUtxoAirdropBadgeType(typeScript, IS_MAINNET)) { const infoCell = await fastify.ckb.getInfoCellData(typeScript); const typeHash = computeScriptHash(typeScript);