@@ -175,6 +175,40 @@ extension ABI.Element {
175
175
case . fallback( _) :
176
176
return nil
177
177
case . function( let function) :
178
+ // the response size greater than equal 100 bytes, when read function aborted by "require" statement.
179
+ // if "require" statement has no message argument, the response is empty (0 byte).
180
+ if ( data. bytes. count >= 100 ) {
181
+ let check00_31 = BigUInt ( " 08C379A000000000000000000000000000000000000000000000000000000000 " , radix: 16 ) !
182
+ let check32_63 = BigUInt ( " 0000002000000000000000000000000000000000000000000000000000000000 " , radix: 16 ) !
183
+
184
+ // check data[00-31] and data[32-63]
185
+ if check00_31 == BigUInt ( data [ 0 ... 31 ] ) && check32_63 == BigUInt ( data [ 32 ... 63 ] ) {
186
+ // data.bytes[64-67] contains the length of require message
187
+ let len = ( Int ( data. bytes [ 64 ] ) <<24 ) | ( Int ( data. bytes [ 65 ] ) <<16 ) | ( Int ( data. bytes [ 66 ] ) <<8 ) | Int ( data. bytes [ 67 ] )
188
+
189
+ let message = String ( bytes: data. bytes [ 68 ..< ( 68 + len) ] , encoding: . utf8 ) !
190
+
191
+ print ( " read function aborted by require statement: \( message) " )
192
+
193
+ var returnArray = [ String: Any] ( )
194
+
195
+ // set infomation
196
+ returnArray [ " _abortedByRequire " ] = true
197
+ returnArray [ " _errorMessageFromRequire " ] = message
198
+
199
+ // set empty values
200
+ for i in 0 ..< function. outputs. count {
201
+ let name = " \( i) "
202
+ returnArray [ name] = function. outputs [ i] . type. emptyValue
203
+ if function. outputs [ i] . name != " " {
204
+ returnArray [ function. outputs [ i] . name] = function. outputs [ i] . type. emptyValue
205
+ }
206
+ }
207
+
208
+ return returnArray
209
+ }
210
+ }
211
+ // the "require" statement with no message argument will be caught here
178
212
if ( data. count == 0 && function. outputs. count == 1 ) {
179
213
let name = " 0 "
180
214
let value = function. outputs [ 0 ] . type. emptyValue
@@ -198,6 +232,8 @@ extension ABI.Element {
198
232
}
199
233
i = i + 1
200
234
}
235
+ // set a flag to detect the request succeeded
236
+ returnArray [ " _success " ] = true
201
237
return returnArray
202
238
}
203
239
}
0 commit comments