Skip to content

Commit 38f8caa

Browse files
committed
- Add extra hook function
- Fix ENS - Implement nonce middleware, example is in tests
1 parent b256f11 commit 38f8caa

File tree

52 files changed

+234
-48
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+234
-48
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,4 @@ fastlane/screenshots
6767
fastlane/test_output
6868
API_keys.plist
6969
web3swiftTests/key.json
70+
web3swiftTests/Resources/key.json

Pods/Headers/Public/BigInt/BigInt-iOS-umbrella.h

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Headers/Public/BigInt/BigInt-iOS.modulemap

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Headers/Public/BigInt/BigInt-macOS-umbrella.h

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Headers/Public/BigInt/BigInt-macOS.modulemap

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Headers/Public/CryptoSwift/CryptoSwift-iOS-umbrella.h

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Headers/Public/CryptoSwift/CryptoSwift-iOS.modulemap

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Headers/Public/CryptoSwift/CryptoSwift-macOS-umbrella.h

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Headers/Public/CryptoSwift/CryptoSwift-macOS.modulemap

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Headers/Public/EthereumABI/EthereumABI-iOS-umbrella.h

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Headers/Public/EthereumABI/EthereumABI-iOS.modulemap

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Headers/Public/EthereumABI/EthereumABI-macOS-umbrella.h

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Headers/Public/EthereumABI/EthereumABI-macOS.modulemap

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Headers/Public/EthereumAddress/EthereumAddress-iOS-umbrella.h

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Headers/Public/EthereumAddress/EthereumAddress-iOS.modulemap

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Headers/Public/EthereumAddress/EthereumAddress-macOS-umbrella.h

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Headers/Public/EthereumAddress/EthereumAddress-macOS.modulemap

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Headers/Public/PromiseKit/PromiseKit-umbrella.h

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Headers/Public/PromiseKit/PromiseKit.modulemap

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Headers/Public/PromiseKit/PromiseKit.root-CorePromise-Foundation-umbrella.h

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Headers/Public/PromiseKit/PromiseKit.root-CorePromise-Foundation.modulemap

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Headers/Public/Result/Result-iOS-umbrella.h

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Headers/Public/Result/Result-iOS.modulemap

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Headers/Public/Result/Result-macOS-umbrella.h

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Headers/Public/Result/Result-macOS.modulemap

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Headers/Public/SipHash/SipHash-iOS-umbrella.h

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Headers/Public/SipHash/SipHash-iOS.modulemap

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Headers/Public/SipHash/SipHash-macOS-umbrella.h

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Headers/Public/SipHash/SipHash-macOS.modulemap

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Headers/Public/SwiftRLP/SwiftRLP-iOS-umbrella.h

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Headers/Public/SwiftRLP/SwiftRLP-iOS.modulemap

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Headers/Public/SwiftRLP/SwiftRLP-macOS-umbrella.h

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Headers/Public/SwiftRLP/SwiftRLP-macOS.modulemap

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Headers/Public/scrypt/scrypt-iOS-umbrella.h

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Headers/Public/scrypt/scrypt-iOS.modulemap

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Headers/Public/scrypt/scrypt-macOS-umbrella.h

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Headers/Public/scrypt/scrypt-macOS.modulemap

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Headers/Public/secp256k1_swift/secp256k1_swift-iOS-umbrella.h

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Headers/Public/secp256k1_swift/secp256k1_swift-iOS.modulemap

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Headers/Public/secp256k1_swift/secp256k1_swift-macOS-umbrella.h

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Headers/Public/secp256k1_swift/secp256k1_swift-macOS.modulemap

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web3swift.xcodeproj/project.pbxproj

+6
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@
165165
81DFB400210775320011DC85 /* Web3+Infura.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81DFB3FE210775320011DC85 /* Web3+Infura.swift */; };
166166
81EB1E4B208173D7003BD47F /* Web3+Personal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81EB1E4A208173D7003BD47F /* Web3+Personal.swift */; };
167167
81EB1E4C208173D7003BD47F /* Web3+Personal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81EB1E4A208173D7003BD47F /* Web3+Personal.swift */; };
168+
81ED4EA82190D922003E932E /* NonceMiddleware.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81ED4EA72190D922003E932E /* NonceMiddleware.swift */; };
169+
81ED4EA92190D922003E932E /* NonceMiddleware.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81ED4EA72190D922003E932E /* NonceMiddleware.swift */; };
168170
81FA43F62044097100EE14D5 /* web3swift_macOS_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81FA43F52044097100EE14D5 /* web3swift_macOS_Tests.swift */; };
169171
81FA43F82044097100EE14D5 /* web3swift_macOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 417715D420362916005C3E16 /* web3swift_macOS.framework */; };
170172
81FB21FE207BB297007F9A83 /* EIP67Code.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81FB21F8207BA78B007F9A83 /* EIP67Code.swift */; };
@@ -310,6 +312,7 @@
310312
81DDECCE1FDF004E0063684A /* Web3.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Web3.swift; sourceTree = "<group>"; };
311313
81DFB3FE210775320011DC85 /* Web3+Infura.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Web3+Infura.swift"; sourceTree = "<group>"; };
312314
81EB1E4A208173D7003BD47F /* Web3+Personal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Web3+Personal.swift"; sourceTree = "<group>"; };
315+
81ED4EA72190D922003E932E /* NonceMiddleware.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonceMiddleware.swift; sourceTree = "<group>"; };
313316
81FA43F32044097000EE14D5 /* web3swift-macOS_Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "web3swift-macOS_Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
314317
81FA43F52044097100EE14D5 /* web3swift_macOS_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = web3swift_macOS_Tests.swift; sourceTree = "<group>"; };
315318
81FA43F72044097100EE14D5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -502,6 +505,7 @@
502505
81A7B2862143DBF6004CD2C7 /* EIP681.swift */,
503506
B2E668CD214F8A7B00C3CC2D /* ENS.swift */,
504507
B219DC162154F3EE0035BF94 /* ENSResolver.swift */,
508+
81ED4EA72190D922003E932E /* NonceMiddleware.swift */,
505509
);
506510
path = Classes;
507511
sourceTree = "<group>";
@@ -1054,6 +1058,7 @@
10541058
8160E5CE20B8245A0070070B /* IBAN.swift in Sources */,
10551059
81909D1521862D37007D2AE5 /* Web3+MutatingTransaction.swift in Sources */,
10561060
810B0F9C1FEC520500CF0DA2 /* Web3+Methods.swift in Sources */,
1061+
81ED4EA82190D922003E932E /* NonceMiddleware.swift in Sources */,
10571062
81A1822520D678590016741F /* Promise+Web3+Eth+GetGasPrice.swift in Sources */,
10581063
8113DE7C1FD8514400CD8DF1 /* NSRegularExpressionExtension.swift in Sources */,
10591064
81C5DA2E2074EBF500424CD6 /* EthereumContract.swift in Sources */,
@@ -1158,6 +1163,7 @@
11581163
41948131203630530065A83B /* BIP32KeystoreJSONStructure.swift in Sources */,
11591164
41948132203630530065A83B /* BIP32HDNode.swift in Sources */,
11601165
81A7B2522143C3A8004CD2C7 /* NameHash.swift in Sources */,
1166+
81ED4EA92190D922003E932E /* NonceMiddleware.swift in Sources */,
11611167
81A1824920D7DDA20016741F /* Promise+Web3+Personal+Sign.swift in Sources */,
11621168
81A1822620D678590016741F /* Promise+Web3+Eth+GetGasPrice.swift in Sources */,
11631169
81909D1621862D37007D2AE5 /* Web3+MutatingTransaction.swift in Sources */,

web3swift/Convenience/Classes/Data+Extension.swift

+3-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ public extension Data {
3737
dataPtr.initialize(repeating: 0, count: count)
3838
}
3939
}
40-
public static func randomBytes(length: Int) -> Data? {
40+
41+
static func randomBytes(length: Int) -> Data? {
4142
for _ in 0...1024 {
4243
var data = Data(repeating: 0, count: length)
4344
let result = data.withUnsafeMutableBytes {
@@ -51,7 +52,7 @@ public extension Data {
5152
return nil
5253
}
5354

54-
public static func fromHex(_ hex: String) -> Data? {
55+
static func fromHex(_ hex: String) -> Data? {
5556
let string = hex.lowercased().stripHexPrefix()
5657
let array = Array<UInt8>(hex: string)
5758
if (array.count == 0) {

web3swift/Promises/Classes/Promise+Web3+Eth+SendRawTransaction.swift

+5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ extension web3.Eth {
3333
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node")
3434
}
3535
let result = TransactionSendingResult(transaction: transaction, hash: value)
36+
for hook in self.web3.postSubmissionHooks {
37+
hook.queue.async {
38+
hook.function(result)
39+
}
40+
}
3641
return result
3742
}
3843
} catch {

web3swift/Promises/Classes/Promise+Web3+Eth+SendTransaction.swift

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import PromiseKit
1010

1111
extension web3.Eth {
1212

13-
public func sendTransactionPromise(_ transaction: EthereumTransaction, transactionOptions: TransactionOptions?, password:String = "web3swift") -> Promise<TransactionSendingResult> {
13+
public func sendTransactionPromise(_ transaction: EthereumTransaction, transactionOptions: TransactionOptions? = nil, password:String = "web3swift") -> Promise<TransactionSendingResult> {
1414
// print(transaction)
1515
var assembledTransaction : EthereumTransaction = transaction // .mergedWithOptions(transactionOptions)
1616
let queue = web3.requestDispatcher.queue
@@ -30,7 +30,7 @@ extension web3.Eth {
3030
}
3131
}
3232
let shouldContinue = try prom.wait()
33-
if shouldContinue {
33+
if !shouldContinue {
3434
throw Web3Error.processingError(desc: "Transaction is canceled by middleware")
3535
}
3636
}
@@ -51,6 +51,11 @@ extension web3.Eth {
5151
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node")
5252
}
5353
let result = TransactionSendingResult(transaction: assembledTransaction, hash: value)
54+
for hook in self.web3.postSubmissionHooks {
55+
hook.queue.async {
56+
hook.function(result)
57+
}
58+
}
5459
return result
5560
}
5661
}

0 commit comments

Comments
 (0)