generated from wharfkit/api-client-template
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementing all Hyperion v2 calls #1
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
54ac5c4
chore: added get_abi_snapshot method
dafuga f26d558
chore: added get_voters function
dafuga eaef62e
chore: added get_links, get_proposals and get_actions
dafuga a7c4bb5
chore: added get_created_accounts and get_creator endpoints
dafuga cdd1c7e
chore: added get_deltas, get_table_state and get_key_accounts
dafuga df03a9a
chore: added get_tokens and get_transaction
dafuga 2d18fdd
style: linted
dafuga File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,44 @@ | ||
import {API, APIClient} from '@wharfkit/antelope' | ||
import {ABI, APIClient} from '@wharfkit/antelope' | ||
import {GetVotersResponse} from './types' | ||
|
||
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, | ||
// }) | ||
// } | ||
|
||
// Example for testing | ||
async get_info() { | ||
async get_abi_snapshot(contract: string, block?: number, fetch = false): Promise<ABI.Def> { | ||
if (!block) { | ||
const info = await this.client.v1.chain.get_info() | ||
|
||
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', | ||
}) | ||
} | ||
|
||
async get_voters( | ||
producer?: string, | ||
proxy?: boolean, | ||
skip?: number, | ||
limit?: number | ||
): Promise<GetVotersResponse> { | ||
let queryParams = '' | ||
const queryParts: string[] = [] | ||
|
||
if (producer) queryParts.push(`producer=${encodeURIComponent(producer)}`) | ||
if (proxy !== undefined) queryParts.push(`proxy=${proxy}`) | ||
if (skip !== undefined) queryParts.push(`skip=${skip}`) | ||
if (limit !== undefined) queryParts.push(`limit=${limit}`) | ||
|
||
queryParams = queryParts.length ? '?' + queryParts.join('&') : '' | ||
|
||
return this.client.call({ | ||
path: '/v1/chain/get_info', | ||
responseType: API.v1.GetInfoResponse, | ||
path: `/v2/state/get_voters${queryParams}`, | ||
method: 'GET', | ||
responseType: GetVotersResponse, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,13 @@ | ||
/** | ||
* Define the API response types | ||
* | ||
* Example and mock below | ||
*/ | ||
import {Float64, Name, Struct, UInt32} from '@wharfkit/antelope' | ||
|
||
import {Struct} from '@wharfkit/antelope' | ||
|
||
@Struct.type('example_response') | ||
export class ExampleResponse extends Struct { | ||
@Struct.field('string') declare foo: string | ||
@Struct.type('voter') | ||
export class Voter extends Struct { | ||
@Struct.field('name') declare account: Name | ||
@Struct.field('float64') declare weight: Float64 | ||
@Struct.field('uint32') declare last_vote: UInt32 | ||
} | ||
|
||
// 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 | ||
// } | ||
@Struct.type('get_voters_response') | ||
export class GetVotersResponse extends Struct { | ||
@Struct.field(Voter, {array: true}) declare voters: Voter[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
test/data/9215270de3881cced9b6bebe07e24133100e3380.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
{ | ||
"request": { | ||
"path": "https://eos.hyperion.eosrio.io/v2/state/get_voters?producer=eoscafeblock&proxy=true&skip=100&limit=200", | ||
"params": { | ||
"method": "GET" | ||
} | ||
}, | ||
"status": 200, | ||
"json": { | ||
"query_time_ms": 10.267, | ||
"last_indexed_block": 331966018, | ||
"last_indexed_block_time": "2023-09-20T00:57:59.500", | ||
"voters": [ | ||
{ | ||
"account": "killc.ftw", | ||
"weight": 20161076275.827435, | ||
"last_vote": 297527904 | ||
}, | ||
{ | ||
"account": "lilyoda12345", | ||
"weight": 15164256984.237717, | ||
"last_vote": 321496531 | ||
}, | ||
{ | ||
"account": "fddsfweghdfd", | ||
"weight": 14755561472, | ||
"last_vote": 282378753 | ||
}, | ||
{ | ||
"account": "butthead.ftw", | ||
"weight": 10524346886.033388, | ||
"last_vote": 327820867 | ||
}, | ||
{ | ||
"account": "httpsjmc.ftw", | ||
"weight": 8449496093.827727, | ||
"last_vote": 298379213 | ||
}, | ||
{ | ||
"account": "vecrazylazyy", | ||
"weight": 7540108464.555911, | ||
"last_vote": 272264082 | ||
}, | ||
{ | ||
"account": "dariusb.ftw", | ||
"weight": 2366668638.478459, | ||
"last_vote": 299903987 | ||
}, | ||
{ | ||
"account": "ghostwritter", | ||
"weight": 1825622665.1887114, | ||
"last_vote": 331476321 | ||
}, | ||
{ | ||
"account": "metamaskbc12", | ||
"weight": 1095142587.150208, | ||
"last_vote": 307011199 | ||
}, | ||
{ | ||
"account": "furkza.ftw", | ||
"weight": 180920288.5627205, | ||
"last_vote": 284399586 | ||
}, | ||
{ | ||
"account": "tanb5.ftw", | ||
"weight": 0, | ||
"last_vote": 269829286 | ||
}, | ||
{ | ||
"account": "exh121.ftw", | ||
"weight": 0, | ||
"last_vote": 274065500 | ||
}, | ||
{ | ||
"account": "5422gameseos", | ||
"weight": 0, | ||
"last_vote": 277702462 | ||
}, | ||
{ | ||
"account": "kurka134.ftw", | ||
"weight": 0, | ||
"last_vote": 303928120 | ||
}, | ||
{ | ||
"account": "hereticsteyn", | ||
"weight": 0, | ||
"last_vote": 310308429 | ||
}, | ||
{ | ||
"account": "omgant.ftw", | ||
"weight": 0, | ||
"last_vote": 329472633 | ||
}, | ||
{ | ||
"account": "gogoen.ftw", | ||
"weight": 0, | ||
"last_vote": 274148470 | ||
}, | ||
{ | ||
"account": "ariajack.ftw", | ||
"weight": 0, | ||
"last_vote": 281208030 | ||
}, | ||
{ | ||
"account": "sanihims.ftw", | ||
"weight": 0, | ||
"last_vote": 283638883 | ||
}, | ||
{ | ||
"account": "mawe2323.ftw", | ||
"weight": 0, | ||
"last_vote": 285576963 | ||
}, | ||
{ | ||
"account": "blanniem.ftw", | ||
"weight": 0, | ||
"last_vote": 290828124 | ||
}, | ||
{ | ||
"account": "gobrentb.ftw", | ||
"weight": 0, | ||
"last_vote": 302093796 | ||
}, | ||
{ | ||
"account": "supasaiyajay", | ||
"weight": 0, | ||
"last_vote": 314092695 | ||
}, | ||
{ | ||
"account": "adrianst1212", | ||
"weight": 0, | ||
"last_vote": 328663340 | ||
} | ||
] | ||
}, | ||
"text": "{\"query_time_ms\":10.267,\"last_indexed_block\":331966018,\"last_indexed_block_time\":\"2023-09-20T00:57:59.500\",\"voters\":[{\"account\":\"killc.ftw\",\"weight\":20161076275.827435,\"last_vote\":297527904},{\"account\":\"lilyoda12345\",\"weight\":15164256984.237717,\"last_vote\":321496531},{\"account\":\"fddsfweghdfd\",\"weight\":14755561472,\"last_vote\":282378753},{\"account\":\"butthead.ftw\",\"weight\":10524346886.033388,\"last_vote\":327820867},{\"account\":\"httpsjmc.ftw\",\"weight\":8449496093.827727,\"last_vote\":298379213},{\"account\":\"vecrazylazyy\",\"weight\":7540108464.555911,\"last_vote\":272264082},{\"account\":\"dariusb.ftw\",\"weight\":2366668638.478459,\"last_vote\":299903987},{\"account\":\"ghostwritter\",\"weight\":1825622665.1887114,\"last_vote\":331476321},{\"account\":\"metamaskbc12\",\"weight\":1095142587.150208,\"last_vote\":307011199},{\"account\":\"furkza.ftw\",\"weight\":180920288.5627205,\"last_vote\":284399586},{\"account\":\"tanb5.ftw\",\"weight\":0,\"last_vote\":269829286},{\"account\":\"exh121.ftw\",\"weight\":0,\"last_vote\":274065500},{\"account\":\"5422gameseos\",\"weight\":0,\"last_vote\":277702462},{\"account\":\"kurka134.ftw\",\"weight\":0,\"last_vote\":303928120},{\"account\":\"hereticsteyn\",\"weight\":0,\"last_vote\":310308429},{\"account\":\"omgant.ftw\",\"weight\":0,\"last_vote\":329472633},{\"account\":\"gogoen.ftw\",\"weight\":0,\"last_vote\":274148470},{\"account\":\"ariajack.ftw\",\"weight\":0,\"last_vote\":281208030},{\"account\":\"sanihims.ftw\",\"weight\":0,\"last_vote\":283638883},{\"account\":\"mawe2323.ftw\",\"weight\":0,\"last_vote\":285576963},{\"account\":\"blanniem.ftw\",\"weight\":0,\"last_vote\":290828124},{\"account\":\"gobrentb.ftw\",\"weight\":0,\"last_vote\":302093796},{\"account\":\"supasaiyajay\",\"weight\":0,\"last_vote\":314092695},{\"account\":\"adrianst1212\",\"weight\":0,\"last_vote\":328663340}]}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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\"}" | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we make all the inputs be typed, e.g. this one being a
NameType
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep!