Skip to content

Commit

Permalink
feat: add BtcAssetsApi.getRgbppApiBalanceByAddress() API for querying…
Browse files Browse the repository at this point in the history
… RGBPP XUDT balances
  • Loading branch information
ShookLyngs committed Jun 5, 2024
1 parent 38eb226 commit e5f41fd
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/silly-rules-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rgbpp-sdk/service": minor
---

Add BtcAssetsApi.getRgbppApiBalanceByAddress() API for querying RGBPP XUDT balances by a BTC address
8 changes: 8 additions & 0 deletions packages/service/src/service/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import {
RgbppApiSendCkbTransactionPayload,
RgbppApiCkbTransactionHash,
RgbppApiAssetsByAddressParams,
RgbppApiBalanceByAddressParams,
RgbppApiBalance,
RgbppApiRetryCkbTransactionPayload,
RgbppApiTransactionStateParams,
RgbppApiTransactionRetry,
Expand Down Expand Up @@ -128,6 +130,12 @@ export class BtcAssetsApi extends BtcAssetsApiBase implements BtcApis, RgbppApis
});
}

getRgbppBalanceByBtcAddress(btcAddress: string, params?: RgbppApiBalanceByAddressParams) {
return this.request<RgbppApiBalance>(`/rgbpp/v1/address/${btcAddress}/balance`, {
params,
});
}

getRgbppSpvProof(btcTxId: string, confirmations: number) {
return this.request<RgbppApiSpvProof>('/rgbpp/v1/btc-spv/proof', {
params: {
Expand Down
19 changes: 19 additions & 0 deletions packages/service/src/types/rgbpp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface RgbppApis {
getRgbppAssetsByBtcTxId(btcTxId: string): Promise<Cell[]>;
getRgbppAssetsByBtcUtxo(btcTxId: string, vout: number): Promise<Cell[]>;
getRgbppAssetsByBtcAddress(btcAddress: string, params?: RgbppApiAssetsByAddressParams): Promise<Cell[]>;
getRgbppBalanceByBtcAddress(btcAddress: string, params?: RgbppApiBalanceByAddressParams): Promise<RgbppApiBalance>;
getRgbppSpvProof(btcTxId: string, confirmations: number): Promise<RgbppApiSpvProof>;
sendRgbppCkbTransaction(payload: RgbppApiSendCkbTransactionPayload): Promise<RgbppApiTransactionState>;
retryRgbppCkbTransaction(payload: RgbppApiRetryCkbTransactionPayload): Promise<RgbppApiTransactionRetry>;
Expand Down Expand Up @@ -47,6 +48,24 @@ export interface RgbppApiAssetsByAddressParams {
no_cache?: boolean;
}

export interface RgbppApiBalanceByAddressParams {
type_script?: string;
no_cache?: boolean;
}
export interface RgbppApiBalance {
address: string;
xudt: RgbppApiXudtBalance[];
}
export interface RgbppApiXudtBalance {
name: string;
decimal: number;
symbol: string;
total_amount: string;
available_amount: string;
pending_amount: string;
type_hash: string;
}

export interface RgbppApiSpvProof {
proof: string;
spv_client: {
Expand Down
18 changes: 13 additions & 5 deletions packages/service/tests/Service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,20 @@ describe(
expectCell(cell);
}
});
it('getRgbppAssetsByBtcAddress() with no_cache', async () => {
const res = await service.getRgbppAssetsByBtcAddress(rgbppBtcAddress, {
no_cache: true,
});
it('getRgbppBalanceByBtcAddress()', async () => {
const res = await service.getRgbppBalanceByBtcAddress(rgbppBtcAddress);
expect(res).toBeDefined();
expect(res.length).toBeGreaterThan(0);
expect(res.address).toBeTypeOf('string');
expect(res.xudt.length).toBeGreaterThan(0);
for (const xudt of res.xudt) {
expect(xudt.name).toBeTypeOf('string');
expect(xudt.decimal).toBeTypeOf('number');
expect(xudt.symbol).toBeTypeOf('string');
expect(xudt.total_amount).toBeTypeOf('string');
expect(xudt.available_amount).toBeTypeOf('string');
expect(xudt.pending_amount).toBeTypeOf('string');
expect(xudt.type_hash).toBeTypeOf('string');
}
});
it('getRgbppSpvProof()', async () => {
const res = await service.getRgbppSpvProof(rgbppBtcTxId, 6);
Expand Down

1 comment on commit e5f41fd

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New snapshot version of the rgbpp-sdk packages have been released:

Name Version
@rgbpp-sdk/btc 0.0.0-snap-20240605095408

Please sign in to comment.