Skip to content

Commit 2c755ba

Browse files
Merge pull request #428 from skywinder/master
2 parents 5e7ea0c + ff538e8 commit 2c755ba

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

Sources/web3swift/EthereumABI/ABIElements.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,40 @@ extension ABI.Element {
187187
case .fallback(_):
188188
return nil
189189
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
190224
if (data.count == 0 && function.outputs.count == 1) {
191225
let name = "0"
192226
let value = function.outputs[0].type.emptyValue
@@ -210,6 +244,8 @@ extension ABI.Element {
210244
}
211245
i = i + 1
212246
}
247+
// set a flag to detect the request succeeded
248+
returnArray["_success"] = true
213249
return returnArray
214250
case .receive(_):
215251
return nil

web3swift.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Pod::Spec.new do |spec|
22
spec.name = 'web3swift'
33
spec.version = '2.5.0'
44
spec.ios.deployment_target = "9.0"
5-
spec.osx.deployment_target = "10.11"
5+
spec.osx.deployment_target = "10.12"
66
spec.license = { :type => 'Apache License 2.0', :file => 'LICENSE.md' }
77
spec.summary = 'Web3 implementation in vanilla Swift for iOS, macOS, and Linux'
88
spec.homepage = 'https://github.com/matter-labs/web3swift'

0 commit comments

Comments
 (0)