You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// Decodes data returned by a function call. Able to decode `revert("...")` calls.
268
+
/// - Parameter data: bytes returned by a function call.
269
+
/// - Returns: a dictionary containing returned data mappend to indices and names of returned values if these are not `nil`.
270
+
/// Return cases:
271
+
/// - when no `outputs` declared: returning `["_success": true]`;
272
+
/// - when `outputs` declared and decoding completed successfully: returning `["_success": true, "0": value_1, "1": value_2, ...]`.
273
+
/// Additionally this dictionary will have mappings to output names if these names are specified in the ABI.
274
+
/// - function call was aborted using `require(some_string_error_message)`: returning `["_success": false, "_abortedByRequire": true, "_errorMessageFromRequire": error_message]`.
275
+
/// - in case of any error: returning `["_success": false, "_failureReason": String]`;
276
+
/// Error reasons include:
277
+
/// - `outputs` declared but at least one value failed to be decoded;
278
+
/// - `data.count` is less than `outputs.count * 32`;
NSLog("Function doesn't have any output types to decode given data.")
284
+
return["_success":true]
285
+
}
297
286
298
-
return returnArray
299
-
}
287
+
/// If data is empty and outputs are expected it is treated as a `requite(expression)` call with no message.
288
+
/// In solidity `require(expression)` call, if `expresison` returns `false`, results in an empty response.
289
+
if data.count ==0 && !outputs.isEmpty {
290
+
return["_success":false,"_failureReason":"Cannot decode empty data. \(outputs.count) outputs are expected: \(outputs.map{ $0.type.abiRepresentation }). Was this a result of en empty `require(expression)` call?"]
300
291
}
301
292
302
-
varreturnArray=[String: Any]()
293
+
guard outputs.count *32<= data.count else{
294
+
return["_success":false,"_failureReason":"Bytes count must be at least \(outputs.count *32). Given \(data.count). Decoding will fail."]
295
+
}
303
296
304
-
// the "require" statement with no message argument will be caught here
0 commit comments