Skip to content

Commit 77ca638

Browse files
authored
Merge pull request #35 from matterinc/EIP681Improvement
EIP681 bug fixes, accessibility in Function changed
2 parents 94e6e5b + be426d6 commit 77ca638

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

web3swift/ABIv2/Classes/ABIv2Elements.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import Foundation
1010
import BigInt
1111

12-
extension ABIv2 {
12+
public extension ABIv2 {
1313
// JSON Decoding
1414
public struct Input: Decodable {
1515
var name: String?
@@ -48,16 +48,16 @@ extension ABIv2 {
4848
case event(Event)
4949

5050
public struct InOut {
51-
let name: String
52-
let type: ParameterType
51+
public let name: String
52+
public let type: ParameterType
5353
}
5454

5555
public struct Function {
56-
let name: String?
57-
let inputs: [InOut]
58-
let outputs: [InOut]
59-
let constant: Bool
60-
let payable: Bool
56+
public let name: String?
57+
public let inputs: [InOut]
58+
public let outputs: [InOut]
59+
public let constant: Bool
60+
public let payable: Bool
6161
}
6262

6363
public struct Constructor {

web3swift/Utils/Classes/EIP681.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ extension Web3 {
116116

117117
var code = EIP681Code(targetAddress)
118118
if chainIDString != nil {
119+
chainIDString!.remove(at: chainIDString!.startIndex)
119120
code.chainID = BigUInt(chainIDString!)
120121
}
121122
if tail == nil {
@@ -137,7 +138,13 @@ extension Web3 {
137138
switch inputType {
138139
case .address:
139140
let val = EIP681Code.TargetAddress(value)
140-
nativeValue = val as AnyObject
141+
switch val {
142+
case .ethereumAddress(let ethereumAddress):
143+
nativeValue = ethereumAddress as AnyObject
144+
case .ensAddress(let ens):
145+
//TODO: - convert ens into ethereum
146+
nativeValue = ens as AnyObject
147+
}
141148
case .uint(bits: _):
142149
if let val = BigUInt(value, radix: 10) {
143150
nativeValue = val as AnyObject
@@ -164,6 +171,15 @@ extension Web3 {
164171
} else if let val = value.data(using: .utf8) {
165172
nativeValue = val as AnyObject
166173
}
174+
case .bool:
175+
switch value {
176+
case "true","True","1":
177+
nativeValue = true as AnyObject
178+
case "false", "False", "0":
179+
nativeValue = false as AnyObject
180+
default:
181+
nativeValue = true as AnyObject
182+
}
167183
default:
168184
continue
169185
}

0 commit comments

Comments
 (0)