Skip to content
This repository was archived by the owner on May 27, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/clean-snails-admire.md
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions packages/service/src/service/service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Cell } from '@ckb-lumos/base';
import { BtcAssetsApiBase } from './base';
import {
BtcApis,
Expand All @@ -18,6 +17,7 @@ import {
} from '../types';
import {
RgbppApis,
RgbppCell,
RgbppApiSpvProof,
RgbppApiPaymasterInfo,
RgbppApiTransactionState,
Expand Down Expand Up @@ -117,15 +117,15 @@ export class BtcAssetsApi extends BtcAssetsApiBase implements BtcApis, RgbppApis
}

getRgbppAssetsByBtcTxId(btcTxId: string) {
return this.request<Cell[]>(`/rgbpp/v1/assets/${btcTxId}`);
return this.request<RgbppCell[]>(`/rgbpp/v1/assets/${btcTxId}`);
}

getRgbppAssetsByBtcUtxo(btcTxId: string, vout: number) {
return this.request<Cell[]>(`/rgbpp/v1/assets/${btcTxId}/${vout}`);
return this.request<RgbppCell[]>(`/rgbpp/v1/assets/${btcTxId}/${vout}`);
}

getRgbppAssetsByBtcAddress(btcAddress: string, params?: RgbppApiAssetsByAddressParams) {
return this.request<Cell[]>(`/rgbpp/v1/address/${btcAddress}/assets`, {
return this.request<RgbppCell[]>(`/rgbpp/v1/address/${btcAddress}/assets`, {
params,
});
}
Expand Down
13 changes: 9 additions & 4 deletions packages/service/src/types/rgbpp.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Cell } from '@ckb-lumos/base';
import { Cell, Hash, Script } from '@ckb-lumos/base';

export interface RgbppApis {
getRgbppPaymasterInfo(): Promise<RgbppApiPaymasterInfo>;
getRgbppTransactionHash(btcTxId: string): Promise<RgbppApiCkbTransactionHash>;
getRgbppTransactionState(btcTxId: string): Promise<RgbppApiTransactionState>;
getRgbppAssetsByBtcTxId(btcTxId: string): Promise<Cell[]>;
getRgbppAssetsByBtcUtxo(btcTxId: string, vout: number): Promise<Cell[]>;
getRgbppAssetsByBtcAddress(btcAddress: string, params?: RgbppApiAssetsByAddressParams): Promise<Cell[]>;
getRgbppAssetsByBtcTxId(btcTxId: string): Promise<RgbppCell[]>;
getRgbppAssetsByBtcUtxo(btcTxId: string, vout: number): Promise<RgbppCell[]>;
getRgbppAssetsByBtcAddress(btcAddress: string, params?: RgbppApiAssetsByAddressParams): Promise<RgbppCell[]>;
getRgbppBalanceByBtcAddress(btcAddress: string, params?: RgbppApiBalanceByAddressParams): Promise<RgbppApiBalance>;
getRgbppSpvProof(btcTxId: string, confirmations: number): Promise<RgbppApiSpvProof>;
sendRgbppCkbTransaction(payload: RgbppApiSendCkbTransactionPayload): Promise<RgbppApiTransactionState>;
Expand Down Expand Up @@ -43,6 +43,10 @@ export interface RgbppApiTransactionState {
};
}

export interface RgbppCell extends Cell {
typeHash?: Hash;
}

export interface RgbppApiAssetsByAddressParams {
type_script?: string;
no_cache?: boolean;
Expand All @@ -64,6 +68,7 @@ export interface RgbppApiXudtBalance {
available_amount: string;
pending_amount: string;
type_hash: string;
type_script: Script;
}

export interface RgbppApiSpvProof {
Expand Down
26 changes: 21 additions & 5 deletions packages/service/tests/Service.test.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -240,15 +240,15 @@ describe(
expect(res).toBeDefined();
expect(res.length).toBeGreaterThan(0);
for (const cell of res) {
expectCell(cell);
expectRgbppCell(cell);
}
});
it('getRgbppAssetsByBtcUtxo()', async () => {
const res = await service.getRgbppAssetsByBtcUtxo(rgbppBtcTxId, rgbppBtcVout);
expect(res).toBeDefined();
expect(res.length).toBeGreaterThan(0);
for (const cell of res) {
expectCell(cell);
expectRgbppCell(cell);
}
});
it('getRgbppAssetsByBtcAddress()', async () => {
Expand All @@ -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 () => {
Expand All @@ -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 () => {
Expand Down Expand Up @@ -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');
}
61 changes: 60 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.