Skip to content

Commit 776ec6d

Browse files
committed
chore: add description and notes for the bitcoin.getAddressTxs() limitations
1 parent ed47880 commit 776ec6d

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/routes/rgbpp/address.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,12 @@ const addressRoutes: FastifyPluginCallback<Record<never, never>, Server, ZodType
125125
'/:btc_address/balance',
126126
{
127127
schema: {
128-
description: 'Get RGB++ balance by btc address, support xUDT only for now',
128+
description: `
129+
Get RGB++ balance by btc address, support xUDT only for now.
130+
131+
An address with more than 50 pending BTC transactions is uncommon.
132+
However, if such a situation arises, it potentially affecting the returned total_amount.
133+
`,
129134
tags: ['RGB++'],
130135
params: z.object({
131136
btc_address: z.string(),
@@ -171,7 +176,7 @@ const addressRoutes: FastifyPluginCallback<Record<never, never>, Server, ZodType
171176
const xudtBalances: Record<string, XUDTBalance> = {};
172177
const utxos = await getUxtos(btc_address, no_cache);
173178

174-
// Find confirmed RgbppLock Xudt assets
179+
// Find confirmed RgbppLock XUDT assets
175180
const confirmedUtxos = utxos.filter((utxo) => utxo.status.confirmed);
176181
const confirmedCells = await getRgbppAssetsCells(btc_address, confirmedUtxos, no_cache);
177182
const confirmedTargetCells = filterCellsByTypeScript(confirmedCells, typeScript);
@@ -186,7 +191,7 @@ const addressRoutes: FastifyPluginCallback<Record<never, never>, Server, ZodType
186191
};
187192
});
188193

189-
// Find all unconfirmed RgbppLock Xudt outputs
194+
// Find all unconfirmed RgbppLock XUDT outputs
190195
const pendingUtxos = utxos.filter(
191196
(utxo) =>
192197
!utxo.status.confirmed ||
@@ -220,9 +225,10 @@ const addressRoutes: FastifyPluginCallback<Record<never, never>, Server, ZodType
220225
.toHexString();
221226
});
222227

223-
// Find spent RgbppLock Xudt assets in unconfirmed transactions' inputs
224-
const allTxs = await fastify.bitcoin.getAddressTxs({ address: btc_address });
225-
const unconfirmedTxids = allTxs.filter((tx) => !tx.status.confirmed).map((tx) => tx.txid);
228+
// Find spent RgbppLock XUDT assets in the inputs of the unconfirmed transactions
229+
// XXX: the bitcoin.getAddressTxs() API only returns up to 50 mempool transactions
230+
const latestTxs = await fastify.bitcoin.getAddressTxs({ address: btc_address });
231+
const unconfirmedTxids = latestTxs.filter((tx) => !tx.status.confirmed).map((tx) => tx.txid);
226232
const spendingInputCellsGroup = await Promise.all(
227233
unconfirmedTxids.map(async (txid) => {
228234
const inputCells = await fastify.transactionProcessor.getPendingInputCellsByTxid(txid);

0 commit comments

Comments
 (0)