@@ -125,7 +125,12 @@ const addressRoutes: FastifyPluginCallback<Record<never, never>, Server, ZodType
125
125
'/:btc_address/balance' ,
126
126
{
127
127
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
+ ` ,
129
134
tags : [ 'RGB++' ] ,
130
135
params : z . object ( {
131
136
btc_address : z . string ( ) ,
@@ -171,7 +176,7 @@ const addressRoutes: FastifyPluginCallback<Record<never, never>, Server, ZodType
171
176
const xudtBalances : Record < string , XUDTBalance > = { } ;
172
177
const utxos = await getUxtos ( btc_address , no_cache ) ;
173
178
174
- // Find confirmed RgbppLock Xudt assets
179
+ // Find confirmed RgbppLock XUDT assets
175
180
const confirmedUtxos = utxos . filter ( ( utxo ) => utxo . status . confirmed ) ;
176
181
const confirmedCells = await getRgbppAssetsCells ( btc_address , confirmedUtxos , no_cache ) ;
177
182
const confirmedTargetCells = filterCellsByTypeScript ( confirmedCells , typeScript ) ;
@@ -186,7 +191,7 @@ const addressRoutes: FastifyPluginCallback<Record<never, never>, Server, ZodType
186
191
} ;
187
192
} ) ;
188
193
189
- // Find all unconfirmed RgbppLock Xudt outputs
194
+ // Find all unconfirmed RgbppLock XUDT outputs
190
195
const pendingUtxos = utxos . filter (
191
196
( utxo ) =>
192
197
! utxo . status . confirmed ||
@@ -220,9 +225,10 @@ const addressRoutes: FastifyPluginCallback<Record<never, never>, Server, ZodType
220
225
. toHexString ( ) ;
221
226
} ) ;
222
227
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 ) ;
226
232
const spendingInputCellsGroup = await Promise . all (
227
233
unconfirmedTxids . map ( async ( txid ) => {
228
234
const inputCells = await fastify . transactionProcessor . getPendingInputCellsByTxid ( txid ) ;
0 commit comments