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

Commit

Permalink
Merge pull request #201 from BANKEX/develop
Browse files Browse the repository at this point in the history
fix gas price setting for transaction
attempt to fix some race condition on sending a transaction
  • Loading branch information
shamatar authored Jul 30, 2018
2 parents 967ea8c + 955c6d5 commit 99d4dfb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
2 changes: 1 addition & 1 deletion web3swift.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "web3swift"
s.version = "1.1.0"
s.version = "1.1.1"
s.summary = "Web3 implementation in vanilla Swift for iOS ans macOS"

s.description = <<-DESC
Expand Down
5 changes: 3 additions & 2 deletions web3swift/Promises/Classes/Promise+Batching.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public class JSONRPCrequestDispatcher {
self.provider = provider
self.queue = queue
self.policy = policy
self.lockQueue = DispatchQueue(label: "batchingQueue", qos: .userInitiated)
self.lockQueue = DispatchQueue.init(label: "batchingQueue") // serial simplest queue
// DispatchQueue(label: "batchingQueue", qos: .userInitiated)
self.batches.append(Batch(provider: self.provider, capacity: 32, queue: self.queue, lockQueue: self.lockQueue))
}

Expand All @@ -41,7 +42,7 @@ public class JSONRPCrequestDispatcher {
}
let requestID = request.id
let promiseToReturn = Promise<JSONRPCresponse>.pending()
self.queue.async {
self.lockQueue.async {
if self.promisesDict[requestID] != nil {
promiseToReturn.resolver.reject(Web3Error.processingError("Request ID collision"))
}
Expand Down
11 changes: 11 additions & 0 deletions web3swift/Web3/Classes/Web3+Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,15 @@ public struct Web3Options {
}
}
}

public static func smartMergeGasPrice(originalOptions: Web3Options?, extraOptions: Web3Options?, priceEstimate: BigUInt) -> BigUInt? {
guard let mergedOptions = Web3Options.merge(originalOptions, with: extraOptions) else {return nil} //just require any non-nils
if mergedOptions.gasPrice == nil {
return priceEstimate
} else if mergedOptions.gasPrice == 0 {
return priceEstimate
} else {
return mergedOptions.gasPrice!
}
}
}
16 changes: 10 additions & 6 deletions web3swift/Web3/Classes/Web3+TransactionIntermediate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,17 @@ extension web3.web3contract.TransactionIntermediate {
}
assembledTransaction.nonce = nonce
assembledTransaction.gasLimit = estimate
if assembledTransaction.gasPrice == 0 {
if mergedOptions.gasPrice != nil {
assembledTransaction.gasPrice = mergedOptions.gasPrice!
} else {
assembledTransaction.gasPrice = gasPrice
}
guard let finalGasPrice = Web3Options.smartMergeGasPrice(originalOptions: options, extraOptions: mergedOptions, priceEstimate: gasPrice) else {
throw Web3Error.processingError("Missing parameter of gas price for transaction")
}
assembledTransaction.gasPrice = finalGasPrice
// if assembledTransaction.gasPrice == 0 {
// if mergedOptions.gasPrice != nil {
// assembledTransaction.gasPrice = mergedOptions.gasPrice!
// } else {
// assembledTransaction.gasPrice = gasPrice
// }
// }
return assembledTransaction
}).done(on: queue) {tx in
seal.fulfill(tx)
Expand Down

0 comments on commit 99d4dfb

Please sign in to comment.