Skip to content

Commit

Permalink
Additional tests + missing get_action fields (#3)
Browse files Browse the repository at this point in the history
* Adding more type checks

* Adding limit and skip to get_created_accounts

* Added missing fields to get_actions
  • Loading branch information
aaroncox authored Feb 23, 2024
1 parent 5a11b11 commit 1cd63c3
Show file tree
Hide file tree
Showing 7 changed files with 272 additions and 115 deletions.
74 changes: 44 additions & 30 deletions src/endpoints/v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
NameType,
PublicKeyType,
} from '@wharfkit/antelope'
import {V2} from '../types'
import {Types} from '$lib'

export class HyperionV2APIClient {
public state: HyperionV2StateAPIClient
Expand All @@ -17,11 +17,11 @@ export class HyperionV2APIClient {
this.history = new HyperionV2HistoryAPIClient(client)
}

get_health(): Promise<V2.GetHealthResponse> {
get_health(): Promise<Types.V2.GetHealthResponse> {
return this.client.call({
path: `/v2/health`,
method: 'GET',
responseType: V2.GetHealthResponse,
responseType: Types.V2.GetHealthResponse,
})
}
}
Expand All @@ -34,7 +34,7 @@ class HyperionV2StateAPIClient {
proxy?: boolean,
skip?: number,
limit?: number
): Promise<V2.GetVotersResponse> {
): Promise<Types.V2.GetVotersResponse> {
let queryParams = ''
const queryParts: string[] = []

Expand All @@ -48,33 +48,33 @@ class HyperionV2StateAPIClient {
return this.client.call({
path: `/v2/state/get_voters${queryParams}`,
method: 'GET',
responseType: V2.GetVotersResponse,
responseType: Types.V2.GetVotersResponse,
})
}

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

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

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

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

Expand All @@ -87,7 +87,7 @@ class HyperionV2StateAPIClient {
track?: number | boolean
skip?: number
limit?: number
}): Promise<V2.GetProposalsResponse> {
}): Promise<Types.V2.GetProposalsResponse> {
const queryParts: string[] = []

for (const [key, value] of Object.entries(options || {})) {
Expand All @@ -99,15 +99,15 @@ class HyperionV2StateAPIClient {
return this.client.call({
path: `/v2/state/get_proposals${queryParams}`,
method: 'GET',
responseType: V2.GetProposalsResponse,
responseType: Types.V2.GetProposalsResponse,
})
}

async get_account(account: NameType): Promise<V2.GetAccountResponse> {
async get_account(account: NameType): Promise<Types.V2.GetAccountResponse> {
return this.client.call({
path: `/v2/state/get_account?account=${account}`,
method: 'GET',
responseType: V2.GetAccountResponse,
responseType: Types.V2.GetAccountResponse,
})
}
}
Expand All @@ -119,7 +119,7 @@ export class HyperionV2HistoryAPIClient {
contract: string,
block?: number,
fetch = false
): Promise<V2.GetABISnapshotResponse> {
): Promise<Types.V2.GetABISnapshotResponse> {
if (!block) {
const info = await this.client.v1.chain.get_info()

Expand All @@ -131,7 +131,7 @@ export class HyperionV2HistoryAPIClient {
contract
)}&block=${block}&fetch=${fetch}`,
method: 'GET',
responseType: V2.GetABISnapshotResponse,
responseType: Types.V2.GetABISnapshotResponse,
})
}

Expand All @@ -150,7 +150,7 @@ export class HyperionV2HistoryAPIClient {
act_name?: string
act_account?: NameType
}
): Promise<V2.GetActionsResponse> {
): Promise<Types.V2.GetActionsResponse> {
const queryParts: string[] = [`account=${account}`]

for (const [key, value] of Object.entries(options || {})) {
Expand All @@ -162,23 +162,37 @@ export class HyperionV2HistoryAPIClient {
return this.client.call({
path: `/v2/history/get_actions${queryParams}`,
method: 'GET',
responseType: V2.GetActionsResponse,
responseType: Types.V2.GetActionsResponse,
})
}

async get_created_accounts(account: NameType): Promise<V2.GetCreatedAccountsResponse> {
async get_created_accounts(
account: NameType,
options?: {
skip?: number
limit?: number
}
): Promise<Types.V2.GetCreatedAccountsResponse> {
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_created_accounts?account=${account}`,
path: `/v2/history/get_created_accounts${queryParams}`,
method: 'GET',
responseType: V2.GetCreatedAccountsResponse,
responseType: Types.V2.GetCreatedAccountsResponse,
})
}

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

Expand All @@ -187,11 +201,11 @@ export class HyperionV2HistoryAPIClient {
scope: NameType,
table: NameType,
payer: NameType
): Promise<V2.GetDeltasResponse> {
): Promise<Types.V2.GetDeltasResponse> {
return this.client.call({
path: `/v2/history/get_deltas?code=${code}&scope=${scope}&table=${table}&payer=${payer}`,
method: 'GET',
responseType: V2.GetDeltasResponse,
responseType: Types.V2.GetDeltasResponse,
})
}

Expand All @@ -200,19 +214,19 @@ export class HyperionV2HistoryAPIClient {
table: NameType,
block_num: Int64Type,
after_key = ''
): Promise<V2.GetTableStateResponse> {
): Promise<Types.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,
responseType: Types.V2.GetTableStateResponse,
})
}

async get_transaction(id: Checksum256Type): Promise<V2.GetTransactionResponse> {
async get_transaction(id: Checksum256Type): Promise<Types.V2.GetTransactionResponse> {
return this.client.call({
path: `/v2/history/get_transaction?id=${id}`,
method: 'GET',
responseType: V2.GetTransactionResponse,
responseType: Types.V2.GetTransactionResponse,
})
}

Expand Down
32 changes: 31 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
BlockTimestamp,
Checksum256,
Float64,
Int64,
Name,
PermissionLevel,
Struct,
Expand Down Expand Up @@ -98,12 +99,41 @@ export namespace V2 {
@Struct.field('any') declare data: any
}

@Struct.type('account_sequence')
export class AccountSequence extends Struct {
@Struct.field(Name) declare account: Name
@Struct.field(UInt64) declare sequence: UInt64
}

@Struct.type('action_receipt')
export class ActionReceipt extends Struct {
@Struct.field(Name) declare receiver: Name
@Struct.field(UInt64) declare global_sequence: UInt64
@Struct.field(UInt64) declare recv_sequence: UInt64
@Struct.field(AccountSequence, {array: true}) declare auth_sequence: AccountSequence[]
}

@Struct.type('action_ram_delta')
export class ActionRamDelta extends Struct {
@Struct.field(Name) declare account: Name
@Struct.field(Int64) declare delta: Int64
}

@Struct.type('action')
export class Action extends Struct {
@Struct.field(UInt32) declare block_num: UInt32
@Struct.field(BlockTimestamp) declare timestamp: BlockTimestamp
@Struct.field(UInt32) declare block_num: UInt32
@Struct.field(Checksum256, {optional: true}) declare block_id: Checksum256
@Struct.field(Checksum256) declare trx_id: Checksum256
@Struct.field(ActionAct) declare act: ActionAct
@Struct.field(ActionReceipt, {array: true, optional: true})
declare receipts: ActionReceipt[]
@Struct.field(ActionRamDelta, {array: true, optional: true})
declare account_ram_deltas: ActionRamDelta[]
@Struct.field(UInt64) declare global_sequence: UInt64
@Struct.field(Name) declare producer: Name
@Struct.field(UInt64) declare action_ordinal: UInt64
@Struct.field(UInt64) declare creator_action_ordinal: UInt64
}

@Struct.type('get_actions_response')
Expand Down
Loading

0 comments on commit 1cd63c3

Please sign in to comment.