Skip to content

Commit

Permalink
chore: added get_abi_snapshot method
Browse files Browse the repository at this point in the history
  • Loading branch information
dafuga committed Sep 20, 2023
1 parent 193cacf commit 54ac5c4
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 85 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"prepare": "make"
},
"dependencies": {
"@wharfkit/antelope": "^0.9.1",
"@wharfkit/antelope": "^0.10.0-rc1",
"tslib": "^2.0.3"
},
"resolutions": {
Expand Down
30 changes: 13 additions & 17 deletions src/endpoints.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
import {API, APIClient} from '@wharfkit/antelope'
import {ABI, APIClient} from '@wharfkit/antelope'

export class ExampleAPI {
export class HyperionAPIClient {
constructor(private client: APIClient) {}

/**
* Define the calls for the API
*/
// async get_raw_abi(accountName: NameType) {
// return this.call({
// path: '/v1/chain/get_raw_abi',
// params: {account_name: Name.from(accountName)},
// responseType: GetRawAbiResponse,
// })
// }
async get_abi_snapshot(contract: string, block?: number, fetch = false): Promise<ABI.Def> {
if (!block) {
const info = await this.client.v1.chain.get_info()

// Example for testing
async get_info() {
return this.client.call({
path: '/v1/chain/get_info',
responseType: API.v1.GetInfoResponse,
block = Number(info.last_irreversible_block_num)
}

return this.client.call<ABI.Def>({
path: `/v2/history/get_abi_snapshot?contract=${encodeURIComponent(
contract
)}&block=${block}&fetch=${fetch}`,
method: 'GET',
})
}
}
28 changes: 2 additions & 26 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,3 @@
/**
* Define the API response types
*
* Example and mock below
*/

import {Struct} from '@wharfkit/antelope'

@Struct.type('example_response')
export class ExampleResponse extends Struct {
@Struct.field('string') declare foo: string
export interface Response {
code: number
}

// import {
// Blob,
// Checksum256,
// Name,
// Struct,
// } from '@wharfkit/antelope'

// @Struct.type('get_raw_abi_response')
// export class GetRawAbiResponse extends Struct {
// @Struct.field('name') declare account_name: Name
// @Struct.field('checksum256') declare code_hash: Checksum256
// @Struct.field('checksum256') declare abi_hash: Checksum256
// @Struct.field(Blob) declare abi: Blob
// }
27 changes: 18 additions & 9 deletions test/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,31 @@ import {assert} from 'chai'
import {APIClient, FetchProvider} from '@wharfkit/antelope'
import {mockFetch} from '@wharfkit/mock-data'

import {ExampleAPI} from '$lib'
import {HyperionAPIClient} from '$lib' // Replace with the actual import

const ABIResponse = {
// Add mock data that mimics the actual ABI snapshot structure
};

// Setup an APIClient
const client = new APIClient({
provider: new FetchProvider('https://jungle4.greymass.com', {fetch: mockFetch}),
provider: new FetchProvider('https://eos.hyperion.eosrio.io/', {fetch: mockFetch}),
})

// Setup the API
const example = new ExampleAPI(client)
const hyperion = new HyperionAPIClient(client)

suite('api', function () {
suite('Hyperion API', function () {
this.slow(200)
this.timeout(10 * 10000)

test('call test api', async function () {
const res = await example.get_info()
assert.equal(res.server_version, '905c5cc9')
test('get_abi_snapshot', async function () {
const response = await hyperion.get_abi_snapshot("eosio.token", 2000, true);
assert.deepEqual(response, {
"block_num": null,
"error": "abi not found for eosio.token until block 2000",
"last_indexed_block": 331963268,
"last_indexed_block_time": "2023-09-20T00:35:04.500",
"present": false,
"query_time_ms": 4,
});
})
})
18 changes: 18 additions & 0 deletions test/data/aa490d31c69413cc7a57f14e10d31884a6ebff04.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"request": {
"path": "https://eos.hyperion.eosrio.io/v2/history/get_abi_snapshot?contract=eosio.token&block=2000&fetch=true",
"params": {
"method": "GET"
}
},
"status": 200,
"json": {
"block_num": null,
"present": false,
"error": "abi not found for eosio.token until block 2000",
"query_time_ms": 4,
"last_indexed_block": 331963268,
"last_indexed_block_time": "2023-09-20T00:35:04.500"
},
"text": "{\"block_num\":null,\"present\":false,\"error\":\"abi not found for eosio.token until block 2000\",\"query_time_ms\":4,\"last_indexed_block\":331963268,\"last_indexed_block_time\":\"2023-09-20T00:35:04.500\"}"
}
32 changes: 0 additions & 32 deletions test/data/b5ae1f53ef4cf6544fe89a0deb7a7d1043f43149.json

This file was deleted.

12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,18 @@
pako "^2.0.4"
tslib "^2.1.0"

"@wharfkit/antelope@^0.10.0-rc1":
version "0.10.0-rc1"
resolved "https://registry.yarnpkg.com/@wharfkit/antelope/-/antelope-0.10.0-rc1.tgz#c3b83a2aaae5bebd4393455f2598f0fd9d17fb60"
integrity sha512-+rvXSGNEbzclMfg3ntyJ09jrjEdM56APV2WGoJHwEEAFjvHfKNUxunybxv6UrG3EgpCDcmSk+kiWQvbGevhCdw==
dependencies:
bn.js "^4.11.9"
brorand "^1.1.0"
elliptic "^6.5.4"
hash.js "^1.0.0"
pako "^2.1.0"
tslib "^2.0.3"

"@wharfkit/antelope@^0.7.3", "@wharfkit/antelope@^0.9.1":
version "0.9.1"
resolved "https://registry.yarnpkg.com/@wharfkit/antelope/-/antelope-0.9.1.tgz#ff6cfbb6f3c4e373407764cfce44a539dbb521ae"
Expand Down

0 comments on commit 54ac5c4

Please sign in to comment.