Skip to content

Commit f1f2e09

Browse files
authored
Merge pull request #33 from matterinc/develop
complete EIP681, fix the most stupid Ethereum address parsing
2 parents 2aa2bf7 + 629116b commit f1f2e09

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

web3swift.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@
150150
81C0FD052044A8AE00D82FAF /* Web3+Protocols.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81C0FCF120440EB500D82FAF /* Web3+Protocols.swift */; };
151151
81C0FD062044A8D100D82FAF /* TransactionSigner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81C0FCF520440F9900D82FAF /* TransactionSigner.swift */; };
152152
81C146F71FF274B200AA943E /* Web3+Structures.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81C146F61FF274B200AA943E /* Web3+Structures.swift */; };
153+
81C456FE214A54D50091FF45 /* key.json in Resources */ = {isa = PBXBuildFile; fileRef = 8159C50F2135929700197B91 /* key.json */; };
153154
81C5DA0E207254D000424CD6 /* ABIv2Elements.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81C5DA0D207254D000424CD6 /* ABIv2Elements.swift */; };
154155
81C5DA0F207254D000424CD6 /* ABIv2Elements.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81C5DA0D207254D000424CD6 /* ABIv2Elements.swift */; };
155156
81C5DA11207254F600424CD6 /* ABIv2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81C5DA10207254F600424CD6 /* ABIv2.swift */; };
@@ -1009,6 +1010,7 @@
10091010
isa = PBXResourcesBuildPhase;
10101011
buildActionMask = 2147483647;
10111012
files = (
1013+
81C456FE214A54D50091FF45 /* key.json in Resources */,
10121014
);
10131015
runOnlyForDeploymentPostprocessing = 0;
10141016
};

web3swift/KeystoreManager/Classes/EthereumAddress.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,11 @@ public struct EthereumAddress: Equatable {
100100
self.type = .normal
101101
return
102102
}
103+
} else {
104+
self._address = data.toHexString().addHexPrefix()
105+
self.type = .normal
106+
return
103107
}
104-
return nil
105108
case .contractDeployment:
106109
self._address = "0x"
107110
self.type = .contractDeployment

web3swift/Utils/Classes/EIP681.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,35 @@ extension Web3 {
144144
} else if let val = BigUInt(value.stripHexPrefix(), radix: 16) {
145145
nativeValue = val as AnyObject
146146
}
147+
case .int(bits: _):
148+
if let val = BigInt(value, radix: 10) {
149+
nativeValue = val as AnyObject
150+
} else if let val = BigInt(value.stripHexPrefix(), radix: 16) {
151+
nativeValue = val as AnyObject
152+
}
153+
case .string:
154+
nativeValue = value as AnyObject
155+
case .dynamicBytes:
156+
if let val = Data.fromHex(value) {
157+
nativeValue = val as AnyObject
158+
} else if let val = value.data(using: .utf8) {
159+
nativeValue = val as AnyObject
160+
}
161+
case .bytes(length: _):
162+
if let val = Data.fromHex(value) {
163+
nativeValue = val as AnyObject
164+
} else if let val = value.data(using: .utf8) {
165+
nativeValue = val as AnyObject
166+
}
147167
default:
148168
continue
149169
}
150170
if nativeValue != nil {
151171
inputs.append(ABIv2.Element.InOut(name: String(inputNumber), type: inputType))
152172
code.parameters.append(EIP681Code.EIP681Parameter(type: inputType, value: nativeValue!))
153173
inputNumber = inputNumber + 1
174+
} else {
175+
return nil
154176
}
155177
} else {
156178
switch comp.name {

web3swiftTests/web3swift_local_node_Tests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ class web3swift_local_node_Tests: XCTestCase {
7171
}
7272
}
7373

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

7580

7681

0 commit comments

Comments
 (0)