Skip to content

Commit

Permalink
- Add extra hook function
Browse files Browse the repository at this point in the history
- Fix ENS
- Implement nonce middleware, example is in tests
  • Loading branch information
shamatar committed Nov 5, 2018
1 parent b256f11 commit 38f8caa
Show file tree
Hide file tree
Showing 52 changed files with 234 additions and 48 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,4 @@ fastlane/screenshots
fastlane/test_output
API_keys.plist
web3swiftTests/key.json
web3swiftTests/Resources/key.json
2 changes: 1 addition & 1 deletion Pods/Headers/Public/BigInt/BigInt-iOS-umbrella.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Pods/Headers/Public/BigInt/BigInt-iOS.modulemap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Pods/Headers/Public/BigInt/BigInt-macOS-umbrella.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Pods/Headers/Public/BigInt/BigInt-macOS.modulemap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Pods/Headers/Public/CryptoSwift/CryptoSwift-iOS-umbrella.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Pods/Headers/Public/CryptoSwift/CryptoSwift-iOS.modulemap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Pods/Headers/Public/EthereumABI/EthereumABI-iOS-umbrella.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Pods/Headers/Public/EthereumABI/EthereumABI-iOS.modulemap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Pods/Headers/Public/PromiseKit/PromiseKit-umbrella.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Pods/Headers/Public/PromiseKit/PromiseKit.modulemap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Pods/Headers/Public/Result/Result-iOS-umbrella.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Pods/Headers/Public/Result/Result-iOS.modulemap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Pods/Headers/Public/Result/Result-macOS-umbrella.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Pods/Headers/Public/Result/Result-macOS.modulemap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Pods/Headers/Public/SipHash/SipHash-iOS-umbrella.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Pods/Headers/Public/SipHash/SipHash-iOS.modulemap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Pods/Headers/Public/SipHash/SipHash-macOS-umbrella.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Pods/Headers/Public/SipHash/SipHash-macOS.modulemap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Pods/Headers/Public/SwiftRLP/SwiftRLP-iOS-umbrella.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Pods/Headers/Public/SwiftRLP/SwiftRLP-iOS.modulemap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Pods/Headers/Public/SwiftRLP/SwiftRLP-macOS-umbrella.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Pods/Headers/Public/SwiftRLP/SwiftRLP-macOS.modulemap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Pods/Headers/Public/scrypt/scrypt-iOS-umbrella.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Pods/Headers/Public/scrypt/scrypt-iOS.modulemap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Pods/Headers/Public/scrypt/scrypt-macOS-umbrella.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Pods/Headers/Public/scrypt/scrypt-macOS.modulemap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions web3swift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@
81DFB400210775320011DC85 /* Web3+Infura.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81DFB3FE210775320011DC85 /* Web3+Infura.swift */; };
81EB1E4B208173D7003BD47F /* Web3+Personal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81EB1E4A208173D7003BD47F /* Web3+Personal.swift */; };
81EB1E4C208173D7003BD47F /* Web3+Personal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81EB1E4A208173D7003BD47F /* Web3+Personal.swift */; };
81ED4EA82190D922003E932E /* NonceMiddleware.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81ED4EA72190D922003E932E /* NonceMiddleware.swift */; };
81ED4EA92190D922003E932E /* NonceMiddleware.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81ED4EA72190D922003E932E /* NonceMiddleware.swift */; };
81FA43F62044097100EE14D5 /* web3swift_macOS_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81FA43F52044097100EE14D5 /* web3swift_macOS_Tests.swift */; };
81FA43F82044097100EE14D5 /* web3swift_macOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 417715D420362916005C3E16 /* web3swift_macOS.framework */; };
81FB21FE207BB297007F9A83 /* EIP67Code.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81FB21F8207BA78B007F9A83 /* EIP67Code.swift */; };
Expand Down Expand Up @@ -310,6 +312,7 @@
81DDECCE1FDF004E0063684A /* Web3.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Web3.swift; sourceTree = "<group>"; };
81DFB3FE210775320011DC85 /* Web3+Infura.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Web3+Infura.swift"; sourceTree = "<group>"; };
81EB1E4A208173D7003BD47F /* Web3+Personal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Web3+Personal.swift"; sourceTree = "<group>"; };
81ED4EA72190D922003E932E /* NonceMiddleware.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonceMiddleware.swift; sourceTree = "<group>"; };
81FA43F32044097000EE14D5 /* web3swift-macOS_Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "web3swift-macOS_Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
81FA43F52044097100EE14D5 /* web3swift_macOS_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = web3swift_macOS_Tests.swift; sourceTree = "<group>"; };
81FA43F72044097100EE14D5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -502,6 +505,7 @@
81A7B2862143DBF6004CD2C7 /* EIP681.swift */,
B2E668CD214F8A7B00C3CC2D /* ENS.swift */,
B219DC162154F3EE0035BF94 /* ENSResolver.swift */,
81ED4EA72190D922003E932E /* NonceMiddleware.swift */,
);
path = Classes;
sourceTree = "<group>";
Expand Down Expand Up @@ -1054,6 +1058,7 @@
8160E5CE20B8245A0070070B /* IBAN.swift in Sources */,
81909D1521862D37007D2AE5 /* Web3+MutatingTransaction.swift in Sources */,
810B0F9C1FEC520500CF0DA2 /* Web3+Methods.swift in Sources */,
81ED4EA82190D922003E932E /* NonceMiddleware.swift in Sources */,
81A1822520D678590016741F /* Promise+Web3+Eth+GetGasPrice.swift in Sources */,
8113DE7C1FD8514400CD8DF1 /* NSRegularExpressionExtension.swift in Sources */,
81C5DA2E2074EBF500424CD6 /* EthereumContract.swift in Sources */,
Expand Down Expand Up @@ -1158,6 +1163,7 @@
41948131203630530065A83B /* BIP32KeystoreJSONStructure.swift in Sources */,
41948132203630530065A83B /* BIP32HDNode.swift in Sources */,
81A7B2522143C3A8004CD2C7 /* NameHash.swift in Sources */,
81ED4EA92190D922003E932E /* NonceMiddleware.swift in Sources */,
81A1824920D7DDA20016741F /* Promise+Web3+Personal+Sign.swift in Sources */,
81A1822620D678590016741F /* Promise+Web3+Eth+GetGasPrice.swift in Sources */,
81909D1621862D37007D2AE5 /* Web3+MutatingTransaction.swift in Sources */,
Expand Down
5 changes: 3 additions & 2 deletions web3swift/Convenience/Classes/Data+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public extension Data {
dataPtr.initialize(repeating: 0, count: count)
}
}
public static func randomBytes(length: Int) -> Data? {

static func randomBytes(length: Int) -> Data? {
for _ in 0...1024 {
var data = Data(repeating: 0, count: length)
let result = data.withUnsafeMutableBytes {
Expand All @@ -51,7 +52,7 @@ public extension Data {
return nil
}

public static func fromHex(_ hex: String) -> Data? {
static func fromHex(_ hex: String) -> Data? {
let string = hex.lowercased().stripHexPrefix()
let array = Array<UInt8>(hex: string)
if (array.count == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ extension web3.Eth {
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node")
}
let result = TransactionSendingResult(transaction: transaction, hash: value)
for hook in self.web3.postSubmissionHooks {
hook.queue.async {
hook.function(result)
}
}
return result
}
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import PromiseKit

extension web3.Eth {

public func sendTransactionPromise(_ transaction: EthereumTransaction, transactionOptions: TransactionOptions?, password:String = "web3swift") -> Promise<TransactionSendingResult> {
public func sendTransactionPromise(_ transaction: EthereumTransaction, transactionOptions: TransactionOptions? = nil, password:String = "web3swift") -> Promise<TransactionSendingResult> {
// print(transaction)
var assembledTransaction : EthereumTransaction = transaction // .mergedWithOptions(transactionOptions)
let queue = web3.requestDispatcher.queue
Expand All @@ -30,7 +30,7 @@ extension web3.Eth {
}
}
let shouldContinue = try prom.wait()
if shouldContinue {
if !shouldContinue {
throw Web3Error.processingError(desc: "Transaction is canceled by middleware")
}
}
Expand All @@ -51,6 +51,11 @@ extension web3.Eth {
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node")
}
let result = TransactionSendingResult(transaction: assembledTransaction, hash: value)
for hook in self.web3.postSubmissionHooks {
hook.queue.async {
hook.function(result)
}
}
return result
}
}
Expand Down
Loading

0 comments on commit 38f8caa

Please sign in to comment.