Skip to content

Commit 10f51bb

Browse files
committed
Fix ERC721x
1 parent 96b6462 commit 10f51bb

File tree

1 file changed

+23
-44
lines changed

1 file changed

+23
-44
lines changed

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

Lines changed: 23 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -110,55 +110,37 @@ public class ERC721x: IERC721x {
110110
}
111111

112112
public func transfer(from: EthereumAddress, to: EthereumAddress, tokenId: BigUInt) throws -> WriteOperation {
113-
let contract = self.contract
114-
self.transaction.from = from
115-
self.transaction.to = self.address
116-
113+
updateTransactionAndContract(from: from)
117114
let tx = contract.createWriteOperation("transfer", parameters: [to, tokenId] as [AnyObject] )!
118115
return tx
119116
}
120117

121118
public func transferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, tokenId: BigUInt) throws -> WriteOperation {
122-
let contract = self.contract
123-
self.transaction.from = from
124-
self.transaction.to = self.address
125-
119+
updateTransactionAndContract(from: from)
126120
let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, tokenId] as [AnyObject] )!
127121
return tx
128122
}
129123

130124
public func safeTransferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, tokenId: BigUInt) throws -> WriteOperation {
131-
let contract = self.contract
132-
self.transaction.from = from
133-
self.transaction.to = self.address
134-
125+
updateTransactionAndContract(from: from)
135126
let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId] as [AnyObject] )!
136127
return tx
137128
}
138129

139130
public func safeTransferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, tokenId: BigUInt, data: [UInt8]) throws -> WriteOperation {
140-
let contract = self.contract
141-
self.transaction.from = from
142-
self.transaction.to = self.address
143-
131+
updateTransactionAndContract(from: from)
144132
let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId, data] as [AnyObject] )!
145133
return tx
146134
}
147135

148136
public func approve(from: EthereumAddress, approved: EthereumAddress, tokenId: BigUInt) throws -> WriteOperation {
149-
let contract = self.contract
150-
self.transaction.from = from
151-
self.transaction.to = self.address
152-
137+
updateTransactionAndContract(from: from)
153138
let tx = contract.createWriteOperation("approve", parameters: [approved, tokenId] as [AnyObject] )!
154139
return tx
155140
}
156141

157142
public func setApprovalForAll(from: EthereumAddress, operator user: EthereumAddress, approved: Bool) throws -> WriteOperation {
158-
let contract = self.contract
159-
self.transaction.from = from
160-
self.transaction.to = self.address
161-
143+
updateTransactionAndContract(from: from)
162144
let tx = contract.createWriteOperation("setApprovalForAll", parameters: [user, approved] as [AnyObject] )!
163145
return tx
164146
}
@@ -252,47 +234,44 @@ public class ERC721x: IERC721x {
252234
}
253235

254236
func transfer(from: EthereumAddress, to: EthereumAddress, tokenId: BigUInt, quantity: BigUInt) throws -> WriteOperation {
255-
let contract = self.contract
256-
self.transaction.from = from
257-
self.transaction.to = self.address
258-
237+
updateTransactionAndContract(from: from)
259238
let tx = contract.createWriteOperation("transfer", parameters: [to, tokenId, quantity] as [AnyObject] )!
260239
return tx
261240
}
262241

263242
func transferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, tokenId: BigUInt, quantity: BigUInt) throws -> WriteOperation {
264-
let contract = self.contract
265-
self.transaction.from = from
266-
self.transaction.to = self.address
267-
243+
updateTransactionAndContract(from: from)
268244
let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, tokenId, quantity] as [AnyObject] )!
269245
return tx
270246
}
271247

272248
func safeTransferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, tokenId: BigUInt, amount: BigUInt) throws -> WriteOperation {
273-
let contract = self.contract
274-
self.transaction.from = from
275-
self.transaction.to = self.address
276-
249+
updateTransactionAndContract(from: from)
277250
let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId, amount] as [AnyObject] )!
278251
return tx
279252
}
280253

281254
func safeTransferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, tokenId: BigUInt, amount: BigUInt, data: [UInt8]) throws -> WriteOperation {
282-
let contract = self.contract
283-
self.transaction.from = from
284-
self.transaction.to = self.address
285-
255+
updateTransactionAndContract(from: from)
286256
let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId, amount, data] as [AnyObject] )!
287257
return tx
288258
}
289259

290260
func safeTransferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, tokenIds: [BigUInt], amounts: [BigUInt], data: [UInt8]) throws -> WriteOperation {
291-
let contract = self.contract
292-
self.transaction.from = from
293-
self.transaction.to = self.address
294-
261+
updateTransactionAndContract(from: from)
295262
let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenIds, amounts, data] as [AnyObject] )!
296263
return tx
297264
}
298265
}
266+
267+
// MARK: - Private
268+
269+
extension ERC721x {
270+
271+
private func updateTransactionAndContract(from: EthereumAddress) {
272+
transaction.from = from
273+
transaction.to = address
274+
contract.transaction = transaction
275+
}
276+
277+
}

0 commit comments

Comments
 (0)