Skip to content

Commit

Permalink
enhancement: throwing error when non-implemented method is called
Browse files Browse the repository at this point in the history
  • Loading branch information
dafuga committed Sep 25, 2023
1 parent 40ab9d6 commit 2a26bc3
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 45 deletions.
50 changes: 34 additions & 16 deletions src/endpoints/v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,48 @@ import { SortType } from "../types";

export class HyperionV1APIClient {
public history: HyperionV1HistoryAPIClient;
public chain: HyperionV1ChainAPIClient;
public trace_api: HyperionV1TraceApiClient;

constructor(private client: APIClient) {
this.history = new HyperionV1HistoryAPIClient(client);
this.chain = new HyperionV1ChainAPIClient(client);
this.trace_api = new HyperionV1TraceApiClient(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
})
async get_actions(): Promise<void> {
throw new Error("Method not implemented.");
}

async get_controlled_accounts(): Promise<void> {
throw new Error("Method not implemented.");
}

async get_key_accounts(): Promise<void> {
throw new Error("Method not implemented.");
}

async get_transaction(): Promise<void> {
throw new Error("Method not implemented.");
}
}

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

async get_block(): Promise<void> {
throw new Error("Method not implemented.");
}
}

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

async get_block(): Promise<void> {
throw new Error("Method not implemented.");
}
}
24 changes: 7 additions & 17 deletions src/endpoints/v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class HyperionV2APIClient {
return this.client.call({
path: `/v2/health`,
method: 'GET',
// responseType: V2.GetHealthResponse,
responseType: V2.GetHealthResponse,
})
}
}
Expand Down Expand Up @@ -209,21 +209,11 @@ export class HyperionV2HistoryAPIClient {
})
}

async get_transfers(params: {
from?: NameType;
to?: NameType;
symbol?: NameType;
contract?: NameType;
skip?: UInt64Type;
limit?: UInt64Type;
after?: TimePointType;
before?: TimePointType;
}): Promise<any> {
const queryParams = new URLSearchParams(params as any).toString();
return this.client.call({
path: `/v2/history/get_transfers?${queryParams}`,
method: 'GET',
// responseType: V2.GetTransfersResponse,
});
async get_transfers(): Promise<any> {
throw new Error("Method not implemented.");
}

async get_transacted_accounts(): Promise<any> {
throw new Error("Method not implemented.");
}
}
6 changes: 2 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ import {

export type SortType = 'desc' | 'asc' | '1' | '-1';

export namespace V1 {

}
export namespace V1 {}

export namespace V2 {
@Struct.type('get_abi_snapshot_response')
Expand Down Expand Up @@ -225,7 +223,7 @@ export namespace V2 {
export class HealthEntry extends Struct {
@Struct.field('string') declare service: string;
@Struct.field('string') declare status: string;
@Struct.field('map') declare service_data?: NodeosRPCServiceData | ElasticsearchServiceData;
@Struct.field('any', { optional: true }) declare service_data?: NodeosRPCServiceData | ElasticsearchServiceData;
@Struct.field(UInt64) declare time: UInt64;
}

Expand Down
8 changes: 0 additions & 8 deletions test/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,6 @@ suite('Hyperion API', function () {
assert.instanceOf(response.creator, Name);
assert.equal(String(response.creator), "gqyqi.waa");
})

test('get_transfers', async function () {
const response = await hyperion.v2.history.get_transfers({ from: 'teamgreymass' });

assert.isArray(response.transfers);
assert.equal(response.transfers.length, 10);
assert.instanceOf(response.transfers[0].from, Name);
})
})
})
})

0 comments on commit 2a26bc3

Please sign in to comment.