From 936f0b8671f87cae6b03e2971b60466cfc7e9ae8 Mon Sep 17 00:00:00 2001 From: lukasaric Date: Fri, 13 Sep 2024 17:24:25 +0200 Subject: [PATCH] chore: add js docs example --- src/utils/calldata/requestParser.ts | 42 +++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/utils/calldata/requestParser.ts b/src/utils/calldata/requestParser.ts index 0587b268a..203b17ba4 100644 --- a/src/utils/calldata/requestParser.ts +++ b/src/utils/calldata/requestParser.ts @@ -283,6 +283,48 @@ function parseCalldataValue( * @param structs - structs from abi * @param enums - enums from abi * @return {string | string[]} - parsed arguments in format that contract is expecting + * + * @example + * const abiEntry = { name: 'test', type: 'struct' }; + * const abiStructs: AbiStructs = { + * struct: { + * members: [ + * { + * name: 'test_name', + * type: 'test_type', + * offset: 1, + * }, + * ], + * size: 2, + * name: 'cairo__struct', + * type: 'struct', + * }, + * }; + * + * const abiEnums: AbiEnums = { + * enum: { + * variants: [ + * { + * name: 'test_name', + * type: 'cairo_struct_variant', + * offset: 1, + * }, + * ], + * size: 2, + * name: 'test_cairo', + * type: 'enum', + * }, + * }; + * + * const args = [{ test_name: 'test' }]; + * const argsIterator = args[Symbol.iterator](); + * const parsedField = parseCalldataField( + * argsIterator, + * abiEntry, + * abiStructs, + * abiEnums + * ); + * // parsedField === ['1952805748'] */ export function parseCalldataField( argsIterator: Iterator,