Skip to content

Commit 30b43b6

Browse files
committed
Allow extracting nodeos API query params from cursor
1 parent 1e84f06 commit 30b43b6

3 files changed

Lines changed: 31 additions & 21 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@wharfkit/contract",
33
"description": "ContractKit for Wharf",
4-
"version": "1.2.1",
4+
"version": "1.2.2-rc1",
55
"homepage": "https://github.com/wharfkit/contract",
66
"license": "BSD-3-Clause",
77
"main": "lib/contract.js",

src/contract/row-cursor.ts

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {API, Serializer} from '@wharfkit/antelope'
2-
import {wrapIndexValue} from '../utils'
32
import {TableCursor} from './table-cursor'
43

54
export class TableRowCursor<RowType = any> extends TableCursor {
@@ -15,26 +14,10 @@ export class TableRowCursor<RowType = any> extends TableCursor {
1514
return []
1615
}
1716

18-
// Set the lower_bound, and override if the cursor has a next_key value
19-
let lower_bound = this.params.lower_bound
20-
if (this.next_key) {
21-
lower_bound = this.next_key
22-
}
23-
24-
// Determine the maximum number of remaining rows for the cursor
25-
const rowsRemaining = this.maxRows - this.rowsCount
26-
27-
// Find the lowest amount between rows remaining, rows per request, or the provided query params limit
28-
const limit = Math.min(rowsRemaining, rowsPerAPIRequest, this.params.limit)
29-
30-
// Assemble and perform the v1/chain/get_table_rows query
31-
const query = {
32-
...this.params,
33-
limit,
34-
lower_bound: wrapIndexValue(lower_bound),
35-
upper_bound: wrapIndexValue(this.params.upper_bound),
36-
}
17+
// Assemble the query params
18+
const query = this.getTableRowsParams(rowsPerAPIRequest)
3719

20+
// Execute the query
3821
const result = await this.client!.v1.chain.get_table_rows(query)
3922

4023
// Determine if we need to decode the rows, based on if:

src/contract/table-cursor.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {ABI, ABIDef, API, APIClient, Name} from '@wharfkit/antelope'
2+
import {wrapIndexValue} from '../utils'
23

34
/** Mashup of valid types for an APIClient call to v1.chain.get_table_rows */
45
export type TableRowParamsTypes =
@@ -123,4 +124,30 @@ export abstract class TableCursor<RowType = any> {
123124
}
124125
return rows
125126
}
127+
128+
/**
129+
* Build the query for the get_table_rows API endpoint.
130+
*/
131+
getTableRowsParams(rowsPerAPIRequest: number = Number.MAX_SAFE_INTEGER): any {
132+
// Set the lower_bound, and override if the cursor has a next_key value
133+
let lower_bound = this.params.lower_bound
134+
if (this.next_key) {
135+
lower_bound = this.next_key
136+
}
137+
138+
// Determine the maximum number of remaining rows for the cursor
139+
const rowsRemaining = this.maxRows - this.rowsCount
140+
141+
// Find the lowest amount between rows remaining, rows per request, or the provided query params limit
142+
const limit = Math.min(rowsRemaining, rowsPerAPIRequest, this.params.limit)
143+
144+
// Assemble and perform the v1/chain/get_table_rows query
145+
const query = {
146+
...this.params,
147+
limit,
148+
lower_bound: wrapIndexValue(lower_bound),
149+
upper_bound: wrapIndexValue(this.params.upper_bound),
150+
}
151+
return query
152+
}
126153
}

0 commit comments

Comments
 (0)