@@ -72,8 +72,21 @@ public class WriteTransaction: ReadTransaction {
7272 optionsForGasEstimation. from = mergedOptions. from
7373 optionsForGasEstimation. to = mergedOptions. to
7474 optionsForGasEstimation. value = mergedOptions. value
75+ optionsForGasEstimation. gasLimit = mergedOptions. gasLimit
7576 optionsForGasEstimation. callOnBlock = mergedOptions. callOnBlock
76- let gasEstimatePromise : Promise < BigUInt > = self . web3. eth. estimateGasPromise ( assembledTransaction, transactionOptions: optionsForGasEstimation)
77+
78+ // assemble promise for gasLimit
79+ var gasEstimatePromise : Promise < BigUInt > ? = nil
80+ guard let gasLimitPolicy = mergedOptions. gasLimit else {
81+ seal. reject ( Web3Error . inputError ( desc: " No gasLimit policy provided " ) )
82+ return
83+ }
84+ switch gasLimitPolicy {
85+ case . automatic, . withMargin, . limited:
86+ gasEstimatePromise = self . web3. eth. estimateGasPromise ( assembledTransaction, transactionOptions: optionsForGasEstimation)
87+ case . manual( let gasLimit) :
88+ gasEstimatePromise = Promise< BigUInt> . value( gasLimit)
89+ }
7790
7891 // assemble promise for nonce
7992 var getNoncePromise : Promise < BigUInt > ?
@@ -90,9 +103,20 @@ public class WriteTransaction: ReadTransaction {
90103 getNoncePromise = Promise< BigUInt> . value( nonce)
91104 }
92105
93- let gasPricePromise : Promise < BigUInt > = self . web3. eth. getGasPricePromise ( )
94- var promisesToFulfill : [ Promise < BigUInt > ] = [ getNoncePromise!, gasPricePromise, gasPricePromise]
95- when ( resolved: getNoncePromise!, gasEstimatePromise, gasPricePromise) . map ( on: queue, { ( results: [ PromiseResult < BigUInt > ] ) throws -> EthereumTransaction in
106+ // assemble promise for gasPrice
107+ var gasPricePromise : Promise < BigUInt > ? = nil
108+ guard let gasPricePolicy = mergedOptions. gasPrice else {
109+ seal. reject ( Web3Error . inputError ( desc: " No gasPrice policy provided " ) )
110+ return
111+ }
112+ switch gasPricePolicy {
113+ case . automatic, . withMargin:
114+ gasPricePromise = self . web3. eth. getGasPricePromise ( )
115+ case . manual( let gasPrice) :
116+ gasPricePromise = Promise< BigUInt> . value( gasPrice)
117+ }
118+ var promisesToFulfill : [ Promise < BigUInt > ] = [ getNoncePromise!, gasPricePromise!, gasEstimatePromise!]
119+ when ( resolved: getNoncePromise!, gasEstimatePromise!, gasPricePromise!) . map ( on: queue, { ( results: [ PromiseResult < BigUInt > ] ) throws -> EthereumTransaction in
96120
97121 promisesToFulfill. removeAll ( )
98122 guard case . fulfilled( let nonce) = results [ 0 ] else {
0 commit comments