@@ -187,6 +187,40 @@ extension ABI.Element {
187
187
case . fallback( _) :
188
188
return nil
189
189
case . function( let function) :
190
+ // the response size greater than equal 100 bytes, when read function aborted by "require" statement.
191
+ // if "require" statement has no message argument, the response is empty (0 byte).
192
+ if ( data. bytes. count >= 100 ) {
193
+ let check00_31 = BigUInt ( " 08C379A000000000000000000000000000000000000000000000000000000000 " , radix: 16 ) !
194
+ let check32_63 = BigUInt ( " 0000002000000000000000000000000000000000000000000000000000000000 " , radix: 16 ) !
195
+
196
+ // check data[00-31] and data[32-63]
197
+ if check00_31 == BigUInt ( data [ 0 ... 31 ] ) && check32_63 == BigUInt ( data [ 32 ... 63 ] ) {
198
+ // data.bytes[64-67] contains the length of require message
199
+ let len = ( Int ( data. bytes [ 64 ] ) <<24 ) | ( Int ( data. bytes [ 65 ] ) <<16 ) | ( Int ( data. bytes [ 66 ] ) <<8 ) | Int ( data. bytes [ 67 ] )
200
+
201
+ let message = String ( bytes: data. bytes [ 68 ..< ( 68 + len) ] , encoding: . utf8 ) !
202
+
203
+ print ( " read function aborted by require statement: \( message) " )
204
+
205
+ var returnArray = [ String: Any] ( )
206
+
207
+ // set infomation
208
+ returnArray [ " _abortedByRequire " ] = true
209
+ returnArray [ " _errorMessageFromRequire " ] = message
210
+
211
+ // set empty values
212
+ for i in 0 ..< function. outputs. count {
213
+ let name = " \( i) "
214
+ returnArray [ name] = function. outputs [ i] . type. emptyValue
215
+ if function. outputs [ i] . name != " " {
216
+ returnArray [ function. outputs [ i] . name] = function. outputs [ i] . type. emptyValue
217
+ }
218
+ }
219
+
220
+ return returnArray
221
+ }
222
+ }
223
+ // the "require" statement with no message argument will be caught here
190
224
if ( data. count == 0 && function. outputs. count == 1 ) {
191
225
let name = " 0 "
192
226
let value = function. outputs [ 0 ] . type. emptyValue
@@ -210,6 +244,8 @@ extension ABI.Element {
210
244
}
211
245
i = i + 1
212
246
}
247
+ // set a flag to detect the request succeeded
248
+ returnArray [ " _success " ] = true
213
249
return returnArray
214
250
case . receive( _) :
215
251
return nil
0 commit comments