Skip to content
This repository was archived by the owner on Sep 13, 2024. It is now read-only.

Commit 621a172

Browse files
committed
Added txpool #222
1 parent 5ca0e52 commit 621a172

File tree

15 files changed

+498
-37
lines changed

15 files changed

+498
-37
lines changed

web3swift.xcodeproj/project.pbxproj

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@
3434
13A24E52216365A4004C48A0 /* EthURL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13A24E50216365A4004C48A0 /* EthURL.swift */; };
3535
13A24EE7216F988C004C48A0 /* UInt256.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13A24EE6216F988C004C48A0 /* UInt256.swift */; };
3636
13A24EE8216F9899004C48A0 /* UInt256.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13A24EE6216F988C004C48A0 /* UInt256.swift */; };
37+
13A691612185B7AC00F2D9A9 /* TxPool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13A691602185B7AC00F2D9A9 /* TxPool.swift */; };
38+
13A691672185CA6300F2D9A9 /* DictionaryReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13A691662185CA6300F2D9A9 /* DictionaryReader.swift */; };
39+
13A6916921860A1900F2D9A9 /* DecoderExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13A6916821860A1900F2D9A9 /* DecoderExtensions.swift */; };
40+
13A6916A21860A1B00F2D9A9 /* DecoderExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13A6916821860A1900F2D9A9 /* DecoderExtensions.swift */; };
41+
13A6916B21860A1D00F2D9A9 /* DictionaryReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13A691662185CA6300F2D9A9 /* DictionaryReader.swift */; };
42+
13A6916C21860A1F00F2D9A9 /* TxPool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13A691602185B7AC00F2D9A9 /* TxPool.swift */; };
43+
13A6916D21860F3100F2D9A9 /* TxPoolTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13A691622185B90000F2D9A9 /* TxPoolTests.swift */; };
3744
13FD60DF21821A1100D73D4E /* SolidityFunctionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13FD60DE21821A1100D73D4E /* SolidityFunctionTests.swift */; };
3845
13FD60F521822FAE00D73D4E /* SolidityDataWriter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13FD60F421822FAE00D73D4E /* SolidityDataWriter.swift */; };
3946
13FD60F621822FAE00D73D4E /* SolidityDataWriter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13FD60F421822FAE00D73D4E /* SolidityDataWriter.swift */; };
@@ -265,6 +272,10 @@
265272
134B10CE2182447600113663 /* Int+Sequence.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Int+Sequence.swift"; sourceTree = "<group>"; };
266273
13A24E50216365A4004C48A0 /* EthURL.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EthURL.swift; sourceTree = "<group>"; };
267274
13A24EE6216F988C004C48A0 /* UInt256.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UInt256.swift; sourceTree = "<group>"; };
275+
13A691602185B7AC00F2D9A9 /* TxPool.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TxPool.swift; sourceTree = "<group>"; };
276+
13A691622185B90000F2D9A9 /* TxPoolTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TxPoolTests.swift; sourceTree = "<group>"; };
277+
13A691662185CA6300F2D9A9 /* DictionaryReader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DictionaryReader.swift; sourceTree = "<group>"; };
278+
13A6916821860A1900F2D9A9 /* DecoderExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DecoderExtensions.swift; sourceTree = "<group>"; };
268279
13FD60DE21821A1100D73D4E /* SolidityFunctionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SolidityFunctionTests.swift; sourceTree = "<group>"; };
269280
13FD60F421822FAE00D73D4E /* SolidityDataWriter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SolidityDataWriter.swift; sourceTree = "<group>"; };
270281
1CD91AFC1FD76910007BFB45 /* web3swift_iOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = web3swift_iOS.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -465,12 +476,14 @@
465476
path = Contracts;
466477
sourceTree = "<group>";
467478
};
468-
13FD60F321822F9700D73D4E /* DataManagers */ = {
479+
13A6915F2185B78E00F2D9A9 /* TxPool */ = {
469480
isa = PBXGroup;
470481
children = (
471-
13FD60F421822FAE00D73D4E /* SolidityDataWriter.swift */,
482+
13A691602185B7AC00F2D9A9 /* TxPool.swift */,
483+
13A691662185CA6300F2D9A9 /* DictionaryReader.swift */,
484+
13A6916821860A1900F2D9A9 /* DecoderExtensions.swift */,
472485
);
473-
path = DataManagers;
486+
path = TxPool;
474487
sourceTree = "<group>";
475488
};
476489
1CD91AF21FD76910007BFB45 = {
@@ -500,7 +513,7 @@
500513
1CD91AFE1FD76910007BFB45 /* web3swift */ = {
501514
isa = PBXGroup;
502515
children = (
503-
13FD60F321822F9700D73D4E /* DataManagers */,
516+
13A6915F2185B78E00F2D9A9 /* TxPool */,
504517
13A24EDF216E4BF5004C48A0 /* Contracts */,
505518
13A24E4F21636541004C48A0 /* EthURL */,
506519
81FECD43211ADE20006DA367 /* ObjectiveCbridge */,
@@ -546,6 +559,7 @@
546559
E23B5AE220EA69B900DC7F32 /* NumberFormattingUtilTests.swift */,
547560
E23B5AE420EA6A0A00DC7F32 /* ContractV2Tests.swift */,
548561
1323B7F32174BB1E00306BBB /* Support.swift */,
562+
13A691622185B90000F2D9A9 /* TxPoolTests.swift */,
549563
1CD91B331FD769A6007BFB45 /* Info.plist */,
550564
);
551565
path = web3swiftTests;
@@ -684,6 +698,7 @@
684698
81C5DA2A2074CA1400424CD6 /* ABIv2Decoding.swift */,
685699
1323B7F62176255900306BBB /* SolidityTypes.swift */,
686700
1323B7AC2170E1ED00306BBB /* SolidityFunction.swift */,
701+
13FD60F421822FAE00D73D4E /* SolidityDataWriter.swift */,
687702
);
688703
path = ABIv2;
689704
sourceTree = "<group>";
@@ -1038,11 +1053,13 @@
10381053
8113D2CA1FD7E1590074282C /* KeystoreManager.swift in Sources */,
10391054
817EBB1F2006265400E02EAA /* Base58.swift in Sources */,
10401055
817EBB2520066E2B00E02EAA /* AbstractKeystore.swift in Sources */,
1056+
13A691612185B7AC00F2D9A9 /* TxPool.swift in Sources */,
10411057
81C0FCF720441A1D00D82FAF /* TransactionSigner.swift in Sources */,
10421058
8125F06920499AC300A0F2FE /* BloomFilter.swift in Sources */,
10431059
810B0F9A1FEC446B00CF0DA2 /* Web3+JSONRPC.swift in Sources */,
10441060
81195AB020D7FF8500ABC6B1 /* Promise+Web3+Contract+GetIndexedEvents.swift in Sources */,
10451061
1323B8052177B85F00306BBB /* ERC721.swift in Sources */,
1062+
13A6916921860A1900F2D9A9 /* DecoderExtensions.swift in Sources */,
10461063
8113D2C61FD7E1590074282C /* LibSecp256k1Extension.swift in Sources */,
10471064
81EB1E4B208173D7003BD47F /* Web3+Personal.swift in Sources */,
10481065
81A1824B20D7DF1B0016741F /* Promise+Web3+Personal+UnlockAccount.swift in Sources */,
@@ -1055,6 +1072,7 @@
10551072
81C5DA252072E14E00424CD6 /* ABIv2Encoding.swift in Sources */,
10561073
81A1824220D7AA750016741F /* Promise+Web3+Eth+SendTransaction.swift in Sources */,
10571074
817EBB2920075D2E00E02EAA /* BIP39.swift in Sources */,
1075+
13A691672185CA6300F2D9A9 /* DictionaryReader.swift in Sources */,
10581076
81FECD49211ADEB1006DA367 /* Web3+Instance+ObjC.swift in Sources */,
10591077
815630022007B53C00A0EC2F /* BIP32Keystore.swift in Sources */,
10601078
818ABD5B1FE95F8F002657BB /* Web3+Instance.swift in Sources */,
@@ -1146,6 +1164,7 @@
11461164
81A1821D20D5C6C10016741F /* PromiseTests.swift in Sources */,
11471165
81FECD5E211AEFCE006DA367 /* ObjectiveCTests.swift in Sources */,
11481166
E23B5ADD20EA685D00DC7F32 /* EIP67Tests.swift in Sources */,
1167+
13A6916D21860F3100F2D9A9 /* TxPoolTests.swift in Sources */,
11491168
00E5FE8220EA3FF40030E0D6 /* InfuraTests.swift in Sources */,
11501169
1CD91B321FD769A6007BFB45 /* MainTests.swift in Sources */,
11511170
E23B5ADF20EA68FA00DC7F32 /* SECP256K1Tests.swift in Sources */,
@@ -1163,6 +1182,7 @@
11631182
4194811E203630530065A83B /* Web3.swift in Sources */,
11641183
134B10D02182447600113663 /* Int+Sequence.swift in Sources */,
11651184
4194811F203630530065A83B /* Web3+Instance.swift in Sources */,
1185+
13A6916C21860A1F00F2D9A9 /* TxPool.swift in Sources */,
11661186
41948120203630530065A83B /* Web3+Contract.swift in Sources */,
11671187
41948121203630530065A83B /* Web3+Utils.swift in Sources */,
11681188
8125F06A20499AC300A0F2FE /* BloomFilter.swift in Sources */,
@@ -1173,6 +1193,7 @@
11731193
1323B8062177B85F00306BBB /* ERC721.swift in Sources */,
11741194
41948125203630530065A83B /* Web3+Methods.swift in Sources */,
11751195
81EB1E4C208173D7003BD47F /* Web3+Personal.swift in Sources */,
1196+
13A6916B21860A1D00F2D9A9 /* DictionaryReader.swift in Sources */,
11761197
81FECD4D211ADF70006DA367 /* Web3+HttpProvider+ObjC.swift in Sources */,
11771198
81D7D97620A3240900A193EC /* EthereumFilterEncodingExtensions.swift in Sources */,
11781199
41948126203630530065A83B /* Web3+Eth.swift in Sources */,
@@ -1201,6 +1222,7 @@
12011222
8160E5CF20B8245A0070070B /* IBAN.swift in Sources */,
12021223
41948131203630530065A83B /* BIP32KeystoreJSONStructure.swift in Sources */,
12031224
41948132203630530065A83B /* BIP32HDNode.swift in Sources */,
1225+
13A6916A21860A1B00F2D9A9 /* DecoderExtensions.swift in Sources */,
12041226
81A1824920D7DDA20016741F /* Promise+Web3+Personal+Sign.swift in Sources */,
12051227
81A1822620D678590016741F /* Promise+Web3+Eth+GetGasPrice.swift in Sources */,
12061228
13A24E52216365A4004C48A0 /* EthURL.swift in Sources */,
@@ -1421,6 +1443,7 @@
14211443
DYLIB_INSTALL_NAME_BASE = "@rpath";
14221444
ENABLE_BITCODE = YES;
14231445
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
1446+
GCC_GENERATE_TEST_COVERAGE_FILES = NO;
14241447
HEADER_SEARCH_PATHS = "$(inherited)";
14251448
INFOPLIST_FILE = web3swift/Info.plist;
14261449
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
@@ -1460,6 +1483,7 @@
14601483
DYLIB_INSTALL_NAME_BASE = "@rpath";
14611484
ENABLE_BITCODE = YES;
14621485
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
1486+
GCC_GENERATE_TEST_COVERAGE_FILES = NO;
14631487
HEADER_SEARCH_PATHS = "$(inherited)";
14641488
INFOPLIST_FILE = web3swift/Info.plist;
14651489
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";

web3swift.xcodeproj/xcshareddata/xcschemes/web3swift-iOS.xcscheme

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
codeCoverageEnabled = "YES"
2930
shouldUseLaunchSchemeArgsEnv = "YES">
3031
<Testables>
3132
<TestableReference
File renamed without changes.

web3swift/ABIv2/SolidityTypes.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ public enum ArraySize { // bytes for convenience
3434
case notArray
3535
}
3636

37-
private extension String {
38-
subscript(range: PartialRangeUpTo<Int>) -> Substring {
39-
return self[..<self.index(self.startIndex, offsetBy: range.upperBound)]
40-
}
41-
}
42-
4337
public class SolidityType: Equatable, CustomStringConvertible {
4438
public var isStatic: Bool { return true }
4539
public var isArray: Bool { return false }

web3swift/Convenience/String+Extension.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@
88

99
import Foundation
1010

11+
extension String {
12+
subscript(range: PartialRangeUpTo<Int>) -> Substring {
13+
return self[..<index(range.upperBound)]
14+
}
15+
@inline(__always)
16+
func index(_ i: Int) -> String.Index {
17+
return index(startIndex, offsetBy: i)
18+
}
19+
}
20+
1121
extension String {
1222
public func keccak256() -> Data {
1323
return data.keccak256()

web3swift/KeystoreManager/EthereumAddress.swift

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

12+
public enum AddressError: Error {
13+
case invalidAddress(String)
14+
}
15+
1216
public struct EthereumAddress: Equatable {
1317
public enum AddressType {
1418
case normal
@@ -88,6 +92,9 @@ public struct EthereumAddress: Equatable {
8892
_address = addressData.toHexString().withHex
8993
self.type = type
9094
}
95+
public func check() throws {
96+
guard isValid else { throw AddressError.invalidAddress(_address) }
97+
}
9198

9299
public static var contractDeployment: EthereumAddress {
93100
return EthereumAddress("0x", type: .contractDeployment)
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
//
2+
// DecoderExtensions.swift
3+
// web3swift-iOS
4+
//
5+
// Created by Dmitry on 28/10/2018.
6+
// Copyright © 2018 Bankex Foundation. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
// Inspired by https://gist.github.com/mbuchetics/c9bc6c22033014aa0c550d3b4324411a
12+
13+
struct JSONCodingKeys: CodingKey {
14+
var stringValue: String
15+
16+
init?(stringValue: String) {
17+
self.stringValue = stringValue
18+
}
19+
20+
var intValue: Int?
21+
22+
init?(intValue: Int) {
23+
self.init(stringValue: "\(intValue)")
24+
self.intValue = intValue
25+
}
26+
}
27+
28+
29+
extension KeyedDecodingContainer {
30+
31+
func decode(_ type: Dictionary<String, Any>.Type, forKey key: K) throws -> Dictionary<String, Any> {
32+
let container = try self.nestedContainer(keyedBy: JSONCodingKeys.self, forKey: key)
33+
return try container.decode(type)
34+
}
35+
36+
func decodeIfPresent(_ type: Dictionary<String, Any>.Type, forKey key: K) throws -> Dictionary<String, Any>? {
37+
guard contains(key) else {
38+
return nil
39+
}
40+
return try decode(type, forKey: key)
41+
}
42+
43+
func decode(_ type: Array<Any>.Type, forKey key: K) throws -> Array<Any> {
44+
var container = try self.nestedUnkeyedContainer(forKey: key)
45+
return try container.decode(type)
46+
}
47+
48+
func decodeIfPresent(_ type: Array<Any>.Type, forKey key: K) throws -> Array<Any>? {
49+
guard contains(key) else {
50+
return nil
51+
}
52+
return try decode(type, forKey: key)
53+
}
54+
55+
func decode(_ type: Dictionary<String, Any>.Type) throws -> Dictionary<String, Any> {
56+
var dictionary = Dictionary<String, Any>()
57+
58+
for key in allKeys {
59+
if let boolValue = try? decode(Bool.self, forKey: key) {
60+
dictionary[key.stringValue] = boolValue
61+
} else if let stringValue = try? decode(String.self, forKey: key) {
62+
dictionary[key.stringValue] = stringValue
63+
} else if let intValue = try? decode(Int.self, forKey: key) {
64+
dictionary[key.stringValue] = intValue
65+
} else if let doubleValue = try? decode(Double.self, forKey: key) {
66+
dictionary[key.stringValue] = doubleValue
67+
} else if let nestedDictionary = try? decode(Dictionary<String, Any>.self, forKey: key) {
68+
dictionary[key.stringValue] = nestedDictionary
69+
} else if let nestedArray = try? decode(Array<Any>.self, forKey: key) {
70+
dictionary[key.stringValue] = nestedArray
71+
}
72+
}
73+
return dictionary
74+
}
75+
}
76+
77+
extension UnkeyedDecodingContainer {
78+
79+
mutating func decode(_ type: Array<Any>.Type) throws -> Array<Any> {
80+
var array: [Any] = []
81+
while isAtEnd == false {
82+
if let value = try? decode(Bool.self) {
83+
array.append(value)
84+
} else if let value = try? decode(Double.self) {
85+
array.append(value)
86+
} else if let value = try? decode(String.self) {
87+
array.append(value)
88+
} else if let nestedDictionary = try? decode(Dictionary<String, Any>.self) {
89+
array.append(nestedDictionary)
90+
} else if let nestedArray = try? decode(Array<Any>.self) {
91+
array.append(nestedArray)
92+
}
93+
}
94+
return array
95+
}
96+
97+
mutating func decode(_ type: Dictionary<String, Any>.Type) throws -> Dictionary<String, Any> {
98+
99+
let nestedContainer = try self.nestedContainer(keyedBy: JSONCodingKeys.self)
100+
return try nestedContainer.decode(type)
101+
}
102+
}

0 commit comments

Comments
 (0)