Skip to content

Commit

Permalink
Merge pull request #35 from matterinc/EIP681Improvement
Browse files Browse the repository at this point in the history
EIP681 bug fixes, accessibility in Function changed
  • Loading branch information
shamatar authored Sep 14, 2018
2 parents 94e6e5b + be426d6 commit 77ca638
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
16 changes: 8 additions & 8 deletions web3swift/ABIv2/Classes/ABIv2Elements.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation
import BigInt

extension ABIv2 {
public extension ABIv2 {
// JSON Decoding
public struct Input: Decodable {
var name: String?
Expand Down Expand Up @@ -48,16 +48,16 @@ extension ABIv2 {
case event(Event)

public struct InOut {
let name: String
let type: ParameterType
public let name: String
public let type: ParameterType
}

public struct Function {
let name: String?
let inputs: [InOut]
let outputs: [InOut]
let constant: Bool
let payable: Bool
public let name: String?
public let inputs: [InOut]
public let outputs: [InOut]
public let constant: Bool
public let payable: Bool
}

public struct Constructor {
Expand Down
18 changes: 17 additions & 1 deletion web3swift/Utils/Classes/EIP681.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ extension Web3 {

var code = EIP681Code(targetAddress)
if chainIDString != nil {
chainIDString!.remove(at: chainIDString!.startIndex)
code.chainID = BigUInt(chainIDString!)
}
if tail == nil {
Expand All @@ -137,7 +138,13 @@ extension Web3 {
switch inputType {
case .address:
let val = EIP681Code.TargetAddress(value)
nativeValue = val as AnyObject
switch val {
case .ethereumAddress(let ethereumAddress):
nativeValue = ethereumAddress as AnyObject
case .ensAddress(let ens):
//TODO: - convert ens into ethereum
nativeValue = ens as AnyObject
}
case .uint(bits: _):
if let val = BigUInt(value, radix: 10) {
nativeValue = val as AnyObject
Expand All @@ -164,6 +171,15 @@ extension Web3 {
} else if let val = value.data(using: .utf8) {
nativeValue = val as AnyObject
}
case .bool:
switch value {
case "true","True","1":
nativeValue = true as AnyObject
case "false", "False", "0":
nativeValue = false as AnyObject
default:
nativeValue = true as AnyObject
}
default:
continue
}
Expand Down

0 comments on commit 77ca638

Please sign in to comment.