Skip to content

Commit

Permalink
Make GasPrice optional for estimateGas request
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelekol committed Nov 19, 2024
1 parent a5eff38 commit a0ac622
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class RpcBlockchain(
return syncer.single(GetTransactionCountJsonRpc(address, defaultBlockParameter))
}

override fun estimateGas(to: Address?, amount: BigInteger?, gasLimit: Long?, gasPrice: GasPrice, data: ByteArray?): Single<Long> {
override fun estimateGas(to: Address?, amount: BigInteger?, gasLimit: Long?, gasPrice: GasPrice?, data: ByteArray?): Single<Long> {
return syncer.single(EstimateGasJsonRpc(address, to, amount, gasLimit, gasPrice, data))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,25 @@ class EstimateGasJsonRpc(
@Transient val to: Address?,
@Transient val amount: BigInteger?,
@Transient val gasLimit: Long?,
@Transient val gasPrice: GasPrice,
@Transient val gasPrice: GasPrice?,
@Transient val data: ByteArray?
) : LongJsonRpc(
method = "eth_estimateGas",
params = listOf(estimateGasParams(from, to, amount, gasLimit, gasPrice, data))
) {

companion object {
private fun estimateGasParams(from: Address, to: Address?, amount: BigInteger?, gasLimit: Long?, gasPrice: GasPrice, data: ByteArray?): EstimateGasParams {
private fun estimateGasParams(from: Address, to: Address?, amount: BigInteger?, gasLimit: Long?, gasPrice: GasPrice?, data: ByteArray?): EstimateGasParams {
return when (gasPrice) {
is GasPrice.Eip1559 -> {
EstimateGasParams.Eip1559(from, to, amount, gasLimit, gasPrice.maxFeePerGas, gasPrice.maxPriorityFeePerGas, data)
}
is GasPrice.Legacy -> {
EstimateGasParams.Legacy(from, to, amount, gasLimit, gasPrice.legacyGasPrice, data)
}
null -> {
EstimateGasParams.NoGasPrice(from, to, amount, gasLimit, data)
}
}
}
}
Expand Down Expand Up @@ -53,5 +56,15 @@ class EstimateGasJsonRpc(
val maxPriorityFeePerGas: Long,
val data: ByteArray?
) : EstimateGasParams()

data class NoGasPrice(
val from: Address,
val to: Address?,
@SerializedName("value")
val amount: BigInteger?,
@SerializedName("gas")
val gasLimit: Long?,
val data: ByteArray?
) : EstimateGasParams()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,11 @@ class EthereumKit(
return blockchain.estimateGas(to, resolvedAmount, chain.gasLimit, gasPrice, null)
}

fun estimateGas(to: Address?, value: BigInteger?, gasPrice: GasPrice, data: ByteArray?): Single<Long> {
fun estimateGas(to: Address?, value: BigInteger?, gasPrice: GasPrice?, data: ByteArray?): Single<Long> {
return blockchain.estimateGas(to, value, chain.gasLimit, gasPrice, data)
}

fun estimateGas(transactionData: TransactionData, gasPrice: GasPrice): Single<Long> {
fun estimateGas(transactionData: TransactionData, gasPrice: GasPrice? = null): Single<Long> {
return estimateGas(transactionData.to, transactionData.value, gasPrice, transactionData.input)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ interface IBlockchain {

fun send(rawTransaction: RawTransaction, signature: Signature): Single<Transaction>
fun getNonce(defaultBlockParameter: DefaultBlockParameter): Single<Long>
fun estimateGas(to: Address?, amount: BigInteger?, gasLimit: Long?, gasPrice: GasPrice, data: ByteArray?): Single<Long>
fun estimateGas(to: Address?, amount: BigInteger?, gasLimit: Long?, gasPrice: GasPrice?, data: ByteArray?): Single<Long>
fun getTransactionReceipt(transactionHash: ByteArray): Single<RpcTransactionReceipt>
fun getTransaction(transactionHash: ByteArray): Single<RpcTransaction>
fun getBlock(blockNumber: Long): Single<RpcBlock>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class SpvBlockchain(
TODO("not implemented")
}

override fun estimateGas(to: Address?, amount: BigInteger?, gasLimit: Long?, gasPrice: GasPrice, data: ByteArray?): Single<Long> {
override fun estimateGas(to: Address?, amount: BigInteger?, gasLimit: Long?, gasPrice: GasPrice?, data: ByteArray?): Single<Long> {
TODO("not implemented")
}

Expand Down

0 comments on commit a0ac622

Please sign in to comment.