Skip to content

Commit e9b53c0

Browse files
committed
Restore failing #440 PR
1 parent 5edab19 commit e9b53c0

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

Sources/web3swift/EthereumABI/ABIDecoding.swift

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,25 @@ extension ABIDecoder {
173173
let (v, c) = decodeSignleType(type: subTypes[i], data: elementItself, pointer: consumed)
174174
guard let valueUnwrapped = v, let consumedUnwrapped = c else {return (nil, nil)}
175175
toReturn.append(valueUnwrapped)
176-
consumed = consumed + consumedUnwrapped
176+
/*
177+
When decoding a tuple that is not static or an array with a subtype that is not static, the second value in the tuple returned by decodeSignleType is a pointer to the next element, NOT the length of the consumed element. So when decoding such an element, consumed should be set to consumedUnwrapped, NOT incremented by consumedUnwrapped.
178+
*/
179+
switch subTypes[i] {
180+
case .array(type: let subType, length: _):
181+
if !subType.isStatic {
182+
consumed = consumedUnwrapped
183+
} else {
184+
fallthrough
185+
}
186+
case .tuple(types: _):
187+
if !subTypes[i].isStatic {
188+
consumed = consumedUnwrapped
189+
} else {
190+
fallthrough
191+
}
192+
default:
193+
consumed = consumed + consumedUnwrapped
194+
}
177195
}
178196
// print("Tuple element is: \n" + String(describing: toReturn))
179197
if type.isStatic {

0 commit comments

Comments
 (0)