Skip to content

Commit 4ad1217

Browse files
Merge pull request #379 from izakpavel/fix/abi_tuples
fixed parsing of ABIs with tuples + wrong gas info when transactionOptions created from json
2 parents 2ae750b + a4919d5 commit 4ad1217

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

Sources/web3swift/EthereumABI/ABIDecoding.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,12 @@ extension ABIDecoder {
137137
let (v, c) = decodeSignleType(type: subType, data: dataSlice, pointer: subpointer)
138138
guard let valueUnwrapped = v, let consumedUnwrapped = c else {break}
139139
toReturn.append(valueUnwrapped)
140-
subpointer = subpointer + consumedUnwrapped
140+
if (subType.isStatic) {
141+
subpointer = subpointer + consumedUnwrapped
142+
}
143+
else {
144+
subpointer = consumedUnwrapped // need to go by nextElementPointer
145+
}
141146
}
142147
return (toReturn as AnyObject, nextElementPointer)
143148
}

Sources/web3swift/EthereumABI/ABIParameterTypes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ extension ABI.Element.ParameterType: ABIEncoding {
220220
case .tuple(types: let types):
221221
let typesRepresentation = types.map({return $0.abiRepresentation})
222222
let typesJoined = typesRepresentation.joined(separator: ",")
223-
return "tuple(\(typesJoined))"
223+
return "(\(typesJoined))"
224224
case .string:
225225
return "string"
226226
}

Sources/web3swift/EthereumABI/ABIParsing.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,17 @@ extension ABI.Input {
155155
let nativeInput = ABI.Element.InOut(name: name, type: type)
156156
return nativeInput
157157
}
158+
else if case .array(type: .tuple(types: _), length: _) = parameterType {
159+
let components = try self.components?.compactMap({ (inp: ABI.Input) throws -> ABI.Element.ParameterType in
160+
let input = try inp.parse()
161+
return input.type
162+
})
163+
let tupleType = ABI.Element.ParameterType.tuple(types: components!)
164+
165+
let newType: ABI.Element.ParameterType = .array(type: tupleType, length: 0)
166+
let nativeInput = ABI.Element.InOut(name: name, type: newType)
167+
return nativeInput
168+
}
158169
else {
159170
let nativeInput = ABI.Element.InOut(name: name, type: parameterType)
160171
return nativeInput

Sources/web3swift/Web3/Web3+Options.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public struct TransactionOptions {
125125
public static func fromJSON(_ json: [String: Any]) -> TransactionOptions? {
126126
var options = TransactionOptions()
127127
if let gas = json["gas"] as? String, let gasBiguint = BigUInt(gas.stripHexPrefix().lowercased(), radix: 16) {
128-
options.gasLimit = .limited(gasBiguint)
128+
options.gasLimit = .manual(gasBiguint)
129129
} else if let gasLimit = json["gasLimit"] as? String, let gasgasLimitBiguint = BigUInt(gasLimit.stripHexPrefix().lowercased(), radix: 16) {
130130
options.gasLimit = .limited(gasgasLimitBiguint)
131131
} else {

0 commit comments

Comments
 (0)