Skip to content

Fix remaining no tx assigns #715

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 22 additions & 28 deletions Sources/web3swift/Tokens/ERC1155/Web3+ERC1155.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ public class ERC1155: IERC1155 {
if self._hasReadProperties {
return
}
let contract = self.contract
guard contract.contract.address != nil else {return}
self.transaction.callOnBlock = .latest

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

Expand All @@ -80,34 +78,25 @@ public class ERC1155: IERC1155 {
}

public func safeTransferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, id: BigUInt, value: BigUInt, data: [UInt8]) throws -> WriteOperation {
let contract = self.contract
self.transaction.from = from
self.transaction.to = self.address

let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, id, value, data] as [AnyObject] )!
updateTransactionAndContract(from: from)
let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, id, value, data] as [AnyObject])!
return tx
}

public func safeBatchTransferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, ids: [BigUInt], values: [BigUInt], data: [UInt8]) throws -> WriteOperation {
let contract = self.contract
self.transaction.from = from
self.transaction.to = self.address

updateTransactionAndContract(from: from)
let tx = contract
.createWriteOperation("safeBatchTransferFrom", parameters: [originalOwner, to, ids, values, data] as [AnyObject] )!
.createWriteOperation("safeBatchTransferFrom", parameters: [originalOwner, to, ids, values, data] as [AnyObject])!
return tx
}

public func balanceOf(account: EthereumAddress, id: BigUInt) async throws -> BigUInt {
let contract = self.contract
self.transaction.callOnBlock = .latest
let result = try await contract
.createReadOperation("balanceOf", parameters: [account, id] as [AnyObject], extraData: Data() )!
.createReadOperation("balanceOf", parameters: [account, id] as [AnyObject], extraData: Data())!
.callContractMethod()

/*
let result = try await contract
.prepareToRead("balanceOf", parameters: [account, id] as [AnyObject], extraData: Data() )!
.prepareToRead("balanceOf", parameters: [account, id] as [AnyObject], extraData: Data())!
.execute()
.decodeData()

Expand All @@ -117,27 +106,32 @@ public class ERC1155: IERC1155 {
}

public func setApprovalForAll(from: EthereumAddress, operator user: EthereumAddress, approved: Bool, scope: Data) throws -> WriteOperation {
let contract = self.contract
self.transaction.from = from
self.transaction.to = self.address

let tx = contract.createWriteOperation("setApprovalForAll", parameters: [user, approved, scope] as [AnyObject] )!
updateTransactionAndContract(from: from)
let tx = contract.createWriteOperation("setApprovalForAll", parameters: [user, approved, scope] as [AnyObject])!
return tx
}

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

public func supportsInterface(interfaceID: String) async throws -> Bool {
let contract = self.contract
self.transaction.callOnBlock = .latest
let result = try await contract.createReadOperation("supportsInterface", parameters: [interfaceID] as [AnyObject], extraData: Data() )!.callContractMethod()
let result = try await contract.createReadOperation("supportsInterface", parameters: [interfaceID] as [AnyObject], extraData: Data())!.callContractMethod()
guard let res = result["0"] as? Bool else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
return res
}
}

// MARK: - Private

extension ERC1155 {

private func updateTransactionAndContract(from: EthereumAddress) {
transaction.from = from
transaction.to = address
contract.transaction = transaction
}

}
Loading