Skip to content

Commit

Permalink
Made it possible to pass down getTableRows options beyond just scope.
Browse files Browse the repository at this point in the history
  • Loading branch information
thekevinbrown committed May 21, 2019
1 parent 15adf32 commit 8fdce04
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
25 changes: 23 additions & 2 deletions src/contracts/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ export interface ContractConstructorArgs {
types: Map<string, Type>;
}

export interface GetTableRowsOptions {
scope?: string;
tableKey?: string;
lowerBound?: any;
upperBound?: any;
indexPosition?: any;
keyType?: any;
limit?: number;
reverse?: boolean;
showPayer?: boolean;
}

/**
* Adds additional functionality to the EOSJS `Contract` class
*/
Expand Down Expand Up @@ -134,14 +146,23 @@ export class Contract implements EOSJSContract {
* @note Implements a temporary patch for the EOSjs `bool` mapping error
* @param table The table name
* @param scope Optional table scope, defaults to the table name
* @note The original EOSJS typings for this are just `any`. I'd love to improve that.
*/
public getTableRows = async (table: string, scope?: string) => {
public getTableRows = async (table: string, options?: GetTableRowsOptions) => {
// Wait for the next block to appear before we query the values.
await nextBlock();

const result = await this._eos.rpc.get_table_rows({
code: this.account.name,
scope: scope || this.account.name,
scope: (options && options.scope) || this.account.name,
table_key: options && options.tableKey,
lower_bound: options && options.lowerBound,
upper_bound: options && options.upperBound,
index_position: options && options.indexPosition,
key_type: options && options.keyType,
limit: options && options.limit,
reverse: options && options.reverse,
show_payer: options && options.showPayer,
table,
json: true,
});
Expand Down
6 changes: 4 additions & 2 deletions src/contracts/typeGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const generateTypes = async (contractIdentifier: string) => {
'',
];
// Define imports
const imports = ['Account', 'Contract'];
const imports = ['Account', 'Contract', 'GetTableRowsOptions'];
if (contractTables.length > 0) imports.push('TableRowsResult');
// Generate import definitions
result.push(`import { ${imports.join(', ')} } from 'lamington';`);
Expand Down Expand Up @@ -106,7 +106,9 @@ export const generateTypes = async (contractIdentifier: string) => {
// Generate tables
const generatedTables = contractTables.map(
(table: any) =>
`${camelCase(table.name)}(scope?: string): Promise<TableRowsResult<${pascalCase(
`${camelCase(
table.name
)}(options?: GetTableRowsOptions): Promise<TableRowsResult<${pascalCase(
contractName
)}${pascalCase(table.name)}>>;`
);
Expand Down

0 comments on commit 8fdce04

Please sign in to comment.