-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
11,942 additions
and
74 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import {ABIDef, Action, ActionType, AnyAction} from '@wharfkit/antelope' | ||
|
||
export class ContractAction extends Action { | ||
static from<T>(object: ActionType | AnyAction, abi?: ABIDef): T { | ||
return super.from(object, abi) as T | ||
} | ||
} |
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,56 @@ | ||
import {API} from '@wharfkit/antelope' | ||
import {TableCursor} from './table-cursor' | ||
|
||
export class TableScopeCursor extends TableCursor { | ||
/** | ||
* Fetch the next batch of rows from the cursor. | ||
* | ||
* @param rowsPerAPIRequest The number of rows to fetch per API request. | ||
* @returns A promise containing the next batch of rows. | ||
*/ | ||
async next( | ||
rowsPerAPIRequest: number = Number.MAX_SAFE_INTEGER | ||
): Promise<API.v1.GetTableByScopeResponseRow[]> { | ||
// If the cursor has deemed its at the end, return an empty array | ||
if (this.endReached) { | ||
return [] | ||
} | ||
|
||
// Set the lower_bound, and override if the cursor has a next_key value | ||
let lower_bound = this.params.lower_bound | ||
if (this.next_key) { | ||
lower_bound = this.next_key | ||
} | ||
|
||
// Determine the maximum number of remaining rows for the cursor | ||
const rowsRemaining = this.maxRows - this.rowsCount | ||
|
||
// Find the lowest amount between rows remaining, rows per request, or the provided query params limit | ||
const limit = Math.min(rowsRemaining, rowsPerAPIRequest, this.params.limit) | ||
|
||
// Assemble and perform the v1/chain/get_table_rows query | ||
const query: API.v1.GetTableByScopeParams = { | ||
code: this.params.code, | ||
table: this.params.table, | ||
limit, | ||
lower_bound: lower_bound ? String(lower_bound) : undefined, | ||
upper_bound: this.params.upper_bound ? String(this.params.upper_bound) : undefined, | ||
} | ||
|
||
const result = await this.client!.v1.chain.get_table_by_scope(query) | ||
|
||
// Retrieve the rows from the result, decoding if needed | ||
const rows: API.v1.GetTableByScopeResponseRow[] = result.rows | ||
|
||
// Persist cursor state for subsequent calls | ||
this.next_key = result.more | ||
this.rowsCount += rows.length | ||
|
||
// Determine if we've reached the end of the cursor | ||
if (!result.more || rows.length === 0 || this.rowsCount === this.maxRows) { | ||
this.endReached = true | ||
} | ||
|
||
return rows | ||
} | ||
} |
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
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,6 +1,6 @@ | ||
export * from './contract' | ||
export * from './contract/table' | ||
export * from './contract/row-cursor' | ||
// export * from './contract/scope-cursor' | ||
export * from './contract/scope-cursor' | ||
export * from './kit' | ||
export * from './utils' |
86 changes: 86 additions & 0 deletions
86
test/data/requests/0ca21fdda73edaa99a47135d3ec7e0e1c4fd9901.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,86 @@ | ||
{ | ||
"request": { | ||
"path": "https://eos.greymass.com/v1/chain/get_table_by_scope", | ||
"params": { | ||
"method": "POST", | ||
"body": "{\"code\":\"eosio.msig\",\"table\":\"proposal\",\"limit\":10,\"lower_bound\":\"1charcha.ftw\"}" | ||
} | ||
}, | ||
"status": 200, | ||
"json": { | ||
"rows": [ | ||
{ | ||
"code": "eosio.msig", | ||
"scope": "1charcha.ftw", | ||
"table": "proposal", | ||
"payer": "1charcha.ftw", | ||
"count": 1 | ||
}, | ||
{ | ||
"code": "eosio.msig", | ||
"scope": "1cjfya.ftw", | ||
"table": "proposal", | ||
"payer": "1cjfya.ftw", | ||
"count": 1 | ||
}, | ||
{ | ||
"code": "eosio.msig", | ||
"scope": "1farah.ftw", | ||
"table": "proposal", | ||
"payer": "1farah.ftw", | ||
"count": 3 | ||
}, | ||
{ | ||
"code": "eosio.msig", | ||
"scope": "1luntxd.ftw", | ||
"table": "proposal", | ||
"payer": "1luntxd.ftw", | ||
"count": 1 | ||
}, | ||
{ | ||
"code": "eosio.msig", | ||
"scope": "1muarte.ftw", | ||
"table": "proposal", | ||
"payer": "1muarte.ftw", | ||
"count": 1 | ||
}, | ||
{ | ||
"code": "eosio.msig", | ||
"scope": "1mycrypto213", | ||
"table": "proposal", | ||
"payer": "1mycrypto213", | ||
"count": 2 | ||
}, | ||
{ | ||
"code": "eosio.msig", | ||
"scope": "1plsd.ftw", | ||
"table": "proposal", | ||
"payer": "1plsd.ftw", | ||
"count": 1 | ||
}, | ||
{ | ||
"code": "eosio.msig", | ||
"scope": "1rtkjeosdac1", | ||
"table": "proposal", | ||
"payer": "1rtkjeosdac1", | ||
"count": 1 | ||
}, | ||
{ | ||
"code": "eosio.msig", | ||
"scope": "1shahram.ftw", | ||
"table": "proposal", | ||
"payer": "1shahram.ftw", | ||
"count": 1 | ||
}, | ||
{ | ||
"code": "eosio.msig", | ||
"scope": "1slapaho.ftw", | ||
"table": "proposal", | ||
"payer": "1slapaho.ftw", | ||
"count": 1 | ||
} | ||
], | ||
"more": "1stdwn33.ftw" | ||
}, | ||
"text": "{\"rows\":[{\"code\":\"eosio.msig\",\"scope\":\"1charcha.ftw\",\"table\":\"proposal\",\"payer\":\"1charcha.ftw\",\"count\":1},{\"code\":\"eosio.msig\",\"scope\":\"1cjfya.ftw\",\"table\":\"proposal\",\"payer\":\"1cjfya.ftw\",\"count\":1},{\"code\":\"eosio.msig\",\"scope\":\"1farah.ftw\",\"table\":\"proposal\",\"payer\":\"1farah.ftw\",\"count\":3},{\"code\":\"eosio.msig\",\"scope\":\"1luntxd.ftw\",\"table\":\"proposal\",\"payer\":\"1luntxd.ftw\",\"count\":1},{\"code\":\"eosio.msig\",\"scope\":\"1muarte.ftw\",\"table\":\"proposal\",\"payer\":\"1muarte.ftw\",\"count\":1},{\"code\":\"eosio.msig\",\"scope\":\"1mycrypto213\",\"table\":\"proposal\",\"payer\":\"1mycrypto213\",\"count\":2},{\"code\":\"eosio.msig\",\"scope\":\"1plsd.ftw\",\"table\":\"proposal\",\"payer\":\"1plsd.ftw\",\"count\":1},{\"code\":\"eosio.msig\",\"scope\":\"1rtkjeosdac1\",\"table\":\"proposal\",\"payer\":\"1rtkjeosdac1\",\"count\":1},{\"code\":\"eosio.msig\",\"scope\":\"1shahram.ftw\",\"table\":\"proposal\",\"payer\":\"1shahram.ftw\",\"count\":1},{\"code\":\"eosio.msig\",\"scope\":\"1slapaho.ftw\",\"table\":\"proposal\",\"payer\":\"1slapaho.ftw\",\"count\":1}],\"more\":\"1stdwn33.ftw\"}" | ||
} |
30 changes: 30 additions & 0 deletions
30
test/data/requests/16978d9aa599819a2e0c519e805c979aac765121.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,30 @@ | ||
{ | ||
"request": { | ||
"path": "https://eos.greymass.com/v1/chain/get_table_by_scope", | ||
"params": { | ||
"method": "POST", | ||
"body": "{\"code\":\"eosio.msig\",\"table\":\"proposal\",\"limit\":2}" | ||
} | ||
}, | ||
"status": 200, | ||
"json": { | ||
"rows": [ | ||
{ | ||
"code": "eosio.msig", | ||
"scope": "1111111zzzzz", | ||
"table": "proposal", | ||
"payer": "1111111zzzzz", | ||
"count": 1 | ||
}, | ||
{ | ||
"code": "eosio.msig", | ||
"scope": "113332.pcash", | ||
"table": "proposal", | ||
"payer": "113332.pcash", | ||
"count": 1 | ||
} | ||
], | ||
"more": "11rippche24y" | ||
}, | ||
"text": "{\"rows\":[{\"code\":\"eosio.msig\",\"scope\":\"1111111zzzzz\",\"table\":\"proposal\",\"payer\":\"1111111zzzzz\",\"count\":1},{\"code\":\"eosio.msig\",\"scope\":\"113332.pcash\",\"table\":\"proposal\",\"payer\":\"113332.pcash\",\"count\":1}],\"more\":\"11rippche24y\"}" | ||
} |
30 changes: 30 additions & 0 deletions
30
test/data/requests/2193f0c21bbcfbc0e4adddf35a7c4162d04f9df1.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,30 @@ | ||
{ | ||
"request": { | ||
"path": "https://eos.greymass.com/v1/chain/get_table_by_scope", | ||
"params": { | ||
"method": "POST", | ||
"body": "{\"code\":\"eosio.msig\",\"table\":\"proposal\",\"limit\":2,\"lower_bound\":\"11rippche24y\"}" | ||
} | ||
}, | ||
"status": 200, | ||
"json": { | ||
"rows": [ | ||
{ | ||
"code": "eosio.msig", | ||
"scope": "11rippche24y", | ||
"table": "proposal", | ||
"payer": "11rippche24y", | ||
"count": 1 | ||
}, | ||
{ | ||
"code": "eosio.msig", | ||
"scope": "121moe.ftw", | ||
"table": "proposal", | ||
"payer": "121moe.ftw", | ||
"count": 1 | ||
} | ||
], | ||
"more": "12235213.ftw" | ||
}, | ||
"text": "{\"rows\":[{\"code\":\"eosio.msig\",\"scope\":\"11rippche24y\",\"table\":\"proposal\",\"payer\":\"11rippche24y\",\"count\":1},{\"code\":\"eosio.msig\",\"scope\":\"121moe.ftw\",\"table\":\"proposal\",\"payer\":\"121moe.ftw\",\"count\":1}],\"more\":\"12235213.ftw\"}" | ||
} |
Oops, something went wrong.