|
| 1 | +import * as request from 'request-promise-native' |
| 2 | +import { Address } from '../entities/Address' |
| 3 | +import { ApiKey } from '../entities/Apikey' |
| 4 | +import { IClientAccountTxlistInternalTxhash } from '../interfaces/Account' |
| 5 | +import { requestBuilder } from '../requestBuilder' |
| 6 | +import { ClientBase } from './ClientBase' |
| 7 | + |
| 8 | +/** |
| 9 | + * Client for the account balance |
| 10 | + */ |
| 11 | +export class ClientAccountTxlistinternalTxhash extends ClientBase implements IClientAccountTxlistInternalTxhash { |
| 12 | + /** |
| 13 | + * Api key to send with the request |
| 14 | + */ |
| 15 | + apiKey: ApiKey |
| 16 | + /** |
| 17 | + * Hash of the transaction |
| 18 | + */ |
| 19 | + txhash: string |
| 20 | + /** |
| 21 | + * module of the etherscan api to request |
| 22 | + */ |
| 23 | + module: string |
| 24 | + /** |
| 25 | + * action of the etherscan api to request |
| 26 | + */ |
| 27 | + action: string |
| 28 | + /** |
| 29 | + * Block to start reading data |
| 30 | + */ |
| 31 | + startblock: string |
| 32 | + /** |
| 33 | + * Read data to |
| 34 | + */ |
| 35 | + endblock: string |
| 36 | + /** |
| 37 | + * Sort |
| 38 | + */ |
| 39 | + sort?: string |
| 40 | + /** |
| 41 | + * Page |
| 42 | + */ |
| 43 | + page?: string |
| 44 | + /** |
| 45 | + * startpage |
| 46 | + */ |
| 47 | + offset?: string |
| 48 | + |
| 49 | + constructor( |
| 50 | + apiKey: ApiKey, |
| 51 | + module: string, |
| 52 | + action: string, |
| 53 | + txhash: string, |
| 54 | + startblock: string, |
| 55 | + endblock: string, |
| 56 | + sort?: string, |
| 57 | + page?: string, |
| 58 | + offset?: string) { |
| 59 | + super() |
| 60 | + this.apiKey = apiKey |
| 61 | + this.module = module |
| 62 | + this.action = action |
| 63 | + this.txhash = txhash |
| 64 | + this.startblock = startblock |
| 65 | + this.endblock = endblock |
| 66 | + this.sort = sort |
| 67 | + this.page = page |
| 68 | + this.offset = offset |
| 69 | + } |
| 70 | + /** |
| 71 | + * Returns the serice url |
| 72 | + * @returns url |
| 73 | + */ |
| 74 | + toUrl(): string { |
| 75 | + |
| 76 | + let params = { |
| 77 | + apiKey: this.apiKey.toString(), |
| 78 | + endblock: this.endblock.toString(), |
| 79 | + startblock: this.startblock.toString(), |
| 80 | + txhash: this.txhash.toString(), |
| 81 | + } |
| 82 | + |
| 83 | + if (this.sort) { |
| 84 | + params = Object.assign(params, { |
| 85 | + sort: this.sort, |
| 86 | + }) |
| 87 | + } |
| 88 | + |
| 89 | + if (this.page) { |
| 90 | + params = Object.assign(params, { |
| 91 | + page: this.page, |
| 92 | + }) |
| 93 | + } |
| 94 | + |
| 95 | + if (this.offset) { |
| 96 | + params = Object.assign(params, { |
| 97 | + offset: this.offset, |
| 98 | + }) |
| 99 | + } |
| 100 | + return requestBuilder(this.module, this.action, params) |
| 101 | + } |
| 102 | + /** |
| 103 | + * Dies the actual request to the server |
| 104 | + */ |
| 105 | + async request(): Promise<any> { |
| 106 | + const options = { |
| 107 | + uri: this.toUrl(), |
| 108 | + } |
| 109 | + const res = await request.get(options) |
| 110 | + return this.processResult(res) |
| 111 | + } |
| 112 | +} |
0 commit comments