@@ -85,7 +85,6 @@ public class ERC721: IERC721 {
85
85
}
86
86
87
87
public func readProperties( ) async throws {
88
-
89
88
if self . _hasReadProperties {
90
89
return
91
90
}
@@ -128,56 +127,38 @@ public class ERC721: IERC721 {
128
127
}
129
128
130
129
public func transfer( from: EthereumAddress , to: EthereumAddress , tokenId: BigUInt ) throws -> WriteOperation {
131
- let contract = self . contract
132
- self . transaction. from = from
133
- self . transaction. to = self . address
134
-
135
- let tx = contract. createWriteOperation ( " transfer " , parameters: [ to, tokenId] as [ AnyObject ] ) !
130
+ updateTransactionAndContract ( from: from)
131
+ let tx = contract. createWriteOperation ( " transfer " , parameters: [ to, tokenId] as [ AnyObject ] ) !
136
132
return tx
137
133
}
138
134
139
135
public func transferFrom( from: EthereumAddress , to: EthereumAddress , originalOwner: EthereumAddress , tokenId: BigUInt ) throws -> WriteOperation {
140
- let contract = self . contract
141
- self . transaction. from = from
142
- self . transaction. to = self . address
143
-
144
- let tx = contract. createWriteOperation ( " transferFrom " , parameters: [ originalOwner, to, tokenId] as [ AnyObject ] ) !
136
+ updateTransactionAndContract ( from: from)
137
+ let tx = contract. createWriteOperation ( " transferFrom " , parameters: [ originalOwner, to, tokenId] as [ AnyObject ] ) !
145
138
return tx
146
139
}
147
140
148
141
public func safeTransferFrom( from: EthereumAddress , to: EthereumAddress , originalOwner: EthereumAddress , tokenId: BigUInt ) throws -> WriteOperation {
149
- let contract = self . contract
150
- self . transaction. from = from
151
- self . transaction. to = self . address
152
-
153
- let tx = contract. createWriteOperation ( " safeTransferFrom " , parameters: [ originalOwner, to, tokenId] as [ AnyObject ] ) !
142
+ updateTransactionAndContract ( from: from)
143
+ let tx = contract. createWriteOperation ( " safeTransferFrom " , parameters: [ originalOwner, to, tokenId] as [ AnyObject ] ) !
154
144
return tx
155
145
}
156
146
157
147
public func safeTransferFrom( from: EthereumAddress , to: EthereumAddress , originalOwner: EthereumAddress , tokenId: BigUInt , data: [ UInt8 ] ) throws -> WriteOperation {
158
- let contract = self . contract
159
- self . transaction. from = from
160
- self . transaction. to = self . address
161
-
162
- let tx = contract. createWriteOperation ( " safeTransferFrom " , parameters: [ originalOwner, to, tokenId, data] as [ AnyObject ] ) !
148
+ updateTransactionAndContract ( from: from)
149
+ let tx = contract. createWriteOperation ( " safeTransferFrom " , parameters: [ originalOwner, to, tokenId, data] as [ AnyObject ] ) !
163
150
return tx
164
151
}
165
152
166
153
public func approve( from: EthereumAddress , approved: EthereumAddress , tokenId: BigUInt ) throws -> WriteOperation {
167
- let contract = self . contract
168
- self . transaction. from = from
169
- self . transaction. to = self . address
170
-
171
- let tx = contract. createWriteOperation ( " approve " , parameters: [ approved, tokenId] as [ AnyObject ] ) !
154
+ updateTransactionAndContract ( from: from)
155
+ let tx = contract. createWriteOperation ( " approve " , parameters: [ approved, tokenId] as [ AnyObject ] ) !
172
156
return tx
173
157
}
174
158
175
159
public func setApprovalForAll( from: EthereumAddress , operator user: EthereumAddress , approved: Bool ) throws -> WriteOperation {
176
- let contract = self . contract
177
- self . transaction. from = from
178
- self . transaction. to = self . address
179
-
180
- let tx = contract. createWriteOperation ( " setApprovalForAll " , parameters: [ user, approved] as [ AnyObject ] ) !
160
+ updateTransactionAndContract ( from: from)
161
+ let tx = contract. createWriteOperation ( " setApprovalForAll " , parameters: [ user, approved] as [ AnyObject ] ) !
181
162
return tx
182
163
}
183
164
@@ -199,6 +180,20 @@ public class ERC721: IERC721 {
199
180
200
181
}
201
182
183
+ // MARK: - Private
184
+
185
+ extension ERC721 {
186
+
187
+ private func updateTransactionAndContract( from: EthereumAddress ) {
188
+ transaction. from = from
189
+ transaction. to = address
190
+ contract. transaction = transaction
191
+ }
192
+
193
+ }
194
+
195
+ // MARK: - IERC721Enumerable
196
+
202
197
extension ERC721 : IERC721Enumerable {
203
198
204
199
public func totalSupply( ) async throws -> BigUInt {
@@ -227,6 +222,8 @@ extension ERC721: IERC721Enumerable {
227
222
228
223
}
229
224
225
+ // MARK: - IERC721Metadata
226
+
230
227
// FIXME: Rewrite this to CodableTransaction
231
228
extension ERC721 : IERC721Metadata {
232
229
0 commit comments