From ede31bfd05b00139969f82b06968d98b204b2f12 Mon Sep 17 00:00:00 2001 From: Aaron Cox Date: Mon, 24 Jul 2023 15:09:35 -0700 Subject: [PATCH] Comments and splitting logic a bit --- src/contract/table-cursor.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/contract/table-cursor.ts b/src/contract/table-cursor.ts index 3da630c..42879f3 100644 --- a/src/contract/table-cursor.ts +++ b/src/contract/table-cursor.ts @@ -82,16 +82,22 @@ export class TableCursor { 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