Skip to content

Commit

Permalink
Merge pull request #229 from utxostack/fix/xudt-info-response
Browse files Browse the repository at this point in the history
Update token info to snake case
  • Loading branch information
duanyytop authored Jan 15, 2025
2 parents d51d57e + 6ebdea5 commit d918ab9
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 12 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.4",
"version": "2.5.5",
"title": "Bitcoin/RGB++ Assets API",
"description": "",
"main": "index.js",
Expand Down
2 changes: 1 addition & 1 deletion src/routes/rgbpp/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ const addressRoutes: FastifyPluginCallback<Record<never, never>, Server, ZodType
{
schema: {
description: 'Get RGB++ activity by btc address',
tags: ['RGB++@Unstable'],
tags: ['RGB++'],
params: z.object({
btc_address: z.string(),
}),
Expand Down
2 changes: 1 addition & 1 deletion src/routes/rgbpp/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const assetsRoute: FastifyPluginCallback<Record<never, never>, Server, ZodTypePr
{
schema: {
description: 'Get RGB++ assets type info by typescript',
tags: ['RGB++@Unstable'],
tags: ['RGB++'],
querystring: z.object({
type_script: Script.or(z.string())
.optional()
Expand Down
29 changes: 23 additions & 6 deletions src/services/ckb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { scriptToHash } from '@nervosnetwork/ckb-sdk-utils';
import { Cell } from '../routes/rgbpp/types';
import { uniq } from 'lodash';
import { IS_MAINNET } from '../constants';
import { decodeMetadata, decodeTokenInfo, Metadata, TokenInfo } from '@utxostack/metadata';
import { decodeMetadata, decodeTokenInfo } from '@utxostack/metadata';

export type TransactionWithStatus = Awaited<ReturnType<CKBRPC['getTransaction']>>;

Expand Down Expand Up @@ -148,7 +148,15 @@ export class CKBRpcError extends Error {
}
}

type TokenInfoMetadata = TokenInfo & Partial<Metadata>;
type TokenInfoMetadata = {
decimal: number;
name: string;
symbol: string;
total_supply?: string;
issuer?: string;
circulating_supply?: string;
token_info_cell_type_hash?: string;
};
export default class CKBClient {
public rpc: RPC;
public indexer: Indexer;
Expand Down Expand Up @@ -201,8 +209,13 @@ export default class CKBClient {
if (!encodeData) {
return null;
}
const data = decodeTokenInfo(encodeData);
return data;
const { symbol, name, decimal, totalSupply } = decodeTokenInfo(encodeData);
return {
symbol,
name,
decimal,
total_supply: totalSupply,
};
}

/**
Expand All @@ -227,8 +240,12 @@ export default class CKBClient {
if (!encodeData) {
return null;
}
const data = decodeMetadata(encodeData);
return data;
const { issuer, circulatingSupply, tokenInfoCellTypeHash } = decodeMetadata(encodeData);
return {
issuer,
circulating_supply: circulatingSupply,
token_info_cell_type_hash: tokenInfoCellTypeHash,
};
}

/**
Expand Down
7 changes: 4 additions & 3 deletions test/services/__snapshots__/rgbpp.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ exports[`RgbppCollector > getRgbppBalanceByCells: should return the rgbpp balanc
"decimal": 8,
"name": "Unique BBQ",
"symbol": "",
"total_supply": undefined,
"type_hash": "0x78e21efcf107e7886eadeadecd1a01cfb88f1e5617f4438685db55b3a540d202",
"type_script": {
"args": "0x30d3fbec9ceba691770d57c6d06bdb98cf0f82bef0ca6e87687a118d6ce1e7b7",
Expand All @@ -40,13 +41,13 @@ exports[`RgbppCollector > getRgbppBalanceByCells: should return the rgbpp balanc
},
"0xe5ee2fdd79aaa218bd74a821c305fa40305408fae2dbfedf8243ea2b4d7af8e4": {
"amount": "0x0",
"circulatingSupply": "0x0",
"circulating_supply": "0x0",
"decimal": 0,
"issuer": "0x75f11d14d0d8dfc084ce777961cfd9e75ace8c77282217bcc16f57533ea2ee09",
"name": "Pre-claim -Airdrop Badge",
"symbol": "UTXO-AIRDROP",
"tokenInfoCellTypeHash": "0xb18540dcfde52a96232ec865401284b8b94e1692db54f45803e90d93a4e0d9c7",
"totalSupply": "0x3e8",
"token_info_cell_type_hash": "0xb18540dcfde52a96232ec865401284b8b94e1692db54f45803e90d93a4e0d9c7",
"total_supply": "0x3e8",
"type_hash": "0xe5ee2fdd79aaa218bd74a821c305fa40305408fae2dbfedf8243ea2b4d7af8e4",
"type_script": {
"args": "0xa63d308c04b4c075eb1d7d5cac891cf20276e3ddb2ec855fc981c88d8134dbe2",
Expand Down

0 comments on commit d918ab9

Please sign in to comment.