Skip to content

Commit

Permalink
chore: added get_deltas, get_table_state and get_key_accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
dafuga committed Sep 21, 2023
1 parent a7c4bb5 commit cdd1c7e
Show file tree
Hide file tree
Showing 6 changed files with 312 additions and 12 deletions.
42 changes: 33 additions & 9 deletions src/endpoints.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {APIClient, NameType} from '@wharfkit/antelope'
import {GetABISnapshotResponse, GetActionsResponse, GetCreatedAccountsResponse, GetCreatorResponse, GetLinksResponse, GetProposalsResponse, GetVotersResponse} from './types'
import {APIClient, Asset, Int64Type, NameType, UInt64Type} from '@wharfkit/antelope'
import {GetABISnapshotResponse, GetActionsResponse, GetCreatedAccountsResponse, GetCreatorResponse, GetDeltasResponse, GetKeyAccountsResponse, GetLinksResponse, GetProposalsResponse, GetTableStateResponse, GetVotersResponse} from './types'

export class HyperionAPIClient {
constructor(private client: APIClient) {}
Expand Down Expand Up @@ -78,18 +78,18 @@ export class HyperionAPIClient {
});
}

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

Expand All @@ -106,19 +106,43 @@ export class HyperionAPIClient {
});
}

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

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

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

async get_table_state(code: NameType, table: NameType, block_num: Int64Type, after_key = ''): Promise<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: GetTableStateResponse,
});
}

async get_key_accounts(public_key: string): Promise<GetKeyAccountsResponse> {
return this.client.call({
path: `/v2/state/get_key_accounts?public_key=${public_key}`,
method: 'GET',
responseType: GetKeyAccountsResponse,
});
}
}
39 changes: 38 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ABI, Authority, BlockTimestamp, Checksum256, Float64, Name, PermissionLevel, PermissionLevelType, Struct, TimePoint, UInt32, UInt64} from '@wharfkit/antelope'
import {ABI, BlockTimestamp, Checksum256, Float64, Name, PermissionLevel, Struct, TimePoint, UInt32, UInt64, UInt8, Variant} from '@wharfkit/antelope'

@Struct.type('get_abi_snapshot_response')
export class GetABISnapshotResponse extends Struct {
Expand Down Expand Up @@ -121,3 +121,40 @@ export class GetCreatorResponse extends Struct {
@Struct.field(UInt32) declare block_num: UInt32;
@Struct.field(Checksum256) declare trx_id: Checksum256;
}

@Struct.type('delta')
export class Delta extends Struct {
@Struct.field(BlockTimestamp) declare timestamp: BlockTimestamp;
@Struct.field(UInt8) declare present: UInt8;
@Struct.field(Name) declare code: Name;
@Struct.field(Name) declare scope: Name;
@Struct.field(Name) declare table: Name;
@Struct.field(Name) declare primary_key: Name;
@Struct.field(Name) declare payer: Name;
@Struct.field(UInt64) declare block_num: UInt64;
@Struct.field(Checksum256) declare block_id: Checksum256;
@Struct.field('any') declare data: any;
}

@Struct.type('get_deltas_response')
export class GetDeltasResponse extends Struct {
@Struct.field(Float64) declare query_time_ms: Float64;
@Struct.field(TotalCount) declare total: TotalCount;
@Struct.field(Delta, { array: true }) declare deltas: Delta[];
}

@Struct.type('get_table_state_response')
export class GetTableStateResponse extends Struct {
@Struct.field(Float64) declare query_time_ms: Float64;
@Struct.field(Name) declare code: Name;
@Struct.field(Name) declare table: Name;
@Struct.field(UInt64) declare block_num: UInt64;
@Struct.field('string') declare after_key: string;
@Struct.field('string') declare next_key: string;
@Struct.field('any', { array: true }) declare results: any[];
}

@Struct.type('get_key_accounts_response')
export class GetKeyAccountsResponse extends Struct {
@Struct.field(Name, { array: true }) declare account_names: Name[];
}
25 changes: 23 additions & 2 deletions test/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {assert} from 'chai'

import {APIClient, FetchProvider, Name} from '@wharfkit/antelope'
import {APIClient, FetchProvider, Name, UInt64} from '@wharfkit/antelope'
import {mockFetch} from '@wharfkit/mock-data'

import {HyperionAPIClient} from '$lib'
Expand Down Expand Up @@ -79,5 +79,26 @@ suite('Hyperion API', function () {
assert.instanceOf(response.creator, Name);
assert.equal(String(response.creator), "gqyqi.waa");
})


test('get_deltas', async function () {
const response = await hyperion.get_deltas("eosio.token", "teamgreymass", "accounts", "teamgreymass");

assert.equal(response.deltas.length, 10);
assert.instanceOf(response.deltas[0].code, Name);
})

test('get_table_state', async function () {
const response = await hyperion.get_table_state("eosio.token", "stat", 267000000);

assert.instanceOf(response.code, Name);
assert.equal(response.results.length, 1);
})

test('get_key_accounts', async function () {
const response = await hyperion.get_key_accounts("EOS8KmhygTrrvtW7zJd6HXWrNqA5WX9NzScZ37JyXRiwpiJN2g2rR");

assert.equal(response.account_names.length, 1);
assert.instanceOf(response.account_names[0], Name);
assert.equal(String(response.account_names[0]), "teamgreymass");
})
})
15 changes: 15 additions & 0 deletions test/data/2022c93c5ef208662fe65475813f932e571ad2e3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"request": {
"path": "https://wax.blokcrafters.io/v2/state/get_key_accounts?public_key=EOS8KmhygTrrvtW7zJd6HXWrNqA5WX9NzScZ37JyXRiwpiJN2g2rR",
"params": {
"method": "GET"
}
},
"status": 200,
"json": {
"account_names": [
"teamgreymass"
]
},
"text": "{\"account_names\":[\"teamgreymass\"]}"
}
169 changes: 169 additions & 0 deletions test/data/75f3ed74b2d6a1bf2a18e614676205432f2c1f76.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
{
"request": {
"path": "https://wax.blokcrafters.io/v2/history/get_deltas?code=eosio.token&scope=teamgreymass&table=accounts&payer=teamgreymass",
"params": {
"method": "GET"
}
},
"status": 200,
"json": {
"query_time_ms": 943.284,
"total": {
"value": 2397,
"relation": "eq"
},
"deltas": [
{
"timestamp": "2023-09-20T17:51:01.500",
"present": 1,
"code": "eosio.token",
"scope": "teamgreymass",
"table": "accounts",
"primary_key": "5783895",
"payer": "teamgreymass",
"block_num": 267522160,
"block_id": "0ff210701e20b4fa1981189c0ea93524002dbab94e9a931fc1f7ca54c71372f5",
"data": {
"amount": 2393613.8538912,
"symbol": "WAX"
}
},
{
"timestamp": "2023-09-20T17:39:52.500",
"present": 1,
"code": "eosio.token",
"scope": "teamgreymass",
"table": "accounts",
"primary_key": "5783895",
"payer": "teamgreymass",
"block_num": 267520822,
"block_id": "0ff20b36ad36358d07e9ddd4240d32998970823b17a28c78b3d2f0b11da94e63",
"data": {
"amount": 2388453.938477,
"symbol": "WAX"
}
},
{
"timestamp": "2023-09-19T17:50:49.500",
"present": 1,
"code": "eosio.token",
"scope": "teamgreymass",
"table": "accounts",
"primary_key": "5783895",
"payer": "teamgreymass",
"block_num": 267349336,
"block_id": "0fef6d58c0ce663a3dfe5e713035950636e88748c677b27ca449052839ea181d",
"data": {
"amount": 2388448.7852525,
"symbol": "WAX"
}
},
{
"timestamp": "2023-09-19T17:39:40.000",
"present": 1,
"code": "eosio.token",
"scope": "teamgreymass",
"table": "accounts",
"primary_key": "5783895",
"payer": "teamgreymass",
"block_num": 267347997,
"block_id": "0fef681d69e905b80eb7ec374404d74bb68a90bd225ba5fd9444cdde55feafb8",
"data": {
"amount": 2383289.52493801,
"symbol": "WAX"
}
},
{
"timestamp": "2023-09-18T17:50:21.500",
"present": 1,
"code": "eosio.token",
"scope": "teamgreymass",
"table": "accounts",
"primary_key": "5783895",
"payer": "teamgreymass",
"block_num": 267176493,
"block_id": "0fecca2d7b85a1219f3a948cd755a7b863962c1240adc997b49db1e55da684ed",
"data": {
"amount": 2383284.36175499,
"symbol": "WAX"
}
},
{
"timestamp": "2023-09-18T17:39:05.000",
"present": 1,
"code": "eosio.token",
"scope": "teamgreymass",
"table": "accounts",
"primary_key": "5783895",
"payer": "teamgreymass",
"block_num": 267175140,
"block_id": "0fecc4e44e071984c88f082aea52b8d2fd5d683b6c7870c43f0fd52e904be433",
"data": {
"amount": 2378125.7774133,
"symbol": "WAX"
}
},
{
"timestamp": "2023-09-17T17:49:26.000",
"present": 1,
"code": "eosio.token",
"scope": "teamgreymass",
"table": "accounts",
"primary_key": "5783895",
"payer": "teamgreymass",
"block_num": 267003582,
"block_id": "0fea26beb4b92d6b8521da7fcba1c1f6d8d52ab934fadab2f430900c00e504a0",
"data": {
"amount": 2378120.60427956,
"symbol": "WAX"
}
},
{
"timestamp": "2023-09-17T17:38:14.500",
"present": 1,
"code": "eosio.token",
"scope": "teamgreymass",
"table": "accounts",
"primary_key": "5783895",
"payer": "teamgreymass",
"block_num": 267002239,
"block_id": "0fea217f1d2b155930ff5479938dc3ae54dc8710da2c3a69db4634491538dad7",
"data": {
"amount": 2372962.68205242,
"symbol": "WAX"
}
},
{
"timestamp": "2023-09-16T17:48:46.000",
"present": 1,
"code": "eosio.token",
"scope": "teamgreymass",
"table": "accounts",
"primary_key": "5783895",
"payer": "teamgreymass",
"block_num": 266830702,
"block_id": "0fe7836ed1cd2bf5cca67eece2fd2233409538de97929e422996121f603f929a",
"data": {
"amount": 2372957.50026775,
"symbol": "WAX"
}
},
{
"timestamp": "2023-09-16T17:37:37.000",
"present": 1,
"code": "eosio.token",
"scope": "teamgreymass",
"table": "accounts",
"primary_key": "5783895",
"payer": "teamgreymass",
"block_num": 266829364,
"block_id": "0fe77e345b262f5b4edf70856e117c7351edde35d06d5672f96f133da9f06282",
"data": {
"amount": 2367800.24434879,
"symbol": "WAX"
}
}
]
},
"text": "{\"query_time_ms\":943.284,\"total\":{\"value\":2397,\"relation\":\"eq\"},\"deltas\":[{\"timestamp\":\"2023-09-20T17:51:01.500\",\"present\":1,\"code\":\"eosio.token\",\"scope\":\"teamgreymass\",\"table\":\"accounts\",\"primary_key\":\"5783895\",\"payer\":\"teamgreymass\",\"block_num\":267522160,\"block_id\":\"0ff210701e20b4fa1981189c0ea93524002dbab94e9a931fc1f7ca54c71372f5\",\"data\":{\"amount\":2393613.8538912,\"symbol\":\"WAX\"}},{\"timestamp\":\"2023-09-20T17:39:52.500\",\"present\":1,\"code\":\"eosio.token\",\"scope\":\"teamgreymass\",\"table\":\"accounts\",\"primary_key\":\"5783895\",\"payer\":\"teamgreymass\",\"block_num\":267520822,\"block_id\":\"0ff20b36ad36358d07e9ddd4240d32998970823b17a28c78b3d2f0b11da94e63\",\"data\":{\"amount\":2388453.938477,\"symbol\":\"WAX\"}},{\"timestamp\":\"2023-09-19T17:50:49.500\",\"present\":1,\"code\":\"eosio.token\",\"scope\":\"teamgreymass\",\"table\":\"accounts\",\"primary_key\":\"5783895\",\"payer\":\"teamgreymass\",\"block_num\":267349336,\"block_id\":\"0fef6d58c0ce663a3dfe5e713035950636e88748c677b27ca449052839ea181d\",\"data\":{\"amount\":2388448.7852525,\"symbol\":\"WAX\"}},{\"timestamp\":\"2023-09-19T17:39:40.000\",\"present\":1,\"code\":\"eosio.token\",\"scope\":\"teamgreymass\",\"table\":\"accounts\",\"primary_key\":\"5783895\",\"payer\":\"teamgreymass\",\"block_num\":267347997,\"block_id\":\"0fef681d69e905b80eb7ec374404d74bb68a90bd225ba5fd9444cdde55feafb8\",\"data\":{\"amount\":2383289.52493801,\"symbol\":\"WAX\"}},{\"timestamp\":\"2023-09-18T17:50:21.500\",\"present\":1,\"code\":\"eosio.token\",\"scope\":\"teamgreymass\",\"table\":\"accounts\",\"primary_key\":\"5783895\",\"payer\":\"teamgreymass\",\"block_num\":267176493,\"block_id\":\"0fecca2d7b85a1219f3a948cd755a7b863962c1240adc997b49db1e55da684ed\",\"data\":{\"amount\":2383284.36175499,\"symbol\":\"WAX\"}},{\"timestamp\":\"2023-09-18T17:39:05.000\",\"present\":1,\"code\":\"eosio.token\",\"scope\":\"teamgreymass\",\"table\":\"accounts\",\"primary_key\":\"5783895\",\"payer\":\"teamgreymass\",\"block_num\":267175140,\"block_id\":\"0fecc4e44e071984c88f082aea52b8d2fd5d683b6c7870c43f0fd52e904be433\",\"data\":{\"amount\":2378125.7774133,\"symbol\":\"WAX\"}},{\"timestamp\":\"2023-09-17T17:49:26.000\",\"present\":1,\"code\":\"eosio.token\",\"scope\":\"teamgreymass\",\"table\":\"accounts\",\"primary_key\":\"5783895\",\"payer\":\"teamgreymass\",\"block_num\":267003582,\"block_id\":\"0fea26beb4b92d6b8521da7fcba1c1f6d8d52ab934fadab2f430900c00e504a0\",\"data\":{\"amount\":2378120.60427956,\"symbol\":\"WAX\"}},{\"timestamp\":\"2023-09-17T17:38:14.500\",\"present\":1,\"code\":\"eosio.token\",\"scope\":\"teamgreymass\",\"table\":\"accounts\",\"primary_key\":\"5783895\",\"payer\":\"teamgreymass\",\"block_num\":267002239,\"block_id\":\"0fea217f1d2b155930ff5479938dc3ae54dc8710da2c3a69db4634491538dad7\",\"data\":{\"amount\":2372962.68205242,\"symbol\":\"WAX\"}},{\"timestamp\":\"2023-09-16T17:48:46.000\",\"present\":1,\"code\":\"eosio.token\",\"scope\":\"teamgreymass\",\"table\":\"accounts\",\"primary_key\":\"5783895\",\"payer\":\"teamgreymass\",\"block_num\":266830702,\"block_id\":\"0fe7836ed1cd2bf5cca67eece2fd2233409538de97929e422996121f603f929a\",\"data\":{\"amount\":2372957.50026775,\"symbol\":\"WAX\"}},{\"timestamp\":\"2023-09-16T17:37:37.000\",\"present\":1,\"code\":\"eosio.token\",\"scope\":\"teamgreymass\",\"table\":\"accounts\",\"primary_key\":\"5783895\",\"payer\":\"teamgreymass\",\"block_num\":266829364,\"block_id\":\"0fe77e345b262f5b4edf70856e117c7351edde35d06d5672f96f133da9f06282\",\"data\":{\"amount\":2367800.24434879,\"symbol\":\"WAX\"}}]}"
}
34 changes: 34 additions & 0 deletions test/data/93da23af41b5be58591d536c15e3c8001707746b.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"request": {
"path": "https://wax.blokcrafters.io/v2/history/get_table_state?code=eosio.token&table=stat&block_num=267000000&after_key=",
"params": {
"method": "GET"
}
},
"status": 200,
"json": {
"query_time_ms": 13767.49,
"code": "eosio.token",
"table": "stat",
"block_num": 267000000,
"after_key": "",
"next_key": "........f1.pb-5783895",
"results": [
{
"scope": "........f1.pb",
"primary_key": "5783895",
"payer": "eosio.token",
"timestamp": "2023-09-17T17:19:33.000",
"block_num": 266999996,
"block_id": "0fea18bca71f5f7313ea8f1a0a03e1677018f3ec212c94e401a4eb88d7f74bcb",
"present": 1,
"data": {
"max_supply": "46116860184.27387903 WAX",
"supply": "4049099831.80933812 WAX",
"issuer": "eosio"
}
}
]
},
"text": "{\"query_time_ms\":13767.49,\"code\":\"eosio.token\",\"table\":\"stat\",\"block_num\":267000000,\"after_key\":\"\",\"next_key\":\"........f1.pb-5783895\",\"results\":[{\"scope\":\"........f1.pb\",\"primary_key\":\"5783895\",\"payer\":\"eosio.token\",\"timestamp\":\"2023-09-17T17:19:33.000\",\"block_num\":266999996,\"block_id\":\"0fea18bca71f5f7313ea8f1a0a03e1677018f3ec212c94e401a4eb88d7f74bcb\",\"present\":1,\"data\":{\"max_supply\":\"46116860184.27387903 WAX\",\"supply\":\"4049099831.80933812 WAX\",\"issuer\":\"eosio\"}}]}"
}

0 comments on commit cdd1c7e

Please sign in to comment.