Skip to content

Commit 0595214

Browse files
committed
Fix ERC1155
1 parent 2d38fd0 commit 0595214

File tree

1 file changed

+25
-27
lines changed

1 file changed

+25
-27
lines changed

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

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,8 @@ public class ERC1155: IERC1155 {
6767
if self._hasReadProperties {
6868
return
6969
}
70-
let contract = self.contract
7170
guard contract.contract.address != nil else {return}
72-
self.transaction.callOnBlock = .latest
71+
transaction.callOnBlock = .latest
7372

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

@@ -80,31 +79,23 @@ public class ERC1155: IERC1155 {
8079
}
8180

8281
public func safeTransferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, id: BigUInt, value: BigUInt, data: [UInt8]) throws -> WriteOperation {
83-
let contract = self.contract
84-
self.transaction.from = from
85-
self.transaction.to = self.address
86-
87-
let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, id, value, data] as [AnyObject] )!
82+
updateTransactionAndContract(from: from)
83+
let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, id, value, data] as [AnyObject])!
8884
return tx
8985
}
9086

9187
public func safeBatchTransferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, ids: [BigUInt], values: [BigUInt], data: [UInt8]) throws -> WriteOperation {
92-
let contract = self.contract
93-
self.transaction.from = from
94-
self.transaction.to = self.address
95-
88+
updateTransactionAndContract(from: from)
9689
let tx = contract
97-
.createWriteOperation("safeBatchTransferFrom", parameters: [originalOwner, to, ids, values, data] as [AnyObject] )!
90+
.createWriteOperation("safeBatchTransferFrom", parameters: [originalOwner, to, ids, values, data] as [AnyObject])!
9891
return tx
9992
}
10093

10194
public func balanceOf(account: EthereumAddress, id: BigUInt) async throws -> BigUInt {
102-
let contract = self.contract
103-
self.transaction.callOnBlock = .latest
95+
transaction.callOnBlock = .latest
10496
let result = try await contract
105-
.createReadOperation("balanceOf", parameters: [account, id] as [AnyObject], extraData: Data() )!
97+
.createReadOperation("balanceOf", parameters: [account, id] as [AnyObject], extraData: Data())!
10698
.callContractMethod()
107-
10899
/*
109100
let result = try await contract
110101
.prepareToRead("balanceOf", parameters: [account, id] as [AnyObject], extraData: Data() )!
@@ -117,27 +108,34 @@ public class ERC1155: IERC1155 {
117108
}
118109

119110
public func setApprovalForAll(from: EthereumAddress, operator user: EthereumAddress, approved: Bool, scope: Data) throws -> WriteOperation {
120-
let contract = self.contract
121-
self.transaction.from = from
122-
self.transaction.to = self.address
123-
124-
let tx = contract.createWriteOperation("setApprovalForAll", parameters: [user, approved, scope] as [AnyObject] )!
111+
updateTransactionAndContract(from: from)
112+
let tx = contract.createWriteOperation("setApprovalForAll", parameters: [user, approved, scope] as [AnyObject])!
125113
return tx
126114
}
127115

128116
public func isApprovedForAll(owner: EthereumAddress, operator user: EthereumAddress, scope: Data) async throws -> Bool {
129-
let contract = self.contract
130-
self.transaction.callOnBlock = .latest
131-
let result = try await contract.createReadOperation("isApprovedForAll", parameters: [owner, user, scope] as [AnyObject], extraData: Data() )!.callContractMethod()
117+
transaction.callOnBlock = .latest
118+
let result = try await contract.createReadOperation("isApprovedForAll", parameters: [owner, user, scope] as [AnyObject], extraData: Data())!.callContractMethod()
132119
guard let res = result["0"] as? Bool else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
133120
return res
134121
}
135122

136123
public func supportsInterface(interfaceID: String) async throws -> Bool {
137-
let contract = self.contract
138-
self.transaction.callOnBlock = .latest
139-
let result = try await contract.createReadOperation("supportsInterface", parameters: [interfaceID] as [AnyObject], extraData: Data() )!.callContractMethod()
124+
transaction.callOnBlock = .latest
125+
let result = try await contract.createReadOperation("supportsInterface", parameters: [interfaceID] as [AnyObject], extraData: Data())!.callContractMethod()
140126
guard let res = result["0"] as? Bool else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
141127
return res
142128
}
143129
}
130+
131+
// MARK: - Private
132+
133+
extension ERC1155 {
134+
135+
private func updateTransactionAndContract(from: EthereumAddress) {
136+
transaction.from = from
137+
transaction.to = address
138+
contract.transaction = transaction
139+
}
140+
141+
}

0 commit comments

Comments
 (0)