import * as url from 'url'; export interface $FetchOptions { body?: string; headers?: $HttpHeaders; method?: $HttpMethod; } export type $FetchFunction = (url: string, options?: $FetchOptions) => Promise; export interface $HttpHeaders { [key: string]: string; } export type $HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'CONNECT' | 'OPTIONS' | 'TRACE'; export interface $HttpQuery { [key: string]: string | number | boolean | string[] | number[] | boolean[] | undefined | null; } export interface $HttpRequest { body?: any; url: string; headers: $HttpHeaders; method: $HttpMethod; } export interface $HttpRequestOptions { body?: any; endpoint: string; headers?: $HttpHeaders; method: $HttpMethod; query?: $HttpQuery; } export interface $HttpResponse { body: B; headers: $HttpHeaders; ok: O; request: $HttpRequest; status: S; statusText: string; } export type $HttpContinue = $HttpResponse; export type $HttpSwitchingProtocol = $HttpResponse; export type $HttpProcessing = $HttpResponse; export type $HttpOk = $HttpResponse; export type $HttpCreated = $HttpResponse; export type $HttpAccepted = $HttpResponse; export type $HttpNonAuthoritativeInformation = $HttpResponse; export type $HttpNoContent = $HttpResponse; export type $HttpResetContent = $HttpResponse; export type $HttpPartialContent = $HttpResponse; export type $HttpMultiStatus = $HttpResponse; export type $HttpAlreadyReported = $HttpResponse; export type $HttpImUsed = $HttpResponse; export type $HttpMultipleChoices = $HttpResponse; export type $HttpMovedPermanently = $HttpResponse; export type $HttpFound = $HttpResponse; export type $HttpSeeOther = $HttpResponse; export type $HttpNotModified = $HttpResponse; export type $HttpUseProxy = $HttpResponse; export type $HttpTemporaryRedirect = $HttpResponse; export type $HttpPermanentRedirect = $HttpResponse; export type $HttpBadRequest = $HttpResponse; export type $HttpUnauthorized = $HttpResponse; export type $HttpPaymentRequired = $HttpResponse; export type $HttpForbidden = $HttpResponse; export type $HttpNotFound = $HttpResponse; export type $HttpMethodNotAllowed = $HttpResponse; export type $HttpNotAcceptable = $HttpResponse; export type $HttpProxyAuthenticationRequired = $HttpResponse; export type $HttpRequestTimeout = $HttpResponse; export type $HttpConflict = $HttpResponse; export type $HttpGone = $HttpResponse; export type $HttpLengthRequired = $HttpResponse; export type $HttpPreconditionFailed = $HttpResponse; export type $HttpRequestEntityTooLarge = $HttpResponse; export type $HttpRequestUriTooLong = $HttpResponse; export type $HttpUnsupportedMediaType = $HttpResponse; export type $HttpRequestedRangeNotSatisfiable = $HttpResponse; export type $HttpExpectationFailed = $HttpResponse; export type $HttpMisdirectedRequest = $HttpResponse; export type $HttpUnprocessableEntity = $HttpResponse; export type $HttpLocked = $HttpResponse; export type $HttpFailedDependency = $HttpResponse; export type $HttpUpgradeRequired = $HttpResponse; export type $HttpPreconditionRequired = $HttpResponse; export type $HttpTooManyRequests = $HttpResponse; export type $HttpRequestHeaderFieldsTooLarge = $HttpResponse; export type $HttpNoResponse = $HttpResponse; export type $HttpRetryWith = $HttpResponse; export type $HttpBlockedByWindowsParentalControls = $HttpResponse; export type $HttpUnavailableForLegalReasons = $HttpResponse; export type $HttpClientClosedRequest = $HttpResponse; export type $HttpInternalServerError = $HttpResponse; export type $HttpNotImplemented = $HttpResponse; export type $HttpBadGateway = $HttpResponse; export type $HttpServiceUnavailable = $HttpResponse; export type $HttpGatewayTimeout = $HttpResponse; export type $HttpHttpVersionNotSupported = $HttpResponse; export type $HttpInsufficientStorage = $HttpResponse; export type $HttpLoopDetected = $HttpResponse; export type $HttpBandwidthLimitExceeded = $HttpResponse; export type $HttpNotExtended = $HttpResponse; export type $HttpNetworkAuthenticationRequired = $HttpResponse; export type $HttpNetworkReadTimeoutError = $HttpResponse; export type $HttpNetworkConnectTimeoutError = $HttpResponse; export interface $HttpClientOptions { fetch: $FetchFunction; } export function isResponseEmpty(response: Response): boolean { const contentLength = response.headers.get('Content-Length'); return response.status === 204 || contentLength != null && Number.parseInt(contentLength, 10) === 0; } export function isResponseJson(response: Response): boolean { const contentType = response.headers.get('Content-Type'); return contentType != null && contentType.indexOf('json') >= 0; } export function parseJson(response: Response): Promise { return !isResponseEmpty(response) && isResponseJson(response) ? response.json() : Promise.resolve(); } export function parseHeaders(response: Response): Record { const headers: Record = {}; response.headers.forEach((value, key) => { headers[key.toLowerCase()] = value; }); return headers; } export function stripQuery(query: $HttpQuery = {}): $HttpQuery { const initialValue: $HttpQuery = {}; return Object.keys(query).reduce((previousValue, key) => { const value = query[key]; if (value != null) previousValue[key] = value; return previousValue; }, initialValue); } export class $HttpClient { private options: $HttpClientOptions; constructor(options: $HttpClientOptions) { this.options = options; } public request(options: $HttpRequestOptions): Promise<$HttpResponse> { const finalUrl: string = url.format({ hostname: 'hilltop-api.mainnet.dandelion.link', pathname: options.endpoint, protocol: 'https:', query: stripQuery(options.query), }); const finalHeaders: $HttpHeaders = { accept: 'application/json', 'content-type': 'application/json', ...options.headers, }; const request: $HttpRequest = { body: options.body, headers: finalHeaders, method: options.method, url: finalUrl, }; return this.options.fetch(request.url, { body: JSON.stringify(request.body), headers: request.headers, method: request.method, }).then((response) => { return parseJson(response).then((json) => { return { body: json, headers: parseHeaders(response), ok: response.ok, request, status: response.status, statusText: response.statusText, }; }); }); } } export class $Resource { protected client: $HttpClient; constructor(options: $HttpClientOptions) { this.client = new $HttpClient(options); } } export interface ActiveStakeAmountsGetParameters { headers?: $HttpHeaders; epoch_number?: number; } export interface ActiveStakeAmountsGetByPoolBech32IdParameters { headers?: $HttpHeaders; pool_bech32_id: string; epoch_number?: number; } export interface ActiveStakeAmountsGetAddressesByPoolBech32IdParameters { headers?: $HttpHeaders; pool_bech32_id: string; epoch_number: number; } export interface BlocksGetBlocksInDayParameters { headers?: $HttpHeaders; date: string; } export interface BlocksGetByBlockNumberParameters { headers?: $HttpHeaders; /*the block number*/ block_number: number; } export interface DelegationsGetSafePaymentByStakingAddressParameters { headers?: $HttpHeaders; staking_address: string; } export interface DelegationsGetStakepoolByStakingAddressParameters { headers?: $HttpHeaders; staking_address: string; } export interface DelegatorsCountsGetByPoolBech32IdParameters { headers?: $HttpHeaders; pool_bech32_id: string; } export interface EpochsGetCurrentParameters { headers?: $HttpHeaders; } export interface EpochsGetByEpochNumberParameters { headers?: $HttpHeaders; epoch_number: number; } export interface HealthchecksGetParameters { headers?: $HttpHeaders; } export interface NativeAssetsGetIdsParameters { headers?: $HttpHeaders; /*the block number from when fetching updates, it's the pagination index*/ block_number_from?: number; /*the number of updates to fetch*/ limit?: number; } export interface NativeAssetsGetAssetNamesByPolicyIdParameters { headers?: $HttpHeaders; /*the policy id to get the asset name*/ policy_id: string; } export interface NativeAssetsGetNftsParameters { headers?: $HttpHeaders; block_number_from: number; block_number_to: number; } export interface NativeAssetsPostNativeAssetsDetailsParameters { body: io.gimbalabs.hilltop.api.v0.models.NativeAssetDetailsRequest; headers?: $HttpHeaders; } export interface NativeAssetsGetByStakeAddressParameters { headers?: $HttpHeaders; stake_address: string; } export interface PoolUpdatesGetRetiringParameters { headers?: $HttpHeaders; /*the block number from when fetching updates, it's the pagination index*/ block_number_from?: number; /*the number of updates to fetch*/ limit?: number; } export interface PoolUpdatesGetByPoolIdParameters { headers?: $HttpHeaders; pool_id: string; /*the block number from when fetching updates, it's the pagination index*/ block_number_from?: number; /*the number of updates to fetch*/ limit?: number; } export interface PoolUpdatesGetParameters { headers?: $HttpHeaders; /*the block number from when fetching updates, it's the pagination index*/ block_number_from?: number; /*the number of updates to fetch*/ limit?: number; } export interface RewardsGetByStakingAddressParameters { headers?: $HttpHeaders; staking_address: string; epoch_from?: number; epoch_to?: number; } export interface SigmasGetByPoolIdParameters { headers?: $HttpHeaders; pool_id: string; epoch_number: number; } export interface StakepoolsGetVrfVkeyByVrfVkeyHashParameters { headers?: $HttpHeaders; /*the hash of the vrf_vkey*/ vrf_vkey_hash: string; } export interface StakepoolsGetEstablishedEpochByPoolIdParameters { headers?: $HttpHeaders; /*id of the pool to query. Both id and bech32 formats are supported*/ pool_id: string; } export interface StakepoolsGetLiveStakeByPoolIdParameters { headers?: $HttpHeaders; /*id of the pool to query. Both id and bech32 formats are supported*/ pool_id: string; } export interface StakepoolsGetBlocksByPoolIdParameters { headers?: $HttpHeaders; /*id of the pool to query. Both id and bech32 formats are supported*/ pool_id: string; /*epoch in which to query number of produced blocks or current epoch if not specified*/ epoch?: number; } export interface StakepoolsGetParameters { headers?: $HttpHeaders; } export interface StakepoolMetadataGetByPoolIdBech32Parameters { headers?: $HttpHeaders; pool_id_bech32: string; } export interface TransactionsPostHistoryParameters { body: io.gimbalabs.hilltop.api.v0.models.TransactionHistoryRequest; headers?: $HttpHeaders; } export interface WalletBalancesGetByStakingAddressParameters { headers?: $HttpHeaders; staking_address: string; } export type ActiveStakeAmountsGetResponse = $HttpOk; export type ActiveStakeAmountsGetByPoolBech32IdResponse = $HttpOk; export type ActiveStakeAmountsGetAddressesByPoolBech32IdResponse = $HttpOk; export type BlocksGetBlocksInDayResponse = $HttpOk | $HttpNotFound; export type BlocksGetByBlockNumberResponse = $HttpOk | $HttpNotFound; export type DelegationsGetSafePaymentByStakingAddressResponse = $HttpOk | $HttpNotFound; export type DelegationsGetStakepoolByStakingAddressResponse = $HttpOk | $HttpNotFound; export type DelegatorsCountsGetByPoolBech32IdResponse = $HttpOk; export type EpochsGetCurrentResponse = $HttpOk; export type EpochsGetByEpochNumberResponse = $HttpOk; export type HealthchecksGetResponse = $HttpOk; export type NativeAssetsGetIdsResponse = $HttpOk; export type NativeAssetsGetAssetNamesByPolicyIdResponse = $HttpOk; export type NativeAssetsGetNftsResponse = $HttpOk | $HttpNotFound; export type NativeAssetsPostNativeAssetsDetailsResponse = $HttpOk; export type NativeAssetsGetByStakeAddressResponse = $HttpOk; export type PoolUpdatesGetRetiringResponse = $HttpOk | $HttpNotFound; export type PoolUpdatesGetByPoolIdResponse = $HttpOk | $HttpNotFound; export type PoolUpdatesGetResponse = $HttpOk | $HttpNotFound; export type RewardsGetByStakingAddressResponse = $HttpOk; export type SigmasGetByPoolIdResponse = $HttpOk; export type StakepoolsGetVrfVkeyByVrfVkeyHashResponse = $HttpOk | $HttpNotFound; export type StakepoolsGetEstablishedEpochByPoolIdResponse = $HttpOk | $HttpNotFound; export type StakepoolsGetLiveStakeByPoolIdResponse = $HttpOk | $HttpNotFound; export type StakepoolsGetBlocksByPoolIdResponse = $HttpOk | $HttpNotFound; export type StakepoolsGetResponse = $HttpOk; export type StakepoolMetadataGetByPoolIdBech32Response = $HttpOk | $HttpNotFound; export type TransactionsPostHistoryResponse = $HttpOk; export type WalletBalancesGetByStakingAddressResponse = $HttpOk; export class ActiveStakeAmountsResource extends $Resource { public get(params: ActiveStakeAmountsGetParameters = {}): Promise { return this.client.request({ endpoint: '/active_stake_amounts', headers: params.headers, method: 'GET', query: { epoch_number: params.epoch_number, }, }); } public getByPoolBech32Id(params: ActiveStakeAmountsGetByPoolBech32IdParameters): Promise { return this.client.request({ endpoint: `/active_stake_amounts/${encodeURIComponent(params.pool_bech32_id)}`, headers: params.headers, method: 'GET', query: { epoch_number: params.epoch_number, }, }); } public getAddressesByPoolBech32Id(params: ActiveStakeAmountsGetAddressesByPoolBech32IdParameters): Promise { return this.client.request({ endpoint: `/active_stake_amounts/${encodeURIComponent(params.pool_bech32_id)}/addresses`, headers: params.headers, method: 'GET', query: { epoch_number: params.epoch_number, }, }); } } export class BlocksResource extends $Resource { public getBlocksInDay(params: BlocksGetBlocksInDayParameters): Promise { return this.client.request({ endpoint: '/blocks/blocks_in_day', headers: params.headers, method: 'GET', query: { date: params.date, }, }); } public getByBlockNumber(params: BlocksGetByBlockNumberParameters): Promise { return this.client.request({ endpoint: `/blocks/${encodeURIComponent(params.block_number)}`, headers: params.headers, method: 'GET', }); } } export class DelegationsResource extends $Resource { public getSafePaymentByStakingAddress(params: DelegationsGetSafePaymentByStakingAddressParameters): Promise { return this.client.request({ endpoint: `/delegations/${encodeURIComponent(params.staking_address)}/safe_payment`, headers: params.headers, method: 'GET', }); } public getStakepoolByStakingAddress(params: DelegationsGetStakepoolByStakingAddressParameters): Promise { return this.client.request({ endpoint: `/delegations/${encodeURIComponent(params.staking_address)}/stakepool`, headers: params.headers, method: 'GET', }); } } export class DelegatorsCountsResource extends $Resource { public getByPoolBech32Id(params: DelegatorsCountsGetByPoolBech32IdParameters): Promise { return this.client.request({ endpoint: `/delegators_counts/${encodeURIComponent(params.pool_bech32_id)}`, headers: params.headers, method: 'GET', }); } } export class EpochsResource extends $Resource { public getCurrent(params: EpochsGetCurrentParameters = {}): Promise { return this.client.request({ endpoint: '/epochs/current', headers: params.headers, method: 'GET', }); } public getByEpochNumber(params: EpochsGetByEpochNumberParameters): Promise { return this.client.request({ endpoint: `/epochs/${encodeURIComponent(params.epoch_number)}`, headers: params.headers, method: 'GET', }); } } export class HealthchecksResource extends $Resource { public get(params: HealthchecksGetParameters = {}): Promise { return this.client.request({ endpoint: '/healthchecks', headers: params.headers, method: 'GET', }); } } export class NativeAssetsResource extends $Resource { public getIds(params: NativeAssetsGetIdsParameters = {}): Promise { return this.client.request({ endpoint: '/native_assets/ids', headers: params.headers, method: 'GET', query: { block_number_from: params.block_number_from, limit: params.limit, }, }); } public getAssetNamesByPolicyId(params: NativeAssetsGetAssetNamesByPolicyIdParameters): Promise { return this.client.request({ endpoint: `/native_assets/${encodeURIComponent(params.policy_id)}/asset_names`, headers: params.headers, method: 'GET', }); } public getNfts(params: NativeAssetsGetNftsParameters): Promise { return this.client.request({ endpoint: '/native_assets/nfts', headers: params.headers, method: 'GET', query: { block_number_from: params.block_number_from, block_number_to: params.block_number_to, }, }); } public postNativeAssetsDetails(params: NativeAssetsPostNativeAssetsDetailsParameters): Promise { return this.client.request({ body: params.body, endpoint: '/native_assets/native_assets_details', headers: params.headers, method: 'POST', }); } public getByStakeAddress(params: NativeAssetsGetByStakeAddressParameters): Promise { return this.client.request({ endpoint: `/native_assets/${encodeURIComponent(params.stake_address)}`, headers: params.headers, method: 'GET', }); } } export class PoolUpdatesResource extends $Resource { public getRetiring(params: PoolUpdatesGetRetiringParameters = {}): Promise { return this.client.request({ endpoint: '/pool_updates/retiring', headers: params.headers, method: 'GET', query: { block_number_from: params.block_number_from, limit: params.limit, }, }); } public getByPoolId(params: PoolUpdatesGetByPoolIdParameters): Promise { return this.client.request({ endpoint: `/pool_updates/${encodeURIComponent(params.pool_id)}`, headers: params.headers, method: 'GET', query: { block_number_from: params.block_number_from, limit: params.limit, }, }); } public get(params: PoolUpdatesGetParameters = {}): Promise { return this.client.request({ endpoint: '/pool_updates', headers: params.headers, method: 'GET', query: { block_number_from: params.block_number_from, limit: params.limit, }, }); } } export class RewardsResource extends $Resource { public getByStakingAddress(params: RewardsGetByStakingAddressParameters): Promise { return this.client.request({ endpoint: `/rewards/${encodeURIComponent(params.staking_address)}`, headers: params.headers, method: 'GET', query: { epoch_from: params.epoch_from, epoch_to: params.epoch_to, }, }); } } export class SigmasResource extends $Resource { /*can be either the pool_id (e.g. pool1wcwe923r...) or the pool_hash*/ public getByPoolId(params: SigmasGetByPoolIdParameters): Promise { return this.client.request({ endpoint: `/sigmas/${encodeURIComponent(params.pool_id)}`, headers: params.headers, method: 'GET', query: { epoch_number: params.epoch_number, }, }); } } export class StakepoolsResource extends $Resource { /*find pool details by vrf_vkey*/ public getVrfVkeyByVrfVkeyHash(params: StakepoolsGetVrfVkeyByVrfVkeyHashParameters): Promise { return this.client.request({ endpoint: `/stakepools/vrf_vkey/${encodeURIComponent(params.vrf_vkey_hash)}`, headers: params.headers, method: 'GET', }); } /*Epoch at which stake pool was originally registered*/ public getEstablishedEpochByPoolId(params: StakepoolsGetEstablishedEpochByPoolIdParameters): Promise { return this.client.request({ endpoint: `/stakepools/${encodeURIComponent(params.pool_id)}/established_epoch`, headers: params.headers, method: 'GET', }); } /*live stake in lovelaces*/ public getLiveStakeByPoolId(params: StakepoolsGetLiveStakeByPoolIdParameters): Promise { return this.client.request({ endpoint: `/stakepools/${encodeURIComponent(params.pool_id)}/live_stake`, headers: params.headers, method: 'GET', }); } /*number minted blocks in epoch*/ public getBlocksByPoolId(params: StakepoolsGetBlocksByPoolIdParameters): Promise { return this.client.request({ endpoint: `/stakepools/${encodeURIComponent(params.pool_id)}/blocks`, headers: params.headers, method: 'GET', query: { epoch: params.epoch, }, }); } public get(params: StakepoolsGetParameters = {}): Promise { return this.client.request({ endpoint: '/stakepools', headers: params.headers, method: 'GET', }); } } export class StakepoolMetadataResource extends $Resource { public getByPoolIdBech32(params: StakepoolMetadataGetByPoolIdBech32Parameters): Promise { return this.client.request({ endpoint: `/stakepool_metadata/${encodeURIComponent(params.pool_id_bech32)}`, headers: params.headers, method: 'GET', }); } } export class TransactionsResource extends $Resource { public postHistory(params: TransactionsPostHistoryParameters): Promise { return this.client.request({ body: params.body, endpoint: '/transactions/history', headers: params.headers, method: 'POST', }); } } export class WalletBalancesResource extends $Resource { public getByStakingAddress(params: WalletBalancesGetByStakingAddressParameters): Promise { return this.client.request({ endpoint: `/wallet_balances/${encodeURIComponent(params.staking_address)}`, headers: params.headers, method: 'GET', }); } } export interface ClientInstance { activeStakeAmounts: ActiveStakeAmountsResource; blocks: BlocksResource; delegations: DelegationsResource; delegatorsCounts: DelegatorsCountsResource; epochs: EpochsResource; healthchecks: HealthchecksResource; nativeAssets: NativeAssetsResource; poolUpdates: PoolUpdatesResource; rewards: RewardsResource; sigmas: SigmasResource; stakepools: StakepoolsResource; stakepoolMetadata: StakepoolMetadataResource; transactions: TransactionsResource; walletBalances: WalletBalancesResource; } export function createClient(options: $HttpClientOptions): ClientInstance { return { activeStakeAmounts: new ActiveStakeAmountsResource(options), blocks: new BlocksResource(options), delegations: new DelegationsResource(options), delegatorsCounts: new DelegatorsCountsResource(options), epochs: new EpochsResource(options), healthchecks: new HealthchecksResource(options), nativeAssets: new NativeAssetsResource(options), poolUpdates: new PoolUpdatesResource(options), rewards: new RewardsResource(options), sigmas: new SigmasResource(options), stakepools: new StakepoolsResource(options), stakepoolMetadata: new StakepoolMetadataResource(options), transactions: new TransactionsResource(options), walletBalances: new WalletBalancesResource(options), }; }