Skip to content
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

ERC20.transaction doesn't assigns to WriteOperation.transaction property fix #713

Merged
Merged
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
12 changes: 4 additions & 8 deletions Sources/web3swift/Tokens/ERC20/Web3+ERC20.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public class ERC20: IERC20, ERC20BaseProperties {
}

public func transfer(from: EthereumAddress, to: EthereumAddress, amount: String) async throws -> WriteOperation {
let contract = self.contract
self.transaction.from = from
self.transaction.to = self.address
self.transaction.callOnBlock = .latest
Expand All @@ -80,12 +79,12 @@ public class ERC20: IERC20, ERC20BaseProperties {
guard let value = Utilities.parseToBigUInt(amount, decimals: intDecimals) else {
throw Web3Error.inputError(desc: "Can not parse inputted amount")
}
contract.transaction = transaction
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we do the same in all of the functions left?
For example, check public func setAllowance. It looks almost identical to public func transfer in terms of the logic of each step inside the function: set transaction from, to and callOnBlock ; call read-only "decimals" function; create WriteOperation.

Copy link
Collaborator Author

@yaroslavyaroslav yaroslavyaroslav Dec 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is actually a bug that I've left. It's fixed just yet.

let tx = contract.createWriteOperation("transfer", parameters: [to, value] as [AnyObject] )!
return tx
}

public func transferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, amount: String) async throws -> WriteOperation {
let contract = self.contract
self.transaction.from = from
self.transaction.to = self.address
self.transaction.callOnBlock = .latest
Expand All @@ -103,13 +102,12 @@ public class ERC20: IERC20, ERC20BaseProperties {
guard let value = Utilities.parseToBigUInt(amount, decimals: intDecimals) else {
throw Web3Error.inputError(desc: "Can not parse inputted amount")
}

contract.transaction = transaction
let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, value] as [AnyObject] )!
return tx
}

public func setAllowance(from: EthereumAddress, to: EthereumAddress, newAmount: String) async throws -> WriteOperation {
let contract = self.contract
self.transaction.from = from
self.transaction.to = self.address
self.transaction.callOnBlock = .latest
Expand All @@ -127,13 +125,12 @@ public class ERC20: IERC20, ERC20BaseProperties {
guard let value = Utilities.parseToBigUInt(newAmount, decimals: intDecimals) else {
throw Web3Error.inputError(desc: "Can not parse inputted amount")
}

contract.transaction = transaction
let tx = contract.createWriteOperation("setAllowance", parameters: [to, value] as [AnyObject] )!
return tx
}

public func approve(from: EthereumAddress, spender: EthereumAddress, amount: String) async throws -> WriteOperation {
let contract = self.contract
self.transaction.from = from
self.transaction.to = self.address
self.transaction.callOnBlock = .latest
Expand All @@ -151,13 +148,12 @@ public class ERC20: IERC20, ERC20BaseProperties {
guard let value = Utilities.parseToBigUInt(amount, decimals: intDecimals) else {
throw Web3Error.inputError(desc: "Can not parse inputted amount")
}

contract.transaction = transaction
let tx = contract.createWriteOperation("approve", parameters: [spender, value] as [AnyObject] )!
return tx
}

public func totalSupply() async throws -> BigUInt {
let contract = self.contract
self.transaction.callOnBlock = .latest
let result = try await contract
.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data() )!
Expand Down