@@ -132,9 +132,14 @@ export class BlockchainExplorer implements IBlockchainExplorer {
132
132
return info ;
133
133
}
134
134
135
- async getContractCreation ( address : TAddress ) : Promise < { creator : TAddress , txHash : TEth . Hex } > {
135
+ private formatUri ( query : string ) {
136
136
let apiUrl = this . config . api . url ;
137
- let url = `${ apiUrl } ?module=contract&action=getcontractcreation&contractaddresses=${ address } &apikey=${ this . config . api . key } ` ;
137
+ let c = apiUrl . includes ( '?' ) ? '&' : '?' ;
138
+ return `${ apiUrl } ${ c } ${ query } &apikey=${ this . config . api . key } `
139
+ }
140
+
141
+ async getContractCreation ( address : TAddress ) : Promise < { creator : TAddress , txHash : TEth . Hex } > {
142
+ let url = this . formatUri ( `module=contract&action=getcontractcreation&contractaddresses=${ address } ` ) ;
138
143
let result = await this . client . get ( url ) ;
139
144
let json = Array . isArray ( result ) ? result [ 0 ] : result ;
140
145
if ( json == null ) {
@@ -163,8 +168,7 @@ export class BlockchainExplorer implements IBlockchainExplorer {
163
168
return { abi : info . abi , implementation : address }
164
169
}
165
170
166
- let apiUrl = this . config . api . url ;
167
- let url = `${ apiUrl } ?module=contract&action=getabi&address=${ address } &apikey=${ this . config . api . key } ` ;
171
+ let url = this . formatUri ( `module=contract&action=getabi&address=${ address } ` ) ;
168
172
let abi : string ;
169
173
170
174
try {
@@ -324,8 +328,8 @@ export class BlockchainExplorer implements IBlockchainExplorer {
324
328
ContractName : string
325
329
ABI : string
326
330
} > {
327
- let apiUrl = this . config . api . url ;
328
- let url = ` ${ apiUrl } ? module=contract&action=getsourcecode&address=${ address } &apikey= ${ this . config . api . key } ` ;
331
+
332
+ let url = this . formatUri ( ` module=contract&action=getsourcecode&address=${ address } ` ) ;
329
333
let result = await this . client . get ( url ) ;
330
334
let json = Array . isArray ( result ) ? result [ 0 ] : result ;
331
335
@@ -458,8 +462,7 @@ export class BlockchainExplorer implements IBlockchainExplorer {
458
462
size ?: number ,
459
463
sort ?: 'asc' | 'desc'
460
464
} ) {
461
- let apiUrl = this . config . api . url ;
462
- let url = `${ apiUrl } ?module=account&action=${ type } &address=${ address } &sort=${ params . sort ?? 'desc' } &apikey=${ this . config . api . key } ` ;
465
+ let url = this . formatUri ( `module=account&action=${ type } &address=${ address } &sort=${ params . sort ?? 'desc' } ` ) ;
463
466
if ( params . fromBlockNumber != null ) {
464
467
url += `&startblock=${ params . fromBlockNumber } `
465
468
}
0 commit comments