Skip to content
This repository has been archived by the owner on Oct 28, 2022. It is now read-only.

Commit

Permalink
Ability to make eth_estimateGas call with "to" parameter set to null
Browse files Browse the repository at this point in the history
  • Loading branch information
esen committed Oct 27, 2020
1 parent 9e26fac commit 70c5612
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion EthereumKit/Classes/Api/Core/RpcBlockchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ extension RpcBlockchain: IBlockchain {
syncer.single(rpc: CallJsonRpc(contractAddress: contractAddress, data: data, defaultBlockParameter: defaultBlockParameter))
}

func estimateGas(to: Address, amount: BigUInt?, gasLimit: Int?, gasPrice: Int?, data: Data?) -> Single<Int> {
func estimateGas(to: Address?, amount: BigUInt?, gasLimit: Int?, gasPrice: Int?, data: Data?) -> Single<Int> {
syncer.single(rpc: EstimateGasJsonRpc(from: address, to: to, amount: amount, gasLimit: gasLimit, gasPrice: gasPrice, data: data))
}

Expand Down
8 changes: 5 additions & 3 deletions EthereumKit/Classes/Api/JsonRpc/EstimateGasJsonRpc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import BigInt

class EstimateGasJsonRpc: IntJsonRpc {

init(from: Address, to: Address, amount: BigUInt?, gasLimit: Int?, gasPrice: Int?, data: Data?) {
init(from: Address, to: Address?, amount: BigUInt?, gasLimit: Int?, gasPrice: Int?, data: Data?) {
var params: [String: Any] = [
"from": from.hex,
"to": to.hex
"from": from.hex
]

if let to = to {
params["to"] = to.hex
}
if let amount = amount {
params["value"] = "0x" + amount.serialize().hex.removeLeadingZeros()
}
Expand Down
2 changes: 1 addition & 1 deletion EthereumKit/Classes/Core/Kit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ extension Kit {
return blockchain.estimateGas(to: to, amount: resolvedAmount, gasLimit: maxGasLimit, gasPrice: gasPrice, data: nil)
}

public func estimateGas(to: Address, amount: BigUInt?, gasPrice: Int?, data: Data?) -> Single<Int> {
public func estimateGas(to: Address?, amount: BigUInt?, gasPrice: Int?, data: Data?) -> Single<Int> {
blockchain.estimateGas(to: to, amount: amount, gasLimit: maxGasLimit, gasPrice: gasPrice, data: data)
}

Expand Down
2 changes: 1 addition & 1 deletion EthereumKit/Classes/Core/Protocols.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protocol IBlockchain {
func transactionSingle(transactionHash: Data) -> Single<RpcTransaction?>
func getStorageAt(contractAddress: Address, positionData: Data, defaultBlockParameter: DefaultBlockParameter) -> Single<Data>
func call(contractAddress: Address, data: Data, defaultBlockParameter: DefaultBlockParameter) -> Single<Data>
func estimateGas(to: Address, amount: BigUInt?, gasLimit: Int?, gasPrice: Int?, data: Data?) -> Single<Int>
func estimateGas(to: Address?, amount: BigUInt?, gasLimit: Int?, gasPrice: Int?, data: Data?) -> Single<Int>
}

protocol IBlockchainDelegate: class {
Expand Down
2 changes: 1 addition & 1 deletion EthereumKit/Classes/Spv/Core/SpvBlockchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ extension SpvBlockchain: IBlockchain {
// rpcApiProvider.call(contractAddress: contractAddress, data: data, defaultBlockParameter: defaultBlockParameter)
}

func estimateGas(to: Address, amount: BigUInt?, gasLimit: Int?, gasPrice: Int?, data: Data?) -> Single<Int> {
func estimateGas(to: Address?, amount: BigUInt?, gasLimit: Int?, gasPrice: Int?, data: Data?) -> Single<Int> {
fatalError("Not implemented yet")
// rpcApiProvider.getEstimateGas(to: to, amount: amount, gasLimit: gasLimit, gasPrice: gasPrice, data: data)
}
Expand Down

0 comments on commit 70c5612

Please sign in to comment.