Skip to content

Commit

Permalink
fix: Fix ABI array/struct decoding (#956)
Browse files Browse the repository at this point in the history
* Update decoder.ts

* Update decoder.ts

* Update decoder.ts

* Update decoder.ts

* Update decoder.ts
  • Loading branch information
ludamad authored Jul 4, 2023
1 parent ba1a16d commit 404c3f8
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions yarn-project/acir-simulator/src/abi_coder/decoder.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { Fr } from '@aztec/foundation/fields';
import { ABIType, FunctionAbi } from '@aztec/foundation/abi';

/**
* The type of our decoded ABI.
*/
type DecodedReturn = bigint | boolean | DecodedReturn[] | { [key: string]: DecodedReturn };

/**
* Decodes return values from a function call.
* Missing support for integer and string.
Expand All @@ -13,7 +18,7 @@ class ReturnValuesDecoder {
* @param abiType - The type of the return value.
* @returns The decoded return value.
*/
private decodeReturn(abiType: ABIType): any {
private decodeReturn(abiType: ABIType): DecodedReturn {
switch (abiType.kind) {
case 'field':
return this.getNextField().value;
Expand All @@ -24,14 +29,14 @@ class ReturnValuesDecoder {
for (let i = 0; i < abiType.length; i += 1) {
array.push(this.decodeReturn(abiType.type));
}
break;
return array;
}
case 'struct': {
const struct: any = {};
const struct: { [key: string]: DecodedReturn } = {};
for (const field of abiType.fields) {
struct[field.name] = this.decodeReturn(field.type);
}
break;
return struct;
}
default:
throw new Error(`Unsupported type: ${abiType.kind}`);
Expand Down

0 comments on commit 404c3f8

Please sign in to comment.