Skip to content
This repository has been archived by the owner on Sep 13, 2024. It is now read-only.

convenience methods in web3.eth to send ETH using either raw BigUInt value in Wei, or parsing a decimal string of arbitrary units #72

Merged
merged 1 commit into from
Apr 20, 2018
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
18 changes: 17 additions & 1 deletion web3swift/Web3/Classes/Web3+Eth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ extension web3.Eth {
}

public func estimateGas(_ transaction: EthereumTransaction, options: Web3Options?, onBlock: String = "latest") -> Result<BigUInt, Web3Error> {
let mergedOptions = Web3Options.merge(Web3Options.defaultOptions(), with: options)
let mergedOptions = Web3Options.merge(self.options, with: options)
guard let request = EthereumTransaction.createRequest(method: JSONRPCmethod.estimateGas, transaction: transaction, onBlock: onBlock, options: mergedOptions) else {
return Result.failure(Web3Error.inputError("Transaction serialization failed"))
}
Expand Down Expand Up @@ -430,5 +430,21 @@ extension web3.Eth {
return Result(block)
}
}
public func sendETH(to: EthereumAddress, amount: BigUInt, extraData: Data = Data(), options: Web3Options? = nil) -> TransactionIntermediate? {
let contract = self.web3.contract(Web3.Utils.coldWalletABI, at: to, abiVersion: 2)
guard var mergedOptions = Web3Options.merge(self.options, with: options) else {return nil}
mergedOptions.value = amount
let intermediate = contract?.method("fallback", extraData: extraData, options: mergedOptions)
return intermediate
}

public func sendETH(to: EthereumAddress, amount: String, units: Web3.Utils.Units = .eth, extraData: Data = Data(), options: Web3Options? = nil) -> TransactionIntermediate? {
let contract = self.web3.contract(Web3.Utils.coldWalletABI, at: to, abiVersion: 2)
guard var mergedOptions = Web3Options.merge(self.options, with: options) else {return nil}
guard let value = Web3.Utils.parseToBigUInt(amount, units: .eth) else {return nil}
mergedOptions.value = value
let intermediate = contract?.method("fallback", extraData: extraData, options: mergedOptions)
return intermediate
}

}