Skip to content

Commit e905007

Browse files
Rename all all resolvable TransactionOptions property
to `WhateverProlicy`, to avoid it's conflicts with `CodableTransaction` properties.
1 parent e79f102 commit e905007

24 files changed

+103
-76
lines changed

Sources/Core/Transaction/CodableTransaction.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,33 @@ extension CodableTransaction: Codable {
273273

274274
}
275275

276+
extension CodableTransaction {
277+
public enum GasLimitPolicy {
278+
case automatic
279+
case manual(BigUInt)
280+
case limited(BigUInt)
281+
case withMargin(Double)
282+
}
283+
284+
public enum GasPricePolicy {
285+
case automatic
286+
case manual(BigUInt)
287+
case withMargin(Double)
288+
}
289+
290+
public enum FeePerGasPolicy {
291+
case automatic
292+
case manual(BigUInt)
293+
}
294+
295+
public enum NoncePolicy {
296+
case pending
297+
case latest
298+
case manual(BigUInt)
299+
}
300+
}
301+
302+
276303
extension CodableTransaction: CustomStringConvertible {
277304
/// required by CustomString convertable
278305
/// returns a string description for the transaction and its data

Sources/Core/Transaction/Envelope/EIP1559Envelope.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ extension EIP1559Envelope {
235235
// self.nonce = transaction.resolveNonce(self.nonce)
236236
// self.maxPriorityFeePerGas = transaction.resolveMaxPriorityFeePerGas(self.maxPriorityFeePerGas)
237237
// self.maxFeePerGas = transaction.resolveMaxFeePerGas(self.maxFeePerGas)
238-
// self.gasLimit = transaction.resolveGasLimit(self.gasLimit)
238+
// self.gasLimitPolicy = transaction.resolveGasLimit(self.gasLimit)
239239
// self.value = transaction.value ?? self.value
240240
// self.to = transaction.to ?? self.to
241241
// self.accessList = transaction.accessList ?? self.accessList

Sources/Core/Transaction/Envelope/LegacyEnvelope.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ extension LegacyEnvelope {
181181
// // type cannot be changed here, and is ignored
182182
// self.nonce = transaction.resolveNonce(self.nonce)
183183
// self.gasPrice = transaction.resolveGasPrice(self.gasPrice)
184-
// self.gasLimit = transaction.resolveGasLimit(self.gasLimit)
184+
// self.gasLimitPolicy = transaction.resolveGasLimit(self.gasLimit)
185185
// // swiftlint:disable force_unwrapping
186186
// if transaction.value != nil { self.value = transaction.value! }
187187
// if transaction.to != nil { self.to = transaction.to! }

Sources/Core/TransactionOptions.swift

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,23 @@ public struct TransactionOptions {
4242
case limited(BigUInt)
4343
case withMargin(Double)
4444
}
45-
public var gasLimit: GasLimitPolicy?
45+
public var gasLimitPolicy: GasLimitPolicy?
4646

4747
public enum GasPricePolicy {
4848
case automatic
4949
case manual(BigUInt)
5050
case withMargin(Double)
5151
}
5252

53-
public private (set) var gasPrice: GasPricePolicy?
53+
public var gasPricePolicy: GasPricePolicy?
5454

5555
// new gas parameters for EIP-1559 support
5656
public enum FeePerGasPolicy {
5757
case automatic
5858
case manual(BigUInt)
5959
}
60-
public private (set) var maxFeePerGas: FeePerGasPolicy?
61-
public private (set) var maxPriorityFeePerGas: FeePerGasPolicy?
60+
public private (set) var maxFeePerGasPolicy: FeePerGasPolicy?
61+
public private (set) var maxPriorityFeePerGasPolicy: FeePerGasPolicy?
6262

6363
/// The value transferred for the transaction in wei, also the endowment if it’s a contract-creation transaction.
6464
public var value: BigUInt?
@@ -69,7 +69,7 @@ public struct TransactionOptions {
6969
case manual(BigUInt)
7070
}
7171

72-
public private (set) var nonce: NoncePolicy?
72+
public private (set) var noncePolicy: NoncePolicy?
7373

7474
public var callOnBlock: BlockNumber?
7575

@@ -78,11 +78,11 @@ public struct TransactionOptions {
7878
public static var emptyTransaction: TransactionOptions {
7979
var opts = TransactionOptions()
8080
opts.type = .legacy
81-
opts.gasLimit = .automatic
82-
opts.gasPrice = .automatic
83-
opts.maxFeePerGas = .automatic
84-
opts.maxPriorityFeePerGas = .automatic
85-
opts.nonce = .pending
81+
opts.gasLimitPolicy = .automatic
82+
opts.gasPricePolicy = .automatic
83+
opts.maxFeePerGasPolicy = .automatic
84+
opts.maxPriorityFeePerGasPolicy = .automatic
85+
opts.noncePolicy = .pending
8686
opts.callOnBlock = .pending
8787
return opts
8888
}
@@ -92,18 +92,18 @@ public struct TransactionOptions {
9292
self.to = to
9393
self.from = from
9494
self.chainID = chainID
95-
self.gasLimit = gasLimit
96-
self.gasPrice = gasPrice
97-
self.maxFeePerGas = maxFeePerGas
98-
self.maxPriorityFeePerGas = maxPriorityFeePerGas
95+
self.gasLimitPolicy = gasLimit
96+
self.gasPricePolicy = gasPrice
97+
self.maxFeePerGasPolicy = maxFeePerGas
98+
self.maxPriorityFeePerGasPolicy = maxPriorityFeePerGas
9999
self.value = value
100-
self.nonce = nonce
100+
self.noncePolicy = nonce
101101
self.callOnBlock = callOnBlock
102102
self.accessList = accessList
103103
}
104104

105105
public func resolveNonce(_ suggestedByNode: BigUInt) -> BigUInt {
106-
guard let noncePolicy = self.nonce else { return suggestedByNode }
106+
guard let noncePolicy = self.noncePolicy else { return suggestedByNode }
107107
switch noncePolicy {
108108
case .pending, .latest:
109109
return suggestedByNode
@@ -113,7 +113,7 @@ public struct TransactionOptions {
113113
}
114114

115115
public func resolveGasPrice(_ suggestedByNode: BigUInt) -> BigUInt {
116-
guard let gasPricePolicy = self.gasPrice else { return suggestedByNode }
116+
guard let gasPricePolicy = self.gasPricePolicy else { return suggestedByNode }
117117
switch gasPricePolicy {
118118
case .automatic, .withMargin:
119119
return suggestedByNode
@@ -123,7 +123,7 @@ public struct TransactionOptions {
123123
}
124124

125125
public func resolveGasLimit(_ suggestedByNode: BigUInt) -> BigUInt {
126-
guard let gasLimitPolicy = self.gasLimit else { return suggestedByNode }
126+
guard let gasLimitPolicy = self.gasLimitPolicy else { return suggestedByNode }
127127
switch gasLimitPolicy {
128128
case .automatic, .withMargin:
129129
return suggestedByNode
@@ -139,7 +139,7 @@ public struct TransactionOptions {
139139
}
140140

141141
public func resolveMaxFeePerGas(_ suggestedByNode: BigUInt) -> BigUInt {
142-
guard let maxFeePerGasPolicy = self.maxFeePerGas else { return suggestedByNode }
142+
guard let maxFeePerGasPolicy = self.maxFeePerGasPolicy else { return suggestedByNode }
143143
switch maxFeePerGasPolicy {
144144
case .automatic:
145145
return suggestedByNode
@@ -149,7 +149,7 @@ public struct TransactionOptions {
149149
}
150150

151151
public func resolveMaxPriorityFeePerGas(_ suggestedByNode: BigUInt) -> BigUInt {
152-
guard let maxPriorityFeePerGasPolicy = self.maxPriorityFeePerGas else { return suggestedByNode }
152+
guard let maxPriorityFeePerGasPolicy = self.maxPriorityFeePerGasPolicy else { return suggestedByNode }
153153
switch maxPriorityFeePerGasPolicy {
154154
case .automatic:
155155
return suggestedByNode
@@ -165,12 +165,12 @@ public struct TransactionOptions {
165165
opts.to = mergeIfNotNil(first: self.to, second: other.to)
166166
opts.from = mergeIfNotNil(first: self.from, second: other.from)
167167
opts.chainID = mergeIfNotNil(first: self.chainID, second: other.chainID)
168-
opts.gasLimit = mergeIfNotNil(first: self.gasLimit, second: other.gasLimit)
169-
opts.gasPrice = mergeIfNotNil(first: self.gasPrice, second: other.gasPrice)
170-
opts.maxFeePerGas = mergeIfNotNil(first: self.maxFeePerGas, second: other.maxFeePerGas)
171-
opts.maxPriorityFeePerGas = mergeIfNotNil(first: self.maxPriorityFeePerGas, second: other.maxPriorityFeePerGas)
168+
opts.gasLimitPolicy = mergeIfNotNil(first: self.gasLimitPolicy, second: other.gasLimitPolicy)
169+
opts.gasPricePolicy = mergeIfNotNil(first: self.gasPricePolicy, second: other.gasPricePolicy)
170+
opts.maxFeePerGasPolicy = mergeIfNotNil(first: self.maxFeePerGasPolicy, second: other.maxFeePerGasPolicy)
171+
opts.maxPriorityFeePerGasPolicy = mergeIfNotNil(first: self.maxPriorityFeePerGasPolicy, second: other.maxPriorityFeePerGasPolicy)
172172
opts.value = mergeIfNotNil(first: self.value, second: other.value)
173-
opts.nonce = mergeIfNotNil(first: self.nonce, second: other.nonce)
173+
opts.noncePolicy = mergeIfNotNil(first: self.noncePolicy, second: other.noncePolicy)
174174
opts.callOnBlock = mergeIfNotNil(first: self.callOnBlock, second: other.callOnBlock)
175175
return opts
176176
}

Sources/web3swift/EthereumAPICalls/Ethereum/Eth+EstimateGas.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ extension web3.Eth {
1717
let request: APIRequest = .estimateGas(transaction, transactionOptions?.callOnBlock ?? .latest)
1818
let response: APIResponse<BigUInt> = try await APIRequest.sendRequest(with: provider, for: request)
1919

20-
if let policy = transactionOptions?.gasLimit {
20+
if let policy = transactionOptions?.gasLimitPolicy {
2121
switch policy {
2222
case .automatic:
2323
return response.result

Sources/web3swift/HookedFunctions/Web3+BrowserFunctions.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ extension web3.BrowserFunctions {
7979
// transactionOptions.from = options.from
8080
// transactionOptions.to = options.to
8181
// transactionOptions.value = options.value ?? 0
82-
// transactionOptions.gasLimit = options.gasLimit ?? .automatic
83-
// transactionOptions.gasPrice = options.gasPrice ?? .automatic
82+
// transactionOptions.gasLimitPolicy = options.gasLimitPolicy ?? .automatic
83+
// transactionOptions.gasPricePolicy = options.gasPricePolicy ?? .automatic
8484
// return await self.sendTransaction(transaction, transactionOptions: transactionOptions, password: password)
8585
// } catch { return nil }
8686
// }
@@ -104,8 +104,8 @@ extension web3.BrowserFunctions {
104104
// transactionOptions.from = options.from
105105
// transactionOptions.to = options.to
106106
// transactionOptions.value = options.value ?? 0
107-
// transactionOptions.gasLimit = .automatic
108-
// transactionOptions.gasPrice = options.gasPrice ?? .automatic
107+
// transactionOptions.gasLimitPolicy = .automatic
108+
// transactionOptions.gasPricePolicy = options.gasPricePolicy ?? .automatic
109109
// return await self.estimateGas(transaction, transactionOptions: transactionOptions)
110110
// } catch { return nil }
111111
// }
@@ -141,11 +141,11 @@ extension web3.BrowserFunctions {
141141
let gasPrice = try await self.web3.eth.gasPrice()
142142
transaction.gasPrice = gasPrice
143143
// FIXME: Make this work again
144-
// options.gasPrice = .manual(gasPrice)
144+
// options.gasPricePolicy = .manual(gasPricePolicy)
145145
guard let gasEstimate = await self.estimateGas(transaction, transactionOptions: options) else {return (nil, nil)}
146146
transaction.gasLimit = gasEstimate
147147

148-
options.gasLimit = .limited(gasEstimate)
148+
options.gasLimitPolicy = .limited(gasEstimate)
149149
print(transaction)
150150
return (transaction, options)
151151
} catch {
@@ -163,8 +163,8 @@ extension web3.BrowserFunctions {
163163
// transactionOptions.from = options.from
164164
// transactionOptions.to = options.to
165165
// transactionOptions.value = options.value ?? 0
166-
// transactionOptions.gasLimit = options.gasLimit ?? .automatic
167-
// transactionOptions.gasPrice = options.gasPrice ?? .automatic
166+
// transactionOptions.gasLimitPolicy = options.gasLimit ?? .automatic
167+
// transactionOptions.gasPricePolicy = options.gasPrice ?? .automatic
168168
// if let nonceString = transactionJSON["nonce"] as? String, let nonce = BigUInt(nonceString.stripHexPrefix(), radix: 16) {
169169
// transactionOptions.nonce = .manual(nonce)
170170
// } else {

Sources/web3swift/Tokens/ERC1155/Web3+ERC1155.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public class ERC1155: IERC1155 {
134134
let contract = self.contract
135135
var transactionOptions = TransactionOptions()
136136
transactionOptions.callOnBlock = .latest
137-
transactionOptions.gasLimit = .manual(30000)
137+
transactionOptions.gasLimitPolicy = .manual(30000)
138138
let result = try await contract.read("supportsInterface", parameters: [interfaceID] as [AnyObject], extraData: Data(), transactionOptions: self.transactionOptions)!.decodedData(with: transactionOptions)
139139
guard let res = result["0"] as? Bool else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
140140
return res

Sources/web3swift/Tokens/ERC1400/Web3+ERC1400.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ extension ERC1400: IERC777 {
729729
let contract = self.contract
730730
var transactionOptions = TransactionOptions()
731731
transactionOptions.callOnBlock = .latest
732-
transactionOptions.gasLimit = .manual(30000)
732+
transactionOptions.gasLimitPolicy = .manual(30000)
733733
let result = try await contract.read("supportsInterface", parameters: [interfaceID] as [AnyObject], extraData: Data(), transactionOptions: self.transactionOptions)!.decodedData(with: transactionOptions)
734734
guard let res = result["0"] as? Bool else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
735735
return res

Sources/web3swift/Tokens/ERC1410/Web3+ERC1410.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ extension ERC1410: IERC777 {
463463
let contract = self.contract
464464
var transactionOptions = TransactionOptions()
465465
transactionOptions.callOnBlock = .latest
466-
transactionOptions.gasLimit = .manual(30000)
466+
transactionOptions.gasLimitPolicy = .manual(30000)
467467
let result = try await contract.read("supportsInterface", parameters: [interfaceID] as [AnyObject], extraData: Data(), transactionOptions: self.transactionOptions)!.decodedData(with: transactionOptions)
468468
guard let res = result["0"] as? Bool else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
469469
return res

Sources/web3swift/Tokens/ERC1633/Web3+ERC1633.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public class ERC1633: IERC1633, ERC20BaseProperties {
187187
let contract = self.contract
188188
var transactionOptions = TransactionOptions()
189189
transactionOptions.callOnBlock = .latest
190-
transactionOptions.gasLimit = .manual(30000)
190+
transactionOptions.gasLimitPolicy = .manual(30000)
191191
let result = try await contract.read("supportsInterface", parameters: [interfaceID] as [AnyObject], extraData: Data(), transactionOptions: self.transactionOptions)!.decodedData(with: transactionOptions)
192192
guard let res = result["0"] as? Bool else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
193193
return res

0 commit comments

Comments
 (0)