From f50a00a02e3efd3d40fe0d6bbd8b83e1fa109437 Mon Sep 17 00:00:00 2001 From: Dylan Duan Date: Wed, 15 Jan 2025 13:21:54 +0800 Subject: [PATCH] refactor: Update token info to snake case --- src/routes/rgbpp/address.ts | 2 +- src/routes/rgbpp/assets.ts | 2 +- src/services/ckb.ts | 29 +++++++++++++++---- .../services/__snapshots__/rgbpp.test.ts.snap | 6 ++-- 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/routes/rgbpp/address.ts b/src/routes/rgbpp/address.ts index a2e09211..dce98647 100644 --- a/src/routes/rgbpp/address.ts +++ b/src/routes/rgbpp/address.ts @@ -317,7 +317,7 @@ const addressRoutes: FastifyPluginCallback, Server, ZodType { schema: { description: 'Get RGB++ activity by btc address', - tags: ['RGB++@Unstable'], + tags: ['RGB++'], params: z.object({ btc_address: z.string(), }), diff --git a/src/routes/rgbpp/assets.ts b/src/routes/rgbpp/assets.ts index e40b8693..689a56a9 100644 --- a/src/routes/rgbpp/assets.ts +++ b/src/routes/rgbpp/assets.ts @@ -107,7 +107,7 @@ const assetsRoute: FastifyPluginCallback, 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() diff --git a/src/services/ckb.ts b/src/services/ckb.ts index d9b5d0f8..3e406706 100644 --- a/src/services/ckb.ts +++ b/src/services/ckb.ts @@ -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>; @@ -148,7 +148,15 @@ export class CKBRpcError extends Error { } } -type TokenInfoMetadata = TokenInfo & Partial; +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; @@ -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, + }; } /** @@ -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, + }; } /** diff --git a/test/services/__snapshots__/rgbpp.test.ts.snap b/test/services/__snapshots__/rgbpp.test.ts.snap index f9eaa375..b5bb344e 100644 --- a/test/services/__snapshots__/rgbpp.test.ts.snap +++ b/test/services/__snapshots__/rgbpp.test.ts.snap @@ -40,13 +40,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",