Skip to content

Commit 955c6d5

Browse files
author
Alex Vlasov
committed
fix gas price setting for transaction
attempt to fix some race condition on sending a transaction
1 parent 967ea8c commit 955c6d5

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

web3swift.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "web3swift"
3-
s.version = "1.1.0"
3+
s.version = "1.1.1"
44
s.summary = "Web3 implementation in vanilla Swift for iOS ans macOS"
55

66
s.description = <<-DESC

web3swift/Promises/Classes/Promise+Batching.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public class JSONRPCrequestDispatcher {
2222
self.provider = provider
2323
self.queue = queue
2424
self.policy = policy
25-
self.lockQueue = DispatchQueue(label: "batchingQueue", qos: .userInitiated)
25+
self.lockQueue = DispatchQueue.init(label: "batchingQueue") // serial simplest queue
26+
// DispatchQueue(label: "batchingQueue", qos: .userInitiated)
2627
self.batches.append(Batch(provider: self.provider, capacity: 32, queue: self.queue, lockQueue: self.lockQueue))
2728
}
2829

@@ -41,7 +42,7 @@ public class JSONRPCrequestDispatcher {
4142
}
4243
let requestID = request.id
4344
let promiseToReturn = Promise<JSONRPCresponse>.pending()
44-
self.queue.async {
45+
self.lockQueue.async {
4546
if self.promisesDict[requestID] != nil {
4647
promiseToReturn.resolver.reject(Web3Error.processingError("Request ID collision"))
4748
}

web3swift/Web3/Classes/Web3+Options.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,15 @@ public struct Web3Options {
132132
}
133133
}
134134
}
135+
136+
public static func smartMergeGasPrice(originalOptions: Web3Options?, extraOptions: Web3Options?, priceEstimate: BigUInt) -> BigUInt? {
137+
guard let mergedOptions = Web3Options.merge(originalOptions, with: extraOptions) else {return nil} //just require any non-nils
138+
if mergedOptions.gasPrice == nil {
139+
return priceEstimate
140+
} else if mergedOptions.gasPrice == 0 {
141+
return priceEstimate
142+
} else {
143+
return mergedOptions.gasPrice!
144+
}
145+
}
135146
}

web3swift/Web3/Classes/Web3+TransactionIntermediate.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,17 @@ extension web3.web3contract.TransactionIntermediate {
178178
}
179179
assembledTransaction.nonce = nonce
180180
assembledTransaction.gasLimit = estimate
181-
if assembledTransaction.gasPrice == 0 {
182-
if mergedOptions.gasPrice != nil {
183-
assembledTransaction.gasPrice = mergedOptions.gasPrice!
184-
} else {
185-
assembledTransaction.gasPrice = gasPrice
186-
}
181+
guard let finalGasPrice = Web3Options.smartMergeGasPrice(originalOptions: options, extraOptions: mergedOptions, priceEstimate: gasPrice) else {
182+
throw Web3Error.processingError("Missing parameter of gas price for transaction")
187183
}
184+
assembledTransaction.gasPrice = finalGasPrice
185+
// if assembledTransaction.gasPrice == 0 {
186+
// if mergedOptions.gasPrice != nil {
187+
// assembledTransaction.gasPrice = mergedOptions.gasPrice!
188+
// } else {
189+
// assembledTransaction.gasPrice = gasPrice
190+
// }
191+
// }
188192
return assembledTransaction
189193
}).done(on: queue) {tx in
190194
seal.fulfill(tx)

0 commit comments

Comments
 (0)