Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

complete EIP681, fix the most stupid Ethereum address parsing #33

Merged
merged 1 commit into from
Sep 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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