Skip to content

Commit

Permalink
adding hyperion's get_created_accounts, added hyperion base response …
Browse files Browse the repository at this point in the history
…type that response implement
  • Loading branch information
joshglogau committed Jan 6, 2025
1 parent 00e3010 commit a72818c
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@wireio/core",
"description": "Library for working with Wire powered blockchains.",
"version": "0.0.4-3",
"version": "0.0.4-4",
"homepage": "https://github.com/Wire-Network/sdk-core",
"license": "FSL-1.1-Apache-2.0",
"main": "lib/core.js",
Expand Down
19 changes: 18 additions & 1 deletion src/api/v2/history.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { APIClient } from "../client";
import { FetchProvider } from "../provider";
import { GetActionsParams, GetActionsResponse, GetTransactionResponse } from "./types";
import { GetActionsParams, GetActionsResponse, GetCreatedAccountsParams, GetCreatedAccountsResponse, GetTransactionResponse } from "./types";

export class HistoryAPIv2 {
get provider(): FetchProvider | undefined { return this.api.hyperionProvider }
Expand Down Expand Up @@ -39,4 +39,21 @@ export class HistoryAPIv2 {

return response.json as GetActionsResponse;
}

/**
* Fetch all accounts created by a specified account
* @param params - Query parameters for fetching created accounts
* @returns A promise that resolves to a GetCreatedAccountsResponse object containing an array of CreatedAccounts
*/
async get_created_accounts(params: GetCreatedAccountsParams): Promise<GetCreatedAccountsResponse> {
if (!this.provider) throw new Error('HyperionAPI requires a provider');

const response = await this.provider.call({
path: `/v2/history/get_created_accounts`,
params: params as any || {},
method: 'GET',
});

return response.json as GetCreatedAccountsResponse;
}
}
64 changes: 52 additions & 12 deletions src/api/v2/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { AnyAction, NameType, Signature, Struct } from '../../chain';
import { AnyAction, Checksum256Type, NameType, Signature, Struct } from '../../chain';


export interface HyperionBaseResponse {
query_time_ms: number;
last_indexed_block: number;
last_indexed_block_time: string;
}

@Struct.type('account_ram_delta')
export class AccountRamDelta extends Struct {
Expand Down Expand Up @@ -142,12 +149,13 @@ export class HealthFeatures extends Struct {
}

@Struct.type('health_response')
export class HealthResponse extends Struct {
export class HealthResponse extends Struct implements HyperionBaseResponse {
@Struct.field('string') declare version: string;
@Struct.field('string') declare version_hash: string;
@Struct.field('string') declare host: string;
@Struct.field(HealthService, { array: true }) declare health: HealthService[];
@Struct.field(HealthFeatures) declare features: HealthFeatures;
// HyperionBaseResponse
@Struct.field('number') declare query_time_ms: number;
@Struct.field('number') declare last_indexed_block: number;
@Struct.field('string') declare last_indexed_block_time: string;
Expand All @@ -164,12 +172,13 @@ export class ApiUsageBucket extends Struct {
}

@Struct.type('api_usage_response')
export class ApiUsageResponse extends Struct {
export class ApiUsageResponse extends Struct implements HyperionBaseResponse {
@Struct.field(ApiUsageTotal) declare total: ApiUsageTotal;
@Struct.field(ApiUsageBucket, { array: true }) declare buckets: ApiUsageBucket[];
// HyperionBaseResponse
@Struct.field('number') declare query_time_ms: number;
@Struct.field('number') declare last_indexed_block: number;
@Struct.field('string') declare last_indexed_block_time: string;
@Struct.field(ApiUsageTotal) declare total: ApiUsageTotal;
@Struct.field(ApiUsageBucket, { array: true }) declare buckets: ApiUsageBucket[];
}

@Struct.type('missed_blocks_stats')
Expand All @@ -178,12 +187,13 @@ export class MissedBlocksStats extends Struct {
}

@Struct.type('missed_blocks_response')
export class MissedBlocksResponse extends Struct {
export class MissedBlocksResponse extends Struct implements HyperionBaseResponse {
@Struct.field(MissedBlocksStats) declare stats: MissedBlocksStats;
@Struct.field('any', { array: true }) declare events: any[];
// HyperionBaseResponse
@Struct.field('number') declare query_time_ms: number;
@Struct.field('number') declare last_indexed_block: number;
@Struct.field('string') declare last_indexed_block_time: string;
@Struct.field(MissedBlocksStats) declare stats: MissedBlocksStats;
@Struct.field('any', { array: true }) declare events: any[];
}

@Struct.type('resource_usage_stats')
Expand Down Expand Up @@ -226,10 +236,11 @@ export class ResourceUsage extends Struct {
}

@Struct.type('get_resource_usage_response')
export class GetResourceUsageResponse extends Struct {
export class GetResourceUsageResponse extends Struct implements HyperionBaseResponse {
@Struct.field(ResourceUsage) declare cpu: ResourceUsage;
@Struct.field(ResourceUsage) declare net: ResourceUsage;
@Struct.field('boolean') declare cached: boolean;
// HyperionBaseResponse
@Struct.field('number') declare query_time_ms: number;
@Struct.field('number') declare last_indexed_block: number;
@Struct.field('string') declare last_indexed_block_time: string;
Expand Down Expand Up @@ -394,7 +405,7 @@ export class Action extends Struct {
}

@Struct.type('get_account_response')
export class GetAccountResponse extends Struct {
export class GetAccountResponse extends Struct implements HyperionBaseResponse {
@Struct.field('number') declare query_time_ms: number;
@Struct.field('number') declare last_indexed_block: number;
@Struct.field('string') declare last_indexed_block_time: string;
Expand All @@ -404,7 +415,6 @@ export class GetAccountResponse extends Struct {
@Struct.field('number') declare total_actions: number;
@Struct.field(Action, { array: true }) declare actions: Action[];
}

export interface MissedBlocksParams {
producer?: NameType;
after?: string;
Expand All @@ -415,4 +425,34 @@ export interface MissedBlocksParams {
export interface GetResourceUsageParams {
code: NameType;
action: NameType;
}
}

export interface GetCreatedAccountsParams {
/**
* creator account
*/
account: NameType;
/**
* Number of results to skip.
*/
skip?: number;
/**
* Limit the number of results per page.
*/
limit?: number;
}
export interface CreatedAccount {
name: string;
timestamp: string;
trx_id: string;
}

@Struct.type('get_account_response')
export class GetCreatedAccountsResponse extends Struct implements HyperionBaseResponse {
@Struct.field('CreatedAccount[]') declare accounts: CreatedAccount[];
// HyperionBaseResponse
@Struct.field('number') declare query_time_ms: number;
@Struct.field('number') declare last_indexed_block: number;
@Struct.field('string') declare last_indexed_block_time: string;
}

0 comments on commit a72818c

Please sign in to comment.