Skip to content

Commit

Permalink
chore: added get_health and get_account functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dafuga committed Sep 23, 2023
1 parent a02e2ff commit 22e74a8
Show file tree
Hide file tree
Showing 7 changed files with 1,932 additions and 330 deletions.
215 changes: 2 additions & 213 deletions src/endpoints.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
import {
APIClient,
Asset,
Checksum256Type,
Int64Type,
NameType,
PublicKeyType,
TimePointType,
UInt64Type,
} from '@wharfkit/antelope'
import {
V1,
V2,
SortType,
} from './types'
import { HyperionV1APIClient } from './endpoints/v1';
import { HyperionV2APIClient } from './endpoints/v2';

export class HyperionAPIClient {
public v1: HyperionV1APIClient;
Expand All @@ -23,204 +13,3 @@ export class HyperionAPIClient {
this.v2 = new HyperionV2APIClient(client);
}
}

export class HyperionV1APIClient {
constructor(private client: APIClient) {}

async get_actions(options: {
account_name: NameType
pos?: UInt64Type;
offset?: UInt64Type;
filter?: UInt64Type;
sort?: SortType;
after?: TimePointType;
before?: TimePointType;
parent?: number;
}): Promise<any> {
return this.client.call({
path: `/v1/history/get_actions`,
method: 'POST',
// responseType: GetActionsResponse,
params: options
})
}
}

export class HyperionV2APIClient {
constructor(private client: APIClient) {}

async get_abi_snapshot(
contract: string,
block?: number,
fetch = false
): Promise<V2.GetABISnapshotResponse> {
if (!block) {
const info = await this.client.v1.chain.get_info()

block = Number(info.last_irreversible_block_num)
}

return this.client.call({
path: `/v2/history/get_abi_snapshot?contract=${encodeURIComponent(
contract
)}&block=${block}&fetch=${fetch}`,
method: 'GET',
responseType: V2.GetABISnapshotResponse,
})
}

async get_voters(
producer?: NameType,
proxy?: boolean,
skip?: number,
limit?: number
): Promise<V2.GetVotersResponse> {
let queryParams = ''
const queryParts: string[] = []

if (producer) queryParts.push(`producer=${producer}`)
if (proxy !== undefined) queryParts.push(`proxy=${proxy}`)
if (skip !== undefined) queryParts.push(`skip=${skip}`)
if (limit !== undefined) queryParts.push(`limit=${limit}`)

queryParams = queryParts.length ? '?' + queryParts.join('&') : ''

return this.client.call({
path: `/v2/state/get_voters${queryParams}`,
method: 'GET',
responseType: V2.GetVotersResponse,
})
}

async get_links(account?: NameType): Promise<V2.GetLinksResponse> {
const queryParams = account ? `?account=${account}` : ''

return this.client.call({
path: `/v2/state/get_links${queryParams}`,
method: 'GET',
responseType: V2.GetLinksResponse,
})
}

async get_proposals(options?: {
proposer?: NameType
proposal?: NameType
account?: NameType
requested?: string
provided?: string
track?: number | boolean
skip?: number
limit?: number
}): Promise<V2.GetProposalsResponse> {
const queryParts: string[] = []

for (const [key, value] of Object.entries(options || {})) {
queryParts.push(`${key}=${value}`)
}

const queryParams = queryParts.length ? '?' + queryParts.join('&') : ''

return this.client.call({
path: `/v2/state/get_proposals${queryParams}`,
method: 'GET',
responseType: V2.GetProposalsResponse,
})
}

async get_actions(
account: NameType,
options?: {
filter?: string
skip?: number
limit?: number
sort?: string
after?: string
before?: string
transfer_to?: NameType
transfer_from?: NameType
transfer_symbol?: Asset.Symbol
act_name?: string
act_account?: NameType
}
): Promise<V2.GetActionsResponse> {
const queryParts: string[] = [`account=${account}`]

for (const [key, value] of Object.entries(options || {})) {
queryParts.push(`${key}=${value}`)
}

const queryParams = queryParts.length ? '?' + queryParts.join('&') : ''

return this.client.call({
path: `/v2/history/get_actions${queryParams}`,
method: 'GET',
responseType: V2.GetActionsResponse,
})
}

async get_created_accounts(account: NameType): Promise<V2.GetCreatedAccountsResponse> {
return this.client.call({
path: `/v2/history/get_created_accounts?account=${account}`,
method: 'GET',
responseType: V2.GetCreatedAccountsResponse,
})
}

async get_creator(account: NameType): Promise<V2.GetCreatorResponse> {
return this.client.call({
path: `/v2/history/get_creator?account=${account}`,
method: 'GET',
responseType: V2.GetCreatorResponse,
})
}

async get_deltas(
code: NameType,
scope: NameType,
table: NameType,
payer: NameType
): Promise<V2.GetDeltasResponse> {
return this.client.call({
path: `/v2/history/get_deltas?code=${code}&scope=${scope}&table=${table}&payer=${payer}`,
method: 'GET',
responseType: V2.GetDeltasResponse,
})
}

async get_table_state(
code: NameType,
table: NameType,
block_num: Int64Type,
after_key = ''
): Promise<V2.GetTableStateResponse> {
return this.client.call({
path: `/v2/history/get_table_state?code=${code}&table=${table}&block_num=${block_num}&after_key=${after_key}`,
method: 'GET',
responseType: V2.GetTableStateResponse,
})
}

async get_key_accounts(public_key: PublicKeyType): Promise<V2.GetKeyAccountsResponse> {
return this.client.call({
path: `/v2/state/get_key_accounts?public_key=${public_key}`,
method: 'GET',
responseType: V2.GetKeyAccountsResponse,
})
}

async get_tokens(account: NameType): Promise<V2.GetTokensResponse> {
return this.client.call({
path: `/v2/state/get_tokens?account=${account}`,
method: 'GET',
responseType: V2.GetTokensResponse,
})
}

async get_transaction(id: Checksum256Type): Promise<V2.GetTransactionResponse> {
return this.client.call({
path: `/v2/history/get_transaction?id=${id}`,
method: 'GET',
responseType: V2.GetTransactionResponse,
})
}
}
32 changes: 32 additions & 0 deletions src/endpoints/v1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { APIClient, NameType, TimePointType, UInt64Type } from "@wharfkit/antelope";
import { SortType } from "../types";

export class HyperionV1APIClient {
public history: HyperionV1HistoryAPIClient;

constructor(private client: APIClient) {
this.history = new HyperionV1HistoryAPIClient(client);
}
}

class HyperionV1HistoryAPIClient {
constructor(private client: APIClient) {}

async get_actions(options: {
account_name: NameType
pos?: UInt64Type;
offset?: UInt64Type;
filter?: UInt64Type;
sort?: SortType;
after?: TimePointType;
before?: TimePointType;
parent?: number;
}): Promise<any> {
return this.client.call({
path: `/v1/history/get_actions`,
method: 'POST',
// responseType: GetActionsResponse,
params: options
})
}
}
Loading

0 comments on commit 22e74a8

Please sign in to comment.