Skip to content

Commit 3fd2db2

Browse files
Change all TransactionOptions() initializers
to `TransactionOptions.emptyTransaction` static property.
1 parent 9e839eb commit 3fd2db2

19 files changed

+279
-279
lines changed

Sources/Core/TransactionOptions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public struct TransactionOptions {
160160

161161
public func merge(_ otherOptions: TransactionOptions?) -> TransactionOptions {
162162
guard let other = otherOptions else { return self }
163-
var opts = TransactionOptions()
163+
var opts = TransactionOptions.emptyTransaction
164164
opts.type = mergeIfNotNil(first: self.type, second: other.type)
165165
opts.to = mergeIfNotNil(first: self.to, second: other.to)
166166
opts.from = mergeIfNotNil(first: self.from, second: other.from)

Sources/web3swift/HookedFunctions/Web3+BrowserFunctions.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ extension web3.BrowserFunctions {
7575
// let jsonData: Data = try JSONSerialization.data(withJSONObject: transactionJSON, options: [])
7676
// let transaction: CodableTransaction = try JSONDecoder().decode(CodableTransaction.self, from: jsonData)
7777
// let options: TransactionOptions = try JSONDecoder().decode(TransactionOptions.self, from: jsonData)
78-
// var transactionOptions = TransactionOptions()
78+
// var transactionOptions = TransactionOptions.emptyTransaction
7979
// transactionOptions.from = options.from
8080
// transactionOptions.to = options.to
8181
// transactionOptions.value = options.value ?? 0
@@ -100,7 +100,7 @@ extension web3.BrowserFunctions {
100100
// let jsonData: Data = try JSONSerialization.data(withJSONObject: transactionJSON, options: [])
101101
// let transaction: CodableTransaction = try JSONDecoder().decode(CodableTransaction.self, from: jsonData)
102102
// let options: TransactionOptions = try JSONDecoder().decode(TransactionOptions.self, from: jsonData)
103-
// var transactionOptions = TransactionOptions()
103+
// var transactionOptions = TransactionOptions.emptyTransaction
104104
// transactionOptions.from = options.from
105105
// transactionOptions.to = options.to
106106
// transactionOptions.value = options.value ?? 0
@@ -158,7 +158,7 @@ extension web3.BrowserFunctions {
158158
// let jsonData: Data = try JSONSerialization.data(withJSONObject: transactionJSON, options: [])
159159
// let transaction: EthereumTransaction = try JSONDecoder().decode(EthereumTransaction.self, from: jsonData)
160160
// let options: TransactionOptions = try JSONDecoder().decode(TransactionOptions.self, from: jsonData)
161-
// var transactionOptions = TransactionOptions()
161+
// var transactionOptions = TransactionOptions.emptyTransaction
162162
// transactionOptions.from = options.from
163163
// transactionOptions.to = options.to
164164
// transactionOptions.value = options.value ?? 0

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public class ERC1155: IERC1155 {
8484

8585
public func safeTransferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, id: BigUInt, value: BigUInt, data: [UInt8]) throws -> WriteTransaction {
8686
let contract = self.contract
87-
var basicOptions = TransactionOptions()
87+
var basicOptions = TransactionOptions.emptyTransaction
8888
basicOptions.from = from
8989
basicOptions.to = self.address
9090

@@ -94,7 +94,7 @@ public class ERC1155: IERC1155 {
9494

9595
public func safeBatchTransferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, ids: [BigUInt], values: [BigUInt], data: [UInt8]) throws -> WriteTransaction {
9696
let contract = self.contract
97-
var basicOptions = TransactionOptions()
97+
var basicOptions = TransactionOptions.emptyTransaction
9898
basicOptions.from = from
9999
basicOptions.to = self.address
100100

@@ -104,7 +104,7 @@ public class ERC1155: IERC1155 {
104104

105105
public func balanceOf(account: EthereumAddress, id: BigUInt) async throws -> BigUInt {
106106
let contract = self.contract
107-
var transactionOptions = TransactionOptions()
107+
var transactionOptions = TransactionOptions.emptyTransaction
108108
transactionOptions.callOnBlock = .latest
109109
let result = try await contract.read("balanceOf", parameters: [account, id] as [AnyObject], extraData: Data(), transactionOptions: self.transactionOptions)!.decodedData(with: transactionOptions)
110110
guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
@@ -113,7 +113,7 @@ public class ERC1155: IERC1155 {
113113

114114
public func setApprovalForAll(from: EthereumAddress, operator user: EthereumAddress, approved: Bool, scope: Data) throws -> WriteTransaction {
115115
let contract = self.contract
116-
var basicOptions = TransactionOptions()
116+
var basicOptions = TransactionOptions.emptyTransaction
117117
basicOptions.from = from
118118
basicOptions.to = self.address
119119

@@ -123,7 +123,7 @@ public class ERC1155: IERC1155 {
123123

124124
public func isApprovedForAll(owner: EthereumAddress, operator user: EthereumAddress, scope: Data) async throws -> Bool {
125125
let contract = self.contract
126-
var basicOptions = TransactionOptions()
126+
var basicOptions = TransactionOptions.emptyTransaction
127127
basicOptions.callOnBlock = .latest
128128
let result = try await contract.read("isApprovedForAll", parameters: [owner, user, scope] as [AnyObject], extraData: Data(), transactionOptions: self.transactionOptions)!.decodedData(with: transactionOptions)
129129
guard let res = result["0"] as? Bool else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
@@ -132,7 +132,7 @@ public class ERC1155: IERC1155 {
132132

133133
public func supportsInterface(interfaceID: String) async throws -> Bool {
134134
let contract = self.contract
135-
var transactionOptions = TransactionOptions()
135+
var transactionOptions = TransactionOptions.emptyTransaction
136136
transactionOptions.callOnBlock = .latest
137137
transactionOptions.gasLimitPolicy = .manual(30000)
138138
let result = try await contract.read("supportsInterface", parameters: [interfaceID] as [AnyObject], extraData: Data(), transactionOptions: self.transactionOptions)!.decodedData(with: transactionOptions)

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

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
9797

9898
public func getBalance(account: EthereumAddress) async throws -> BigUInt {
9999
let contract = self.contract
100-
var transactionOptions = TransactionOptions()
100+
var transactionOptions = TransactionOptions.emptyTransaction
101101
transactionOptions.callOnBlock = .latest
102102
let result = try await contract.read("balanceOf", parameters: [account] as [AnyObject], extraData: Data(), transactionOptions: self.transactionOptions)!.decodedData(with: transactionOptions)
103103
guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
@@ -106,7 +106,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
106106

107107
public func getAllowance(originalOwner: EthereumAddress, delegate: EthereumAddress) async throws -> BigUInt {
108108
let contract = self.contract
109-
var transactionOptions = TransactionOptions()
109+
var transactionOptions = TransactionOptions.emptyTransaction
110110
transactionOptions.callOnBlock = .latest
111111
let result = try await contract.read("allowance", parameters: [originalOwner, delegate] as [AnyObject], extraData: Data(), transactionOptions: self.transactionOptions)!.decodedData(with: transactionOptions)
112112
guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
@@ -115,7 +115,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
115115

116116
public func transfer(from: EthereumAddress, to: EthereumAddress, amount: String) async throws -> WriteTransaction {
117117
let contract = self.contract
118-
var basicOptions = TransactionOptions()
118+
var basicOptions = TransactionOptions.emptyTransaction
119119
basicOptions.from = from
120120
basicOptions.to = self.address
121121
basicOptions.callOnBlock = .latest
@@ -137,7 +137,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
137137

138138
public func transferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, amount: String) async throws -> WriteTransaction {
139139
let contract = self.contract
140-
var basicOptions = TransactionOptions()
140+
var basicOptions = TransactionOptions.emptyTransaction
141141
basicOptions.from = from
142142
basicOptions.to = self.address
143143
basicOptions.callOnBlock = .latest
@@ -160,7 +160,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
160160

161161
public func setAllowance(from: EthereumAddress, to: EthereumAddress, newAmount: String) async throws -> WriteTransaction {
162162
let contract = self.contract
163-
var basicOptions = TransactionOptions()
163+
var basicOptions = TransactionOptions.emptyTransaction
164164
basicOptions.from = from
165165
basicOptions.to = self.address
166166
basicOptions.callOnBlock = .latest
@@ -183,7 +183,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
183183

184184
public func approve(from: EthereumAddress, spender: EthereumAddress, amount: String) async throws -> WriteTransaction {
185185
let contract = self.contract
186-
var basicOptions = TransactionOptions()
186+
var basicOptions = TransactionOptions.emptyTransaction
187187
basicOptions.from = from
188188
basicOptions.to = self.address
189189
basicOptions.callOnBlock = .latest
@@ -206,7 +206,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
206206

207207
public func totalSupply() async throws -> BigUInt {
208208
let contract = self.contract
209-
var transactionOptions = TransactionOptions()
209+
var transactionOptions = TransactionOptions.emptyTransaction
210210
transactionOptions.callOnBlock = .latest
211211
let result = try await contract.read("totalSupply", parameters: [AnyObject](), extraData: Data(), transactionOptions: self.transactionOptions)!.decodedData(with: transactionOptions)
212212
guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
@@ -215,7 +215,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
215215

216216
func approve(from: EthereumAddress, spender: EthereumAddress, expectedValue: String, newValue: String) async throws -> WriteTransaction {
217217
let contract = self.contract
218-
var basicOptions = TransactionOptions()
218+
var basicOptions = TransactionOptions.emptyTransaction
219219
basicOptions.from = from
220220
basicOptions.to = self.address
221221
basicOptions.callOnBlock = .latest
@@ -241,7 +241,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
241241

242242
func increaseAllowance(from: EthereumAddress, spender: EthereumAddress, value: String) async throws -> WriteTransaction {
243243
let contract = self.contract
244-
var basicOptions = TransactionOptions()
244+
var basicOptions = TransactionOptions.emptyTransaction
245245
basicOptions.from = from
246246
basicOptions.to = self.address
247247
basicOptions.callOnBlock = .latest
@@ -264,7 +264,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
264264

265265
func decreaseAllowance(from: EthereumAddress, spender: EthereumAddress, value: String, strict: Bool) async throws -> WriteTransaction {
266266
let contract = self.contract
267-
var basicOptions = TransactionOptions()
267+
var basicOptions = TransactionOptions.emptyTransaction
268268
basicOptions.from = from
269269
basicOptions.to = self.address
270270
basicOptions.callOnBlock = .latest
@@ -287,7 +287,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
287287

288288
func setERC20ApproveChecking(from: EthereumAddress, approveChecking: Bool) throws -> WriteTransaction {
289289
let contract = self.contract
290-
var basicOptions = TransactionOptions()
290+
var basicOptions = TransactionOptions.emptyTransaction
291291
basicOptions.from = from
292292
basicOptions.to = self.address
293293

@@ -297,7 +297,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
297297

298298
func spendableAllowance(owner: EthereumAddress, spender: EthereumAddress) async throws -> BigUInt {
299299
let contract = self.contract
300-
var transactionOptions = TransactionOptions()
300+
var transactionOptions = TransactionOptions.emptyTransaction
301301
transactionOptions.callOnBlock = .latest
302302
let result = try await contract.read("spendableAllowance", parameters: [owner, spender] as [AnyObject], extraData: Data(), transactionOptions: self.transactionOptions)!.decodedData(with: transactionOptions)
303303
guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
@@ -306,7 +306,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
306306

307307
func transfer(from: EthereumAddress, data: String) async throws -> WriteTransaction {
308308
let contract = self.contract
309-
var basicOptions = TransactionOptions()
309+
var basicOptions = TransactionOptions.emptyTransaction
310310
basicOptions.from = from
311311
basicOptions.to = self.address
312312
basicOptions.callOnBlock = .latest
@@ -328,7 +328,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
328328

329329
func transferAndCall(from: EthereumAddress, to: EthereumAddress, value: String, data: [UInt8]) async throws -> WriteTransaction {
330330
let contract = self.contract
331-
var basicOptions = TransactionOptions()
331+
var basicOptions = TransactionOptions.emptyTransaction
332332
basicOptions.from = from
333333
basicOptions.to = self.address
334334
basicOptions.callOnBlock = .latest
@@ -350,7 +350,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
350350

351351
func nonceOf(owner: EthereumAddress) async throws -> BigUInt {
352352
let contract = self.contract
353-
var transactionOptions = TransactionOptions()
353+
var transactionOptions = TransactionOptions.emptyTransaction
354354
transactionOptions.callOnBlock = .latest
355355
let result = try await contract.read("nonceOf", parameters: [owner] as [AnyObject], extraData: Data(), transactionOptions: self.transactionOptions)!.decodedData(with: transactionOptions)
356356
guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
@@ -359,7 +359,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
359359

360360
func increaseNonce(from: EthereumAddress) throws -> WriteTransaction {
361361
let contract = self.contract
362-
var basicOptions = TransactionOptions()
362+
var basicOptions = TransactionOptions.emptyTransaction
363363
basicOptions.from = from
364364
basicOptions.to = self.address
365365
basicOptions.callOnBlock = .latest
@@ -370,7 +370,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
370370

371371
func delegateTransferAndCall(from: EthereumAddress, nonce: BigUInt, fee: BigUInt, gasAmount: BigUInt, to: EthereumAddress, value: String, data: [UInt8], mode: IERC1376DelegateMode, v: UInt8, r: Data, s: Data) async throws -> WriteTransaction {
372372
let contract = self.contract
373-
var basicOptions = TransactionOptions()
373+
var basicOptions = TransactionOptions.emptyTransaction
374374
basicOptions.from = from
375375
basicOptions.to = self.address
376376
basicOptions.callOnBlock = .latest
@@ -395,7 +395,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
395395

396396
func directDebit(debtor: EthereumAddress, receiver: EthereumAddress) async throws -> DirectDebit {
397397
let contract = self.contract
398-
var transactionOptions = TransactionOptions()
398+
var transactionOptions = TransactionOptions.emptyTransaction
399399
transactionOptions.callOnBlock = .latest
400400
let result = try await contract.read("directDebit", parameters: [debtor, receiver] as [AnyObject], extraData: Data(), transactionOptions: self.transactionOptions)!.decodedData(with: transactionOptions)
401401
guard let res = result["0"] as? DirectDebit else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
@@ -404,7 +404,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
404404

405405
func setupDirectDebit(from: EthereumAddress, receiver: EthereumAddress, info: DirectDebitInfo) throws -> WriteTransaction {
406406
let contract = self.contract
407-
var basicOptions = TransactionOptions()
407+
var basicOptions = TransactionOptions.emptyTransaction
408408
basicOptions.from = from
409409
basicOptions.to = self.address
410410

@@ -414,7 +414,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
414414

415415
func terminateDirectDebit(from: EthereumAddress, receiver: EthereumAddress) throws -> WriteTransaction {
416416
let contract = self.contract
417-
var basicOptions = TransactionOptions()
417+
var basicOptions = TransactionOptions.emptyTransaction
418418
basicOptions.from = from
419419
basicOptions.to = self.address
420420

@@ -424,7 +424,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
424424

425425
func withdrawDirectDebit(from: EthereumAddress, debtor: EthereumAddress) throws -> WriteTransaction {
426426
let contract = self.contract
427-
var basicOptions = TransactionOptions()
427+
var basicOptions = TransactionOptions.emptyTransaction
428428
basicOptions.from = from
429429
basicOptions.to = self.address
430430

@@ -434,7 +434,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
434434

435435
func withdrawDirectDebit(from: EthereumAddress, debtors: [EthereumAddress], strict: Bool) throws -> WriteTransaction {
436436
let contract = self.contract
437-
var basicOptions = TransactionOptions()
437+
var basicOptions = TransactionOptions.emptyTransaction
438438
basicOptions.from = from
439439
basicOptions.to = self.address
440440

0 commit comments

Comments
 (0)