@@ -110,55 +110,37 @@ public class ERC721x: IERC721x {
110
110
}
111
111
112
112
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)
117
114
let tx = contract. createWriteOperation ( " transfer " , parameters: [ to, tokenId] as [ AnyObject ] ) !
118
115
return tx
119
116
}
120
117
121
118
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)
126
120
let tx = contract. createWriteOperation ( " transferFrom " , parameters: [ originalOwner, to, tokenId] as [ AnyObject ] ) !
127
121
return tx
128
122
}
129
123
130
124
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)
135
126
let tx = contract. createWriteOperation ( " safeTransferFrom " , parameters: [ originalOwner, to, tokenId] as [ AnyObject ] ) !
136
127
return tx
137
128
}
138
129
139
130
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)
144
132
let tx = contract. createWriteOperation ( " safeTransferFrom " , parameters: [ originalOwner, to, tokenId, data] as [ AnyObject ] ) !
145
133
return tx
146
134
}
147
135
148
136
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)
153
138
let tx = contract. createWriteOperation ( " approve " , parameters: [ approved, tokenId] as [ AnyObject ] ) !
154
139
return tx
155
140
}
156
141
157
142
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)
162
144
let tx = contract. createWriteOperation ( " setApprovalForAll " , parameters: [ user, approved] as [ AnyObject ] ) !
163
145
return tx
164
146
}
@@ -252,47 +234,44 @@ public class ERC721x: IERC721x {
252
234
}
253
235
254
236
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)
259
238
let tx = contract. createWriteOperation ( " transfer " , parameters: [ to, tokenId, quantity] as [ AnyObject ] ) !
260
239
return tx
261
240
}
262
241
263
242
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)
268
244
let tx = contract. createWriteOperation ( " transferFrom " , parameters: [ originalOwner, to, tokenId, quantity] as [ AnyObject ] ) !
269
245
return tx
270
246
}
271
247
272
248
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)
277
250
let tx = contract. createWriteOperation ( " safeTransferFrom " , parameters: [ originalOwner, to, tokenId, amount] as [ AnyObject ] ) !
278
251
return tx
279
252
}
280
253
281
254
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)
286
256
let tx = contract. createWriteOperation ( " safeTransferFrom " , parameters: [ originalOwner, to, tokenId, amount, data] as [ AnyObject ] ) !
287
257
return tx
288
258
}
289
259
290
260
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)
295
262
let tx = contract. createWriteOperation ( " safeTransferFrom " , parameters: [ originalOwner, to, tokenIds, amounts, data] as [ AnyObject ] ) !
296
263
return tx
297
264
}
298
265
}
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