Skip to content

Commit

Permalink
Comments and splitting logic a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
aaroncox committed Jul 24, 2023
1 parent 785a49f commit ede31bf
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/contract/table-cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,22 @@ export class TableCursor<RowType = any> {

const result = await this.client!.v1.chain.get_table_rows(query)

const rows =
// Determine if we need to decode the rows, based on if:
// - json parameter is false, meaning hex data will be returned
// - type parameter is not set, meaning the APIClient will not automatically decode
const requiresDecoding =
this.params.json === false && !(query as API.v1.GetTableRowsParamsTyped).type
? result.rows.map((row) =>
Serializer.decode({
data: row,
abi: this.abi,
type: this.type,
})
)
: result.rows

// Retrieve the rows from the result, decoding if needed
const rows: RowType[] = requiresDecoding
? result.rows.map((data) =>
Serializer.decode({
data,
abi: this.abi,
type: this.type,
})
)
: result.rows

this.next_key = result.next_key
this.rowsCount += rows.length
Expand Down

0 comments on commit ede31bf

Please sign in to comment.