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
NSLog("Function doesn't have any output types to decode given data.")
284
-
return["_success":true]
285
-
}
286
-
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?"]
291
-
}
292
-
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
-
}
296
-
297
282
/// How `require(expression, string)` return value is decomposed:
298
283
/// - `08C379A0` function selector for Error(string);
299
284
/// - next 32 bytes are the data offset;
300
285
/// - next 32 bytes are the error message length;
301
286
/// - the next N bytes, where N is the int value
302
287
///
303
288
/// Data offset must be present. Hexadecimal value of `0000...0020` is 32 in decimal. Reasoning for `BigInt(...) == 32`.
304
-
ifdata[0..<4]==Data.fromHex("08C379A0"),
305
-
data.bytes.count >=100,
289
+
if data.bytes.count >=100,
290
+
data[0..<4]==Data.fromHex("08C379A0"),
306
291
BigInt(data[4..<36])==32,
307
292
let messageLength =Int(Data(data[36..<68]).toHexString(), radix:16),
308
293
let message =String(bytes: data.bytes[68..<(68+messageLength)], encoding:.utf8){
NSLog("Function doesn't have any output types to decode given data.")
312
+
return["_success":true]
313
+
}
314
+
315
+
/// If data is empty and outputs are expected it is treated as a `requite(expression)` call with no message.
316
+
/// In solidity `require(expression)` call, if `expresison` returns `false`, results in an empty response.
317
+
if data.count ==0 && !outputs.isEmpty {
318
+
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?"]
319
+
}
320
+
321
+
guard outputs.count *32<= data.count else{
322
+
return["_success":false,"_failureReason":"Bytes count must be at least \(outputs.count *32). Given \(data.count). Decoding will fail."]
323
+
}
324
+
325
325
// TODO: need improvement - we should be able to tell which value failed to be decoded
0 commit comments