@@ -72,8 +72,21 @@ public class WriteTransaction: ReadTransaction {
72
72
optionsForGasEstimation. from = mergedOptions. from
73
73
optionsForGasEstimation. to = mergedOptions. to
74
74
optionsForGasEstimation. value = mergedOptions. value
75
+ optionsForGasEstimation. gasLimit = mergedOptions. gasLimit
75
76
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
+ }
77
90
78
91
// assemble promise for nonce
79
92
var getNoncePromise : Promise < BigUInt > ?
@@ -90,9 +103,20 @@ public class WriteTransaction: ReadTransaction {
90
103
getNoncePromise = Promise< BigUInt> . value( nonce)
91
104
}
92
105
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
96
120
97
121
promisesToFulfill. removeAll ( )
98
122
guard case . fulfilled( let nonce) = results [ 0 ] else {
0 commit comments