From a0e0f86c2a8d715391f43dbc833ff415bcc58c55 Mon Sep 17 00:00:00 2001 From: Alex Vlasov Date: Sat, 21 Apr 2018 01:53:09 +0300 Subject: [PATCH] convenience methods in web3.eth to send ETH using either raw BigUInt value in Wei, or parsing a decimal string of arbitrary units --- web3swift/Web3/Classes/Web3+Eth.swift | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/web3swift/Web3/Classes/Web3+Eth.swift b/web3swift/Web3/Classes/Web3+Eth.swift index 6e39336..3e044fe 100644 --- a/web3swift/Web3/Classes/Web3+Eth.swift +++ b/web3swift/Web3/Classes/Web3+Eth.swift @@ -293,7 +293,7 @@ extension web3.Eth { } public func estimateGas(_ transaction: EthereumTransaction, options: Web3Options?, onBlock: String = "latest") -> Result { - 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")) } @@ -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 + } }