@@ -56,9 +56,11 @@ export interface UTXO {
56
56
scriptPubKey: string ;
57
57
}
58
58
59
- export interface Inscription {
60
- // output of the inscription in the format of `txid:vout`
61
- output: string ;
59
+ export interface InscriptionIdentifier {
60
+ // hash of transaction that holds the ordinals/brc-2-/runes etc in the UTXO
61
+ txid: string ;
62
+ // index of the output in the transaction
63
+ vout: number ;
62
64
}
63
65
64
66
// supported networks
@@ -342,25 +344,47 @@ export class OKXWallet extends WalletProvider {
342
344
return await getTipHeight ();
343
345
};
344
346
345
- // Inscriptions(Ordinal/Runes/BRC-20 etc)
346
- getInscriptions = async (): Promise <Inscription []> => {
347
+ getInscriptions = async (): Promise <InscriptionIdentifier []> => {
347
348
if (! this .okxWalletInfo ) {
348
349
throw new Error (" OKX Wallet not connected" );
349
350
}
350
- const inscriptions: Inscription [] = [];
351
+ // max num of iterations to prevent infinite loop
352
+ const MAX_ITERATIONS = 100 ;
353
+ // Fetch inscriptions in batches of 100
354
+ const limit = 100 ;
355
+ const inscriptionIdentifiers: InscriptionIdentifier [] = [];
351
356
let cursor = 0 ;
352
- while (true ) {
353
- const { list } = await this .bitcoinNetworkProvider .getInscriptions (
354
- cursor ,
355
- DEFAULT_INSCRIPTION_LIMIT ,
356
- );
357
- inscriptions .push (... list );
358
- if (list .length < DEFAULT_INSCRIPTION_LIMIT ) {
359
- break ;
357
+ let iterations = 0 ;
358
+ try {
359
+ while (iterations < MAX_ITERATIONS ) {
360
+ const { list } = await this .bitcoinNetworkProvider .getInscriptions (
361
+ cursor ,
362
+ limit ,
363
+ );
364
+ const identifiers = list .map ((i : { output: string }) => {
365
+ const [txid, vout] = i .output .split (" :" );
366
+ return {
367
+ txid ,
368
+ vout ,
369
+ };
370
+ });
371
+ inscriptionIdentifiers .push (... identifiers );
372
+ if (list .length < limit ) {
373
+ break ;
374
+ }
375
+ cursor += limit ;
376
+ iterations ++ ;
377
+ if (iterations >= MAX_ITERATIONS ) {
378
+ throw new Error (
379
+ " Exceeded maximum iterations when fetching inscriptions" ,
380
+ );
381
+ }
360
382
}
361
- cursor += DEFAULT_INSCRIPTION_LIMIT ;
383
+ } catch (error ) {
384
+ throw new Error (" Failed to get inscriptions from OKX Wallet" );
362
385
}
363
- return inscriptions ;
386
+
387
+ return inscriptionIdentifiers ;
364
388
};
365
389
}
366
390
```
0 commit comments