Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(service): add no_cache params to btc/rgbpp service api #181

Merged
merged 3 commits into from
May 20, 2024
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/rude-feet-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rgbpp-sdk/service': patch
---

add no_cache params to btc/rgbpp service api
2 changes: 2 additions & 0 deletions packages/service/src/types/btc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export interface BtcApiRecommendedFeeRates {

export interface BtcApiBalanceParams {
min_satoshi?: number;
no_cache?: boolean;
}
export interface BtcApiBalance {
address: string;
Expand All @@ -70,6 +71,7 @@ export interface BtcApiBalance {
export interface BtcApiUtxoParams {
only_confirmed?: boolean;
min_satoshi?: number;
no_cache?: boolean;
}
export interface BtcApiUtxo {
txid: string;
Expand Down
1 change: 1 addition & 0 deletions packages/service/src/types/rgbpp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface RgbppApiTransactionState {

export interface RgbppApiAssetsByAddressParams {
type_script?: string;
no_cache?: boolean;
}

export interface RgbppApiSpvProof {
Expand Down
23 changes: 21 additions & 2 deletions packages/service/tests/Service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ describe(
expect(filteredBalance.satoshi).toEqual(0);
expect(filteredBalance.dust_satoshi).toEqual(originalBalance.satoshi + originalBalance.dust_satoshi);
});
it('getBtcBalance() with no_cache', async () => {
const res = await service.getBtcBalance(btcAddress, {
no_cache: true,
});
expect(res.address).toEqual(btcAddress);
});
it('getBtcUtxos()', async () => {
const res = await service.getBtcUtxos(btcAddress);
expect(Array.isArray(res)).toBe(true);
Expand Down Expand Up @@ -131,6 +137,12 @@ describe(
expect(utxo.status.confirmed).toBe(true);
}
});
it('getBtcUtxos() with no_cache', async () => {
const utxos = await service.getBtcUtxos(btcAddress, {
no_cache: true,
});
expect(Array.isArray(utxos)).toBe(true);
});
it('getBtcTransactions()', async () => {
const res = await service.getBtcTransactions(btcAddress);
console.log(res.map((tx) => tx.txid));
Expand All @@ -152,13 +164,13 @@ describe(
expect(txs.length).toBeGreaterThan(0);

const filteredTxs = await service.getBtcTransactions(btcAddress, {
after_txid: txs[0].txid,
after_txid: txs[txs.length - 2].txid,
});
expect(Array.isArray(filteredTxs)).toBe(true);

if (txs.length > 1) {
expect(txs.length).toBeGreaterThan(0);
expect(filteredTxs[0].txid).toEqual(txs[1].txid);
expect(filteredTxs[0].txid).toEqual(txs[txs.length - 1].txid);
} else {
expect(filteredTxs).toHaveLength(0);
}
Expand Down Expand Up @@ -248,6 +260,13 @@ describe(
expectCell(cell);
}
});
it('getRgbppAssetsByBtcAddress() with no_cache', async () => {
const res = await service.getRgbppAssetsByBtcAddress(rgbppBtcAddress, {
no_cache: true,
});
expect(res).toBeDefined();
expect(res.length).toBeGreaterThan(0);
});
it('getRgbppSpvProof()', async () => {
const res = await service.getRgbppSpvProof(rgbppBtcTxId, 6);
expect(res).toBeDefined();
Expand Down