Skip to content

Commit 0fa82d7

Browse files
Delete transactionOptions from ERC specs
1 parent d977ebe commit 0fa82d7

File tree

20 files changed

+693
-903
lines changed

20 files changed

+693
-903
lines changed

Sources/web3swift/HookedFunctions/Web3+BrowserFunctions.swift

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ 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: CodableTransaction = try JSONDecoder().decode(CodableTransaction.self, from: jsonData)
78-
// var transactionOptions = CodableTransaction.emptyTransaction
79-
// transactionOptions.from = options.from
80-
// transactionOptions.to = options.to
81-
// transactionOptions.value = options.value ?? 0
82-
// transactionOptions.gasLimitPolicy = options.gasLimitPolicy ?? .automatic
83-
// transactionOptions.gasPricePolicy = options.gasPricePolicy ?? .automatic
78+
// var transaction = CodableTransaction.emptyTransaction
79+
// transaction.from = options.from
80+
// transaction.to = options.to
81+
// transaction.value = options.value ?? 0
82+
// transaction.gasLimitPolicy = options.gasLimitPolicy ?? .automatic
83+
// transaction.gasPricePolicy = options.gasPricePolicy ?? .automatic
8484
// return await self.sendTransaction(transaction , password: password)
8585
// } catch { return nil }
8686
// }
@@ -90,12 +90,12 @@ extension web3.BrowserFunctions {
9090
// let jsonData: Data = try JSONSerialization.data(withJSONObject: transactionJSON, options: [])
9191
// let transaction: CodableTransaction = try JSONDecoder().decode(CodableTransaction.self, from: jsonData)
9292
// let options: CodableTransaction = try JSONDecoder().decode(CodableTransaction.self, from: jsonData)
93-
// var transactionOptions = CodableTransaction.emptyTransaction
94-
// transactionOptions.from = options.from
95-
// transactionOptions.to = options.to
96-
// transactionOptions.value = options.value ?? 0
97-
// transactionOptions.gasLimitPolicy = .automatic
98-
// transactionOptions.gasPricePolicy = options.gasPricePolicy ?? .automatic
93+
// var transaction = CodableTransaction.emptyTransaction
94+
// transaction.from = options.from
95+
// transaction.to = options.to
96+
// transaction.value = options.value ?? 0
97+
// transaction.gasLimitPolicy = .automatic
98+
// transaction.gasPricePolicy = options.gasPricePolicy ?? .automatic
9999
// return await self.estimateGas(transaction )
100100
// } catch { return nil }
101101
// }
@@ -148,30 +148,30 @@ extension web3.BrowserFunctions {
148148
// let jsonData: Data = try JSONSerialization.data(withJSONObject: transactionJSON, options: [])
149149
// let transaction: EthereumTransaction = try JSONDecoder().decode(EthereumTransaction.self, from: jsonData)
150150
// let options: CodableTransaction = try JSONDecoder().decode(TransactionOptions.self, from: jsonData)
151-
// var transactionOptions = TransactionOptions.emptyTransaction
152-
// transactionOptions.from = options.from
153-
// transactionOptions.to = options.to
154-
// transactionOptions.value = options.value ?? 0
155-
// transactionOptions.gasLimitPolicy = options.gasLimit ?? .automatic
156-
// transactionOptions.gasPricePolicy = options.gasPrice ?? .automatic
151+
// var transaction = TransactionOptions.emptyTransaction
152+
// transaction.from = options.from
153+
// transaction.to = options.to
154+
// transaction.value = options.value ?? 0
155+
// transaction.gasLimitPolicy = options.gasLimit ?? .automatic
156+
// transaction.gasPricePolicy = options.gasPrice ?? .automatic
157157
// if let nonceString = transactionJSON["nonce"] as? String, let nonce = BigUInt(nonceString.stripHexPrefix(), radix: 16) {
158-
// transactionOptions.nonce = .manual(nonce)
158+
// transaction.nonce = .manual(nonce)
159159
// } else {
160-
// transactionOptions.nonce = .pending
160+
// transaction.nonce = .pending
161161
// }
162162
// return await self.signTransaction(transaction , password: password)
163163
// } catch { return nil }
164164
// }
165165

166166
// FIXME: Rewrite this to EthereumTransaction
167-
// public func signTransaction(_ trans: EthereumTransaction, transactionOptions: TransactionOptions, password: String ) async -> String? {
167+
// public func signTransaction(_ trans: EthereumTransaction, transaction: TransactionOptions, password: String ) async -> String? {
168168
// do {
169169
// var transaction = trans
170-
// guard let from = transactionOptions.from else {return nil}
170+
// guard let from = transaction.from else {return nil}
171171
// guard let keystoreManager = self.web3.provider.attachedKeystoreManager else {return nil}
172-
// guard let gasPricePolicy = transactionOptions.gasPrice else {return nil}
173-
// guard let gasLimitPolicy = transactionOptions.gasLimit else {return nil}
174-
// guard let noncePolicy = transactionOptions.nonce else {return nil}
172+
// guard let gasPricePolicy = transaction.gasPrice else {return nil}
173+
// guard let gasLimitPolicy = transaction.gasLimit else {return nil}
174+
// guard let noncePolicy = transaction.nonce else {return nil}
175175
// switch gasPricePolicy {
176176
// case .manual(let gasPrice):
177177
// transaction.parameters.gasPrice = gasPrice

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

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class ERC1155: IERC1155 {
3535
private var _tokenId: BigUInt? = nil
3636
private var _hasReadProperties: Bool = false
3737

38-
public var transactionOptions: CodableTransaction
38+
public var transaction: CodableTransaction
3939
public var web3: web3
4040
public var provider: Web3Provider
4141
public var address: EthereumAddress
@@ -51,8 +51,8 @@ public class ERC1155: IERC1155 {
5151
self.web3 = web3
5252
self.provider = provider
5353
self.address = address
54-
self.transactionOptions = transaction
55-
self.transactionOptions.to = address
54+
self.transaction = transaction
55+
self.transaction.to = address
5656
self.abi = abi
5757
}
5858

@@ -70,8 +70,7 @@ public class ERC1155: IERC1155 {
7070
}
7171
let contract = self.contract
7272
guard contract.contract.address != nil else {return}
73-
var transactionOptions = CodableTransaction.emptyTransaction
74-
transactionOptions.callOnBlock = .latest
73+
self.transaction.callOnBlock = .latest
7574

7675
guard let tokenIdPromise = try await contract.createReadOperation("id", parameters: [] as [AnyObject], extraData: Data())?.callContractMethod() else {return}
7776

@@ -83,19 +82,17 @@ public class ERC1155: IERC1155 {
8382

8483
public func safeTransferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, id: BigUInt, value: BigUInt, data: [UInt8]) throws -> WriteOperation {
8584
let contract = self.contract
86-
var basicOptions = CodableTransaction.emptyTransaction
87-
basicOptions.from = from
88-
basicOptions.to = self.address
85+
self.transaction.from = from
86+
self.transaction.to = self.address
8987

9088
let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, id, value, data] as [AnyObject] )!
9189
return tx
9290
}
9391

9492
public func safeBatchTransferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, ids: [BigUInt], values: [BigUInt], data: [UInt8]) throws -> WriteOperation {
9593
let contract = self.contract
96-
var basicOptions = CodableTransaction.emptyTransaction
97-
basicOptions.from = from
98-
basicOptions.to = self.address
94+
self.transaction.from = from
95+
self.transaction.to = self.address
9996

10097
let tx = contract
10198
.createWriteOperation("safeBatchTransferFrom", parameters: [originalOwner, to, ids, values, data] as [AnyObject] )!
@@ -104,8 +101,7 @@ public class ERC1155: IERC1155 {
104101

105102
public func balanceOf(account: EthereumAddress, id: BigUInt) async throws -> BigUInt {
106103
let contract = self.contract
107-
var transactionOptions = CodableTransaction.emptyTransaction
108-
transactionOptions.callOnBlock = .latest
104+
self.transaction.callOnBlock = .latest
109105
let result = try await contract
110106
.createReadOperation("balanceOf", parameters: [account, id] as [AnyObject], extraData: Data() )!
111107
.callContractMethod()
@@ -123,28 +119,25 @@ public class ERC1155: IERC1155 {
123119

124120
public func setApprovalForAll(from: EthereumAddress, operator user: EthereumAddress, approved: Bool, scope: Data) throws -> WriteOperation {
125121
let contract = self.contract
126-
var basicOptions = CodableTransaction.emptyTransaction
127-
basicOptions.from = from
128-
basicOptions.to = self.address
122+
self.transaction.from = from
123+
self.transaction.to = self.address
129124

130125
let tx = contract.createWriteOperation("setApprovalForAll", parameters: [user, approved, scope] as [AnyObject] )!
131126
return tx
132127
}
133128

134129
public func isApprovedForAll(owner: EthereumAddress, operator user: EthereumAddress, scope: Data) async throws -> Bool {
135130
let contract = self.contract
136-
var basicOptions = CodableTransaction.emptyTransaction
137-
basicOptions.callOnBlock = .latest
131+
self.transaction.callOnBlock = .latest
138132
let result = try await contract.createReadOperation("isApprovedForAll", parameters: [owner, user, scope] as [AnyObject], extraData: Data() )!.callContractMethod()
139133
guard let res = result["0"] as? Bool else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
140134
return res
141135
}
142136

143137
public func supportsInterface(interfaceID: String) async throws -> Bool {
144138
let contract = self.contract
145-
var transactionOptions = CodableTransaction.emptyTransaction
146-
transactionOptions.callOnBlock = .latest
147-
transactionOptions.gasLimitPolicy = .manual(30000)
139+
self.transaction.callOnBlock = .latest
140+
self.transaction.gasLimitPolicy = .manual(30000)
148141
let result = try await contract.createReadOperation("supportsInterface", parameters: [interfaceID] as [AnyObject], extraData: Data() )!.callContractMethod()
149142
guard let res = result["0"] as? Bool else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
150143
return res

0 commit comments

Comments
 (0)