@@ -161,14 +161,14 @@ export interface ApiProvider {
161161
162162export class MintlayerApiProvider implements ApiProvider {
163163 private readonly baseUrl : string ;
164- private readonly utxoUrl : string ;
164+ private readonly batchUrl : string ;
165165
166166 constructor (
167167 baseUrl : string ,
168- utxoUrl : string = 'https://api.mintini.app' ,
168+ batchUrl : string ,
169169 ) {
170170 this . baseUrl = baseUrl . replace ( / \/ $ / , '' ) ;
171- this . utxoUrl = utxoUrl . replace ( / \/ $ / , '' ) ;
171+ this . batchUrl = batchUrl . replace ( / \/ $ / , '' ) ;
172172 }
173173
174174 private async get ( path : string ) : Promise < any > {
@@ -239,15 +239,20 @@ export class MintlayerApiProvider implements ApiProvider {
239239 }
240240
241241 async getAccountUtxos ( addresses : string [ ] , network : number ) : Promise < any > {
242- const response = await fetch ( ` ${ this . utxoUrl } /account` , {
242+ const response = await fetch ( this . batchUrl , {
243243 method : 'POST' ,
244244 headers : { 'Content-Type' : 'application/json' } ,
245- body : JSON . stringify ( { addresses, network } ) ,
245+ body : JSON . stringify ( {
246+ ids : addresses ,
247+ type : '/address/:address/spendable-utxos' ,
248+ network,
249+ } ) ,
246250 } ) ;
247251 if ( ! response . ok ) {
248252 throw new Error ( `Failed to fetch utxos: ${ response . status } ` ) ;
249253 }
250- return response . json ( ) ;
254+ const data = await response . json ( ) ;
255+ return ( data . results ?? [ ] ) . flat ( ) ;
251256 }
252257}
253258
@@ -1222,7 +1227,7 @@ class Client {
12221227 this . publicKeys = { receiving : [ ] , change : [ ] } ;
12231228 this . isInitialized = false ;
12241229 this . accountProvider = options . accountProvider || new MojitoAccountProvider ( ) ;
1225- this . apiProvider = options . apiProvider || new MintlayerApiProvider ( this . getDefaultApiServer ( ) ) ;
1230+ this . apiProvider = options . apiProvider || new MintlayerApiProvider ( this . getDefaultApiServer ( ) , this . getDefaultBatchServer ( ) ) ;
12261231 }
12271232
12281233 /**
@@ -1332,6 +1337,16 @@ class Client {
13321337 : 'https://api-server.mintlayer.org/api/v2' ;
13331338 }
13341339
1340+ /**
1341+ * Returns the default batch server URL based on the network.
1342+ * @private
1343+ */
1344+ private getDefaultBatchServer ( ) : string {
1345+ return this . network === 'testnet'
1346+ ? 'https://mojito-api.mintlayer.org/mintlayer/testnet/batch'
1347+ : 'https://mojito-api.mintlayer.org/mintlayer/mainnet/batch' ;
1348+ }
1349+
13351350 /**
13361351 * Initializes the SDK.
13371352 * @private
@@ -2419,7 +2434,7 @@ class Client {
24192434 const currentAddress = address ;
24202435 const addressList = [ ...currentAddress . receiving , ...currentAddress . change ] ;
24212436
2422- const data = await this . apiProvider . getAccountUtxos (
2437+ const data_utxos = await this . apiProvider . getAccountUtxos (
24232438 addressList ,
24242439 this . network === 'mainnet' ? 0 : 1 ,
24252440 ) ;
@@ -2433,7 +2448,7 @@ class Client {
24332448 utxo : item . utxo ,
24342449 } ) ) : [ ] ;
24352450
2436- const utxos : UtxoEntry [ ] = data . utxos . filter ( ( item : UtxoEntry ) => {
2451+ const utxos : UtxoEntry [ ] = data_utxos . filter ( ( item : UtxoEntry ) => {
24372452 // filter out UTXO with type htlc, they have to be added manually
24382453 if ( item . utxo . type === 'Htlc' ) {
24392454 return false ;
0 commit comments