Skip to content

Commit e6a6948

Browse files
committed
Update parameters logic
1 parent dd93eb7 commit e6a6948

File tree

5 files changed

+286
-177
lines changed

5 files changed

+286
-177
lines changed

index.d.ts

Lines changed: 131 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -267,26 +267,36 @@ declare class EtherscanApi {
267267
/**
268268
* Returns Ether balance for a single address
269269
* @param {string} address Address
270-
* @param {string} [unit=wei] Balance unit
270+
* @param {object} [options]
271+
* @param {string} [options.unit=wei] Balance unit
272+
* @param {string} [options.tag=latest]
271273
* @returns {Promise<string>}
274+
* @todo Write test for options
272275
*/
273276
getAccountBalance(
274277
address: string,
275-
unit?: keyof UNITS,
276-
tag?: string
278+
options?: {
279+
unit?: keyof UNITS
280+
tag?: string
281+
}
277282
): Promise<string>
278283

279284
/**
280285
* Returns Ether balance for multiple addresses in a single call.
281286
* Up to a maximum of 20 accounts in a single batch.
282287
* @param {Array<string>} addresses List of addresses
283-
* @param {string} [unit=wei] Balance unit
284-
* @returns {Promise<object>}
288+
* @param {object} [options]
289+
* @param {string} [options.unit=wei] Balance unit
290+
* @param {string} [options.tag=latest]
291+
* @return {Promise<object>}
292+
* @todo Write test for options
285293
*/
286294
getAccountBalances(
287295
addresses: string[],
288-
unit?: keyof UNITS,
289-
tag?: string
296+
options?: {
297+
unit?: keyof UNITS
298+
tag?: string
299+
}
290300
): Promise<
291301
{
292302
account: string
@@ -295,43 +305,53 @@ declare class EtherscanApi {
295305
>
296306

297307
/**
298-
* Get a list of 'Normal' transactions by address
299-
* Returns up to a maximum of the last 10000 transactions only
308+
* Returns a list of 'Normal' transactions by address.
309+
* Returns up to a maximum of the last 10000 transactions only.
300310
* @param {string} address Contract address
301-
* @param {string|number} startBlock Starting block number to retrieve results
302-
* @param {string|number} endBlock Ending block number to retrieve results
303-
* @param {number} offset Max records to return
304-
* @param {number} page Page number
305-
* @param {"asc"|"desc"} sort Sort type
311+
* @param {object} [options]
312+
* @param {object} [options.startBlock] Starting block number to retrieve
313+
* results
314+
* @param {string|number} [options.endBlock] Ending block number to retrieve
315+
* results
316+
* @param {number} [options.offset] Max records to return
317+
* @param {number} [options.page] Page number
318+
* @param {"asc"|"desc"} [options.sort] Sort type
306319
* @returns {Promise<object[]>}
307320
*/
308321
getTransactions(
309322
address: string,
310-
startBlock?: number,
311-
endBlock?: number,
312-
offset?: number,
313-
page?: number,
314-
sort?: 'asc' | 'desc'
323+
options?: {
324+
startBlock?: number
325+
endBlock?: number
326+
offset?: number
327+
page?: number
328+
sort?: 'asc' | 'desc'
329+
}
315330
): Promise<TransactionDescription[]>
316331

317332
/**
318-
* Returns a list of 'Internal' Transactions by Address
319-
* Returns up to a maximum of the last 10000 transactions only
333+
* Returns a list of 'Internal' Transactions by Address.
334+
* Returns up to a maximum of the last 10000 transactions only.
320335
* @param {string} address Contract address
321-
* @param {string|number} startBlock Starting block number to retrieve results
322-
* @param {string|number} endBlock Ending block number to retrieve results
323-
* @param {string|number} offset Max records to return
324-
* @param {string|number} page Page number
325-
* @param {"asc"|"desc"} sort Sort type
336+
* @param {object} [options]
337+
* @param {string|number} [options.startBlock] Starting block number to
338+
* retrieve results
339+
* @param {string|number} [options.endBlock] Ending block number to
340+
* retrieve results
341+
* @param {string|number} [options.offset] Max records to return
342+
* @param {string|number} [options.page] Page number
343+
* @param {"asc"|"desc"} [options.sort] Sort type
326344
* @returns {Promise<object[]>}
327345
*/
328346
getInternalTransactions(
329347
address: string,
330-
startBlock?: number,
331-
endBlock?: number,
332-
offset?: number,
333-
page?: number,
334-
sort?: 'asc' | 'desc'
348+
options?: {
349+
startBlock?: number
350+
endBlock?: number
351+
offset?: number
352+
page?: number
353+
sort?: 'asc' | 'desc'
354+
}
335355
): Promise<InternalTransactionDescription[]>
336356

337357
/**
@@ -346,17 +366,20 @@ declare class EtherscanApi {
346366
/**
347367
* List of blocks mined by address
348368
* @param {string} address Miner address
349-
* @param {"blocks"|"uncles"} type Type of block: blocks (full blocks only)
350-
* or uncles (uncle blocks only)
351-
* @param {number} offset Max records to return
352-
* @param {number} page Page number
369+
* @param {object} [options]
370+
* @param {"blocks"|"uncles"} [options.type] Type of block:
371+
* blocks (full blocks only) or uncles (uncle blocks only)
372+
* @param {number} [options.offset] Max records to return
373+
* @param {number} [options.page] Page number
353374
* @returns {Promise<object[]>}
354375
*/
355376
getMinedBlocks(
356377
address: string,
357-
type?: 'blocks' | 'uncles',
358-
offset?: number,
359-
page?: number
378+
options?: {
379+
type?: 'blocks' | 'uncles'
380+
offset?: number
381+
page?: number
382+
}
360383
): Promise<BlockInfo[]>
361384

362385
/**
@@ -402,35 +425,42 @@ declare class EtherscanApi {
402425
/**
403426
* Returns events logs.
404427
* The Event Log API was designed to provide an alternative to the native
405-
* eth_getLogs. Topic Operator (opr) choices are either 'and' or 'or' and
406-
* are restricted to the above choices only. For performance and security
428+
* eth_getLogs. Topic Operator choices are either 'and' or 'or' and are
429+
* restricted to the above choices only. For performance and security
407430
* considerations, only the first 1000 results are return.
408431
* @param {string} address
409-
* @param {number} fromBlock Start block number (integer, NOT hex)
410-
* @param {number|'latest'} toBlock End block number or "latest"
432+
* @param {object} options
433+
* @param {number} options.fromBlock Start block number (integer, NOT hex)
434+
* @param {number|'latest'} options.toBlock End block number or "latest"
411435
* (earliest and pending is NOT supported yet)
412-
* @param {string} topic0 Topic 0
413-
* @param {"and"|"or"} [topic01operator] Operator between topic0 & topic1
414-
* @param {string} [topic1] Topic 1
415-
* @param {"and"|"or"} [topic12operator] Operator between topic1 & topic2
416-
* @param {string} [topic2] Topic 2
417-
* @param {"and"|"or"} [topic23operator] Operator between topic2 & topic3
418-
* @param {string} [topic3] Topic 3
419-
* @param {"and"|"or"} [topic02operator] Operator between topic0 & topic2
436+
* @param {string} options.topic0 Topic 0
437+
* @param {"and"|"or"} [options.topic01operator] Operator between topic0 &
438+
* topic1
439+
* @param {string} [options.topic1] Topic 1
440+
* @param {"and"|"or"} [options.topic12operator] Operator between topic1 &
441+
* topic2
442+
* @param {string} [options.topic2] Topic 2
443+
* @param {"and"|"or"} [options.topic23operator] Operator between topic2 &
444+
* topic3
445+
* @param {string} [options.topic3] Topic 3
446+
* @param {"and"|"or"} [options.topic02operator] Operator between topic0 &
447+
* topic2
420448
* @return {Promise<object>}
421449
*/
422450
getEventsLogs(
423451
address: string,
424-
fromBlock: number,
425-
toBlock: number | 'latest',
426-
topic0?: string,
427-
topic01operator?: 'and' | 'or',
428-
topic1?: string,
429-
topic12operator?: 'and' | 'or',
430-
topic2?: string,
431-
topic23operator?: 'and' | 'or',
432-
topic3?: string,
433-
topic02operator?: 'and' | 'or'
452+
options: {
453+
fromBlock: number
454+
toBlock: number | 'latest'
455+
topic0?: string
456+
topic01operator?: 'and' | 'or'
457+
topic1?: string
458+
topic12operator?: 'and' | 'or'
459+
topic2?: string
460+
topic23operator?: 'and' | 'or'
461+
topic3?: string
462+
topic02operator?: 'and' | 'or'
463+
}
434464
): Promise<EventDescription[]>
435465

436466
/**
@@ -487,9 +517,14 @@ declare class EtherscanApi {
487517
/**
488518
* Returns the number of transactions sent from an address
489519
* @param {string} address Transaction address
520+
* @param {object} [options]
521+
* @param {string} [options.tag=latest]
490522
* @returns {Promise<number>}
491523
*/
492-
getTransactionCount(address: string, tag?: string): Promise<number>
524+
getTransactionCount(
525+
address: string,
526+
options?: { tag?: string }
527+
): Promise<number>
493528

494529
/**
495530
* Creates new message call transaction or a contract creation for signed
@@ -510,46 +545,60 @@ declare class EtherscanApi {
510545
* the block chain
511546
* @param {string} to Address to execute from
512547
* @param {string} data Data to transfer
548+
* @param {object} [options]
549+
* @param {string} [options.tag=latest]
513550
* @returns {Promise<string>}
514551
*/
515-
call(to: string, data: string, tag?: string): Promise<string>
552+
call(to: string, data: string, options?: { tag?: string }): Promise<string>
516553

517554
/**
518555
* Returns code at a given address
519556
* @param {string} address
557+
* @param {object} [options]
558+
* @param {string} [options.tag=latest]
520559
* @returns {Promise<string>}
521560
*/
522-
getCode(address: string, tag?: string): Promise<string>
561+
getCode(address: string, options?: { tag?: string }): Promise<string>
523562

524563
/**
525564
* Returns the value from a storage position at a given address.
526565
* @param {string} address
527566
* @param {number} position
567+
* @param {object} [options]
568+
* @param {string} [options.tag=latest]
528569
* @returns {Promise<string>}
529570
*/
530-
getStorageAt(address: string, position: number, tag?: string): Promise<string>
571+
getStorageAt(
572+
address: string,
573+
position: number,
574+
options?: { tag?: string }
575+
): Promise<string>
531576

532577
/**
533578
* Returns the current price per gas (in wei by default)
534-
* @param {string} [unit=wei] Unit of gas
579+
* @param {object} [options]
580+
* @param {string} [options.unit=wei] Unit of gas
535581
* @returns {Promise<string>}
536582
*/
537-
getGasPrice(unit?: keyof UNITS): Promise<string>
583+
getGasPrice(options?: { unit?: keyof UNITS }): Promise<string>
538584

539585
/**
540586
* Makes a call or transaction, which won't be added to the blockchain and
541587
* returns the used gas, which can be used for estimating the used gas
542-
* @param {string} to Address to get code from
543-
* @param {string} value Storage position
544-
* @param {string} gasPrice Gas price in wei
545-
* @param {string} gas
546-
* @returns {Promise<void>}
588+
* @param {string} toAddress Address to get code from
589+
* @param {object} options
590+
* @param {string} options.value Storage position
591+
* @param {string} options.gasPrice Gas price in wei
592+
* @param {string} options.gas
593+
* @return {Promise<void>}
547594
*/
548595
estimateGas(
549-
to: string,
550-
value: string | number,
551-
gasPrice: string,
552-
gas: string
596+
toAddress: string,
597+
options: {
598+
value: string | number
599+
gasPrice: string
600+
gas: string
601+
}
553602
): Promise<void>
554603

555604
/**
@@ -562,12 +611,17 @@ declare class EtherscanApi {
562611
/**
563612
* Returns ERC20-Token account balance by token's contract address
564613
* @param {string} contractAddress
614+
* @param {string} address
615+
* @param {object} [options]
616+
* @param {object} [options.tag=latest]
565617
* @returns {Promise<string>}
566618
*/
567619
getTokenBalanceByContractAddress(
568620
contractAddress: string,
569-
address: string,
570-
tag?: string
621+
options?: {
622+
address: string
623+
tag?: string
624+
}
571625
): Promise<string>
572626

573627
/**

0 commit comments

Comments
 (0)