Skip to content

Commit c995bf6

Browse files
committed
refactor: dont use array index for components key
1 parent 679cb0f commit c995bf6

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/Utils/AbiEncoder.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,17 +323,21 @@ private function encodeTuple($value, array $param): array
323323
{
324324
$dynamic = false;
325325
$preparedParams = [];
326-
// TODO: it currently relies on the ABI component arrays to have a string index but our DARK20 ABI doesn't seem to have that
327-
// https://app.clickup.com/t/86dx0at7u
328-
foreach ($param['components'] as $index => $component) {
329-
$key = is_array($value) ? $index : $component['name'];
326+
foreach ($param['components'] as $component) {
327+
if (! isset($component['name'])) {
328+
throw new Exception('Tuple component missing name');
329+
}
330+
331+
$key = $component['name'];
330332
if (! isset($value[$key])) {
331333
throw new Exception('Tuple value missing component: '.$component['name']);
332334
}
335+
333336
$preparedParam = $this->prepareParam($component, $value[$key]);
334337
if ($preparedParam['dynamic']) {
335338
$dynamic = true;
336339
}
340+
337341
$preparedParams[] = $preparedParam;
338342
}
339343
if ($dynamic) {

tests/Unit/Utils/AbiEncoderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,8 +620,8 @@ function testPrivateMethod(string $methodName, &$object): ReflectionMethod
620620
'name' => 'text',
621621
'type' => 'tuple',
622622
'components' => [
623-
'recipient' => [
624-
'name' => 'from',
623+
[
624+
'name' => 'recipient',
625625
'type' => 'string',
626626
],
627627
],

0 commit comments

Comments
 (0)