Skip to content

Commit 0f144dd

Browse files
small refactor
1 parent 871bf2d commit 0f144dd

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

web3swift/PrecompiledContracts/ERC721/Web3+ERC721.swift

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ protocol IERC721Enumerable {
4949

5050
// This namespace contains functions to work with ERC721 tokens.
5151
// can be imperatively read and saved
52-
public class ERC721: IERC721, IERC721Enumerable, IERC721Metadata {
52+
public class ERC721: IERC721 {
5353

5454
@available(*, deprecated, renamed: "transactionOptions")
5555
public var options: Web3Options = .init()
@@ -134,24 +134,6 @@ public class ERC721: IERC721, IERC721Enumerable, IERC721Metadata {
134134
return res
135135
}
136136

137-
public func tokenByIndex(index: BigUInt) throws -> BigUInt {
138-
let contract = self.contract
139-
var transactionOptions = TransactionOptions()
140-
transactionOptions.callOnBlock = .latest
141-
let result = try contract.read("tokenByIndex", parameters: [index] as [AnyObject], extraData: Data(), transactionOptions: self.transactionOptions)!.call(transactionOptions: transactionOptions)
142-
guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
143-
return res
144-
}
145-
146-
public func tokenOfOwnerByIndex(owner: EthereumAddress, index: BigUInt) throws -> BigUInt {
147-
let contract = self.contract
148-
var transactionOptions = TransactionOptions()
149-
transactionOptions.callOnBlock = .latest
150-
let result = try contract.read("tokenOfOwnerByIndex", parameters: [owner, index] as [AnyObject], extraData: Data(), transactionOptions: self.transactionOptions)!.call(transactionOptions: transactionOptions)
151-
guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
152-
return res
153-
}
154-
155137
public func transfer(from: EthereumAddress, to: EthereumAddress, tokenId: BigUInt) throws -> WriteTransaction {
156138
let contract = self.contract
157139
var basicOptions = TransactionOptions()
@@ -199,6 +181,10 @@ public class ERC721: IERC721, IERC721Enumerable, IERC721Metadata {
199181
return res
200182
}
201183

184+
}
185+
186+
extension ERC721: IERC721Enumerable {
187+
202188
public func totalSupply() throws -> BigUInt {
203189
let contract = self.contract
204190
var transactionOptions = TransactionOptions()
@@ -208,6 +194,28 @@ public class ERC721: IERC721, IERC721Enumerable, IERC721Metadata {
208194
return res
209195
}
210196

197+
public func tokenByIndex(index: BigUInt) throws -> BigUInt {
198+
let contract = self.contract
199+
var transactionOptions = TransactionOptions()
200+
transactionOptions.callOnBlock = .latest
201+
let result = try contract.read("tokenByIndex", parameters: [index] as [AnyObject], extraData: Data(), transactionOptions: self.transactionOptions)!.call(transactionOptions: transactionOptions)
202+
guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
203+
return res
204+
}
205+
206+
public func tokenOfOwnerByIndex(owner: EthereumAddress, index: BigUInt) throws -> BigUInt {
207+
let contract = self.contract
208+
var transactionOptions = TransactionOptions()
209+
transactionOptions.callOnBlock = .latest
210+
let result = try contract.read("tokenOfOwnerByIndex", parameters: [owner, index] as [AnyObject], extraData: Data(), transactionOptions: self.transactionOptions)!.call(transactionOptions: transactionOptions)
211+
guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
212+
return res
213+
}
214+
215+
}
216+
217+
extension ERC721: IERC721Metadata {
218+
211219
public func name() throws -> String {
212220
let contract = self.contract
213221
var transactionOptions = TransactionOptions()
@@ -234,4 +242,5 @@ public class ERC721: IERC721, IERC721Enumerable, IERC721Metadata {
234242
guard let res = result["0"] as? String else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
235243
return res
236244
}
245+
237246
}

0 commit comments

Comments
 (0)