Skip to content

Commit

Permalink
Merge pull request #33 from matterinc/develop
Browse files Browse the repository at this point in the history
complete EIP681, fix the most stupid Ethereum address parsing
  • Loading branch information
shamatar authored Sep 13, 2018
2 parents 2aa2bf7 + 629116b commit f1f2e09
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
2 changes: 2 additions & 0 deletions web3swift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
81C0FD052044A8AE00D82FAF /* Web3+Protocols.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81C0FCF120440EB500D82FAF /* Web3+Protocols.swift */; };
81C0FD062044A8D100D82FAF /* TransactionSigner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81C0FCF520440F9900D82FAF /* TransactionSigner.swift */; };
81C146F71FF274B200AA943E /* Web3+Structures.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81C146F61FF274B200AA943E /* Web3+Structures.swift */; };
81C456FE214A54D50091FF45 /* key.json in Resources */ = {isa = PBXBuildFile; fileRef = 8159C50F2135929700197B91 /* key.json */; };
81C5DA0E207254D000424CD6 /* ABIv2Elements.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81C5DA0D207254D000424CD6 /* ABIv2Elements.swift */; };
81C5DA0F207254D000424CD6 /* ABIv2Elements.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81C5DA0D207254D000424CD6 /* ABIv2Elements.swift */; };
81C5DA11207254F600424CD6 /* ABIv2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81C5DA10207254F600424CD6 /* ABIv2.swift */; };
Expand Down Expand Up @@ -1009,6 +1010,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
81C456FE214A54D50091FF45 /* key.json in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
5 changes: 4 additions & 1 deletion web3swift/KeystoreManager/Classes/EthereumAddress.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,11 @@ public struct EthereumAddress: Equatable {
self.type = .normal
return
}
} else {
self._address = data.toHexString().addHexPrefix()
self.type = .normal
return
}
return nil
case .contractDeployment:
self._address = "0x"
self.type = .contractDeployment
Expand Down
22 changes: 22 additions & 0 deletions web3swift/Utils/Classes/EIP681.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,35 @@ extension Web3 {
} else if let val = BigUInt(value.stripHexPrefix(), radix: 16) {
nativeValue = val as AnyObject
}
case .int(bits: _):
if let val = BigInt(value, radix: 10) {
nativeValue = val as AnyObject
} else if let val = BigInt(value.stripHexPrefix(), radix: 16) {
nativeValue = val as AnyObject
}
case .string:
nativeValue = value as AnyObject
case .dynamicBytes:
if let val = Data.fromHex(value) {
nativeValue = val as AnyObject
} else if let val = value.data(using: .utf8) {
nativeValue = val as AnyObject
}
case .bytes(length: _):
if let val = Data.fromHex(value) {
nativeValue = val as AnyObject
} else if let val = value.data(using: .utf8) {
nativeValue = val as AnyObject
}
default:
continue
}
if nativeValue != nil {
inputs.append(ABIv2.Element.InOut(name: String(inputNumber), type: inputType))
code.parameters.append(EIP681Code.EIP681Parameter(type: inputType, value: nativeValue!))
inputNumber = inputNumber + 1
} else {
return nil
}
} else {
switch comp.name {
Expand Down
5 changes: 5 additions & 0 deletions web3swiftTests/web3swift_local_node_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ class web3swift_local_node_Tests: XCTestCase {
}
}

func testGetNodeAccounts() {
let web3 = Web3.new(URL.init(string: "http://127.0.0.1:8545")!)!
guard case .success(let allAddresses) = web3.eth.getAccounts() else {return XCTFail()}
print(allAddresses)
}



Expand Down

0 comments on commit f1f2e09

Please sign in to comment.