Skip to content

Commit

Permalink
Merge pull request #227 from utxostack/fix/utxo-airdrop-support
Browse files Browse the repository at this point in the history
Support UTXO Airdrop Badge type script
  • Loading branch information
duanyytop authored Jan 15, 2025
2 parents 243a2b0 + 4addad7 commit 5be1dac
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
15 changes: 12 additions & 3 deletions src/routes/rgbpp/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -116,7 +122,7 @@ const addressRoutes: FastifyPluginCallback<Record<never, never>, 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.
Expand Down Expand Up @@ -155,7 +161,10 @@ const addressRoutes: FastifyPluginCallback<Record<never, never>, 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');
}

Expand Down
6 changes: 4 additions & 2 deletions src/routes/rgbpp/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -144,7 +144,9 @@ const assetsRoute: FastifyPluginCallback<Record<never, never>, Server, ZodTypePr
if (!typeScript) {
return null;
}
if (isUDTTypeSupported(typeScript, IS_MAINNET)) {
// 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);
if (!infoCell) {
Expand Down

0 comments on commit 5be1dac

Please sign in to comment.