From c995bf64068ca4f328e403b4391a797e805460f5 Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Tue, 24 Jun 2025 15:16:19 +0100 Subject: [PATCH] refactor: dont use array index for components key --- src/Utils/AbiEncoder.php | 12 ++++++++---- tests/Unit/Utils/AbiEncoderTest.php | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) 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', ], ],