From 9afc2a911e6a4ba8a200755b01159b5b149e4010 Mon Sep 17 00:00:00 2001 From: Shook Date: Thu, 4 Jul 2024 11:46:21 +0800 Subject: [PATCH] feat: add "type_script" in the rgbpp balance api, and add "typeHash" in rgbpp assets apis that return Cell[] --- .changeset/clean-snails-admire.md | 5 +++++ packages/service/src/service/service.ts | 8 ++++---- packages/service/src/types/rgbpp.ts | 13 +++++++++---- packages/service/tests/Service.test.ts | 26 ++++++++++++++++++++----- 4 files changed, 39 insertions(+), 13 deletions(-) create mode 100644 .changeset/clean-snails-admire.md diff --git a/.changeset/clean-snails-admire.md b/.changeset/clean-snails-admire.md new file mode 100644 index 00000000..9c8f37ef --- /dev/null +++ b/.changeset/clean-snails-admire.md @@ -0,0 +1,5 @@ +--- +"@rgbpp-sdk/service": minor +--- + +Add "type_script" in the return type of /rgbpp/v1/address/{btc_address}/balance API, and add "typeHash" in the return type of rgbpp asset APIs diff --git a/packages/service/src/service/service.ts b/packages/service/src/service/service.ts index 62045bd4..e971e335 100644 --- a/packages/service/src/service/service.ts +++ b/packages/service/src/service/service.ts @@ -1,4 +1,3 @@ -import { Cell } from '@ckb-lumos/base'; import { BtcAssetsApiBase } from './base'; import { BtcApis, @@ -18,6 +17,7 @@ import { } from '../types'; import { RgbppApis, + RgbppCell, RgbppApiSpvProof, RgbppApiPaymasterInfo, RgbppApiTransactionState, @@ -117,15 +117,15 @@ export class BtcAssetsApi extends BtcAssetsApiBase implements BtcApis, RgbppApis } getRgbppAssetsByBtcTxId(btcTxId: string) { - return this.request(`/rgbpp/v1/assets/${btcTxId}`); + return this.request(`/rgbpp/v1/assets/${btcTxId}`); } getRgbppAssetsByBtcUtxo(btcTxId: string, vout: number) { - return this.request(`/rgbpp/v1/assets/${btcTxId}/${vout}`); + return this.request(`/rgbpp/v1/assets/${btcTxId}/${vout}`); } getRgbppAssetsByBtcAddress(btcAddress: string, params?: RgbppApiAssetsByAddressParams) { - return this.request(`/rgbpp/v1/address/${btcAddress}/assets`, { + return this.request(`/rgbpp/v1/address/${btcAddress}/assets`, { params, }); } diff --git a/packages/service/src/types/rgbpp.ts b/packages/service/src/types/rgbpp.ts index 6473ca31..a5c8c7c4 100644 --- a/packages/service/src/types/rgbpp.ts +++ b/packages/service/src/types/rgbpp.ts @@ -1,12 +1,12 @@ -import { Cell } from '@ckb-lumos/base'; +import { Cell, Hash, Script } from '@ckb-lumos/base'; export interface RgbppApis { getRgbppPaymasterInfo(): Promise; getRgbppTransactionHash(btcTxId: string): Promise; getRgbppTransactionState(btcTxId: string): Promise; - getRgbppAssetsByBtcTxId(btcTxId: string): Promise; - getRgbppAssetsByBtcUtxo(btcTxId: string, vout: number): Promise; - getRgbppAssetsByBtcAddress(btcAddress: string, params?: RgbppApiAssetsByAddressParams): Promise; + getRgbppAssetsByBtcTxId(btcTxId: string): Promise; + getRgbppAssetsByBtcUtxo(btcTxId: string, vout: number): Promise; + getRgbppAssetsByBtcAddress(btcAddress: string, params?: RgbppApiAssetsByAddressParams): Promise; getRgbppBalanceByBtcAddress(btcAddress: string, params?: RgbppApiBalanceByAddressParams): Promise; getRgbppSpvProof(btcTxId: string, confirmations: number): Promise; sendRgbppCkbTransaction(payload: RgbppApiSendCkbTransactionPayload): Promise; @@ -43,6 +43,10 @@ export interface RgbppApiTransactionState { }; } +export interface RgbppCell extends Cell { + typeHash?: Hash; +} + export interface RgbppApiAssetsByAddressParams { type_script?: string; no_cache?: boolean; @@ -64,6 +68,7 @@ export interface RgbppApiXudtBalance { available_amount: string; pending_amount: string; type_hash: string; + type_script: Script; } export interface RgbppApiSpvProof { diff --git a/packages/service/tests/Service.test.ts b/packages/service/tests/Service.test.ts index e01a1ebd..33486b6e 100644 --- a/packages/service/tests/Service.test.ts +++ b/packages/service/tests/Service.test.ts @@ -1,7 +1,7 @@ -import { Cell, blockchain } from '@ckb-lumos/base'; +import { Cell, blockchain, Script } from '@ckb-lumos/base'; import { bytes } from '@ckb-lumos/codec'; import { describe, expect, it } from 'vitest'; -import { BtcAssetsApiError, BtcAssetsApi, ErrorCodes, ErrorMessages } from '../src'; +import { BtcAssetsApiError, BtcAssetsApi, ErrorCodes, ErrorMessages, RgbppCell } from '../src'; describe( 'BtcServiceApi', @@ -240,7 +240,7 @@ describe( expect(res).toBeDefined(); expect(res.length).toBeGreaterThan(0); for (const cell of res) { - expectCell(cell); + expectRgbppCell(cell); } }); it('getRgbppAssetsByBtcUtxo()', async () => { @@ -248,7 +248,7 @@ describe( expect(res).toBeDefined(); expect(res.length).toBeGreaterThan(0); for (const cell of res) { - expectCell(cell); + expectRgbppCell(cell); } }); it('getRgbppAssetsByBtcAddress()', async () => { @@ -258,7 +258,7 @@ describe( expect(res).toBeDefined(); expect(res.length).toBeGreaterThan(0); for (const cell of res) { - expectCell(cell); + expectRgbppCell(cell); } }); it('getRgbppBalanceByBtcAddress()', async () => { @@ -274,6 +274,7 @@ describe( expect(xudt.available_amount).toBeTypeOf('string'); expect(xudt.pending_amount).toBeTypeOf('string'); expect(xudt.type_hash).toBeTypeOf('string'); + expectScript(xudt.type_script); } }); it('getRgbppSpvProof()', async () => { @@ -316,3 +317,18 @@ function expectCell(cell: Cell) { expect(cell.data).toBeTypeOf('string'); } + +function expectRgbppCell(cell: RgbppCell) { + expectCell(cell); + + if (cell.typeHash) { + expect(cell.typeHash).toBeTypeOf('string'); + } +} + +function expectScript(script: Script) { + expect(script).toBeDefined(); + expect(script.codeHash).toBeTypeOf('string'); + expect(script.hashType).toBeTypeOf('string'); + expect(script.args).toBeTypeOf('string'); +}