diff --git a/src/Utils/AbiEncoder.php b/src/Utils/AbiEncoder.php index c0aa068..a1a854b 100644 --- a/src/Utils/AbiEncoder.php +++ b/src/Utils/AbiEncoder.php @@ -323,17 +323,21 @@ private function encodeTuple($value, array $param): array { $dynamic = false; $preparedParams = []; - // TODO: it currently relies on the ABI component arrays to have a string index but our DARK20 ABI doesn't seem to have that - // https://app.clickup.com/t/86dx0at7u - foreach ($param['components'] as $index => $component) { - $key = is_array($value) ? $index : $component['name']; + foreach ($param['components'] as $component) { + if (! isset($component['name'])) { + throw new Exception('Tuple component missing name'); + } + + $key = $component['name']; if (! isset($value[$key])) { throw new Exception('Tuple value missing component: '.$component['name']); } + $preparedParam = $this->prepareParam($component, $value[$key]); if ($preparedParam['dynamic']) { $dynamic = true; } + $preparedParams[] = $preparedParam; } if ($dynamic) { diff --git a/tests/Unit/Utils/AbiEncoderTest.php b/tests/Unit/Utils/AbiEncoderTest.php index 173f1ed..e812741 100644 --- a/tests/Unit/Utils/AbiEncoderTest.php +++ b/tests/Unit/Utils/AbiEncoderTest.php @@ -620,8 +620,8 @@ function testPrivateMethod(string $methodName, &$object): ReflectionMethod 'name' => 'text', 'type' => 'tuple', 'components' => [ - 'recipient' => [ - 'name' => 'from', + [ + 'name' => 'recipient', 'type' => 'string', ], ],