From a89f49eecdc06d24d5089219ec6b7b6cda2c93d2 Mon Sep 17 00:00:00 2001 From: chyngyz Date: Fri, 10 Feb 2023 15:22:25 +0600 Subject: [PATCH 1/3] Add method `getNonce` to EthereumKit --- .../horizontalsystems/ethereumkit/api/core/RpcBlockchain.kt | 4 ++-- .../io/horizontalsystems/ethereumkit/core/EthereumKit.kt | 5 ++++- .../java/io/horizontalsystems/ethereumkit/core/Interfaces.kt | 2 +- .../horizontalsystems/ethereumkit/spv/core/SpvBlockchain.kt | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/api/core/RpcBlockchain.kt b/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/api/core/RpcBlockchain.kt index 78469168..38a04dec 100644 --- a/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/api/core/RpcBlockchain.kt +++ b/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/api/core/RpcBlockchain.kt @@ -114,8 +114,8 @@ class RpcBlockchain( .map { transaction } } - override fun getNonce(): Single { - return syncer.single(GetTransactionCountJsonRpc(address, DefaultBlockParameter.Pending)) + override fun getNonce(defaultBlockParameter: DefaultBlockParameter): Single { + return syncer.single(GetTransactionCountJsonRpc(address, defaultBlockParameter)) } override fun estimateGas(to: Address?, amount: BigInteger?, gasLimit: Long?, gasPrice: GasPrice, data: ByteArray?): Single { diff --git a/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/core/EthereumKit.kt b/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/core/EthereumKit.kt index 07ed087b..219dd8fa 100644 --- a/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/core/EthereumKit.kt +++ b/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/core/EthereumKit.kt @@ -130,6 +130,9 @@ class EthereumKit( transactionSyncManager.sync() } + fun getNonce(defaultBlockParameter: DefaultBlockParameter): Single { + return blockchain.getNonce(defaultBlockParameter) + } fun getFullTransactionsFlowable(tags: List>): Flowable> { return transactionManager.getFullTransactionsFlowable(tags) } @@ -194,7 +197,7 @@ class EthereumKit( gasLimit: Long, nonce: Long? = null ): Single { - val nonceSingle = nonce?.let { Single.just(it) } ?: blockchain.getNonce() + val nonceSingle = nonce?.let { Single.just(it) } ?: blockchain.getNonce(DefaultBlockParameter.Pending) return nonceSingle.flatMap { nonce -> Single.just(RawTransaction(gasPrice, gasLimit, address, value, nonce, transactionInput)) diff --git a/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/core/Interfaces.kt b/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/core/Interfaces.kt index b82a1a5e..aeba48ac 100644 --- a/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/core/Interfaces.kt +++ b/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/core/Interfaces.kt @@ -46,7 +46,7 @@ interface IBlockchain { val accountState: AccountState? fun send(rawTransaction: RawTransaction, signature: Signature): Single - fun getNonce(): Single + fun getNonce(defaultBlockParameter: DefaultBlockParameter): Single fun estimateGas(to: Address?, amount: BigInteger?, gasLimit: Long?, gasPrice: GasPrice, data: ByteArray?): Single fun getTransactionReceipt(transactionHash: ByteArray): Single fun getTransaction(transactionHash: ByteArray): Single diff --git a/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/spv/core/SpvBlockchain.kt b/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/spv/core/SpvBlockchain.kt index baf9fe03..4e690fd2 100644 --- a/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/spv/core/SpvBlockchain.kt +++ b/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/spv/core/SpvBlockchain.kt @@ -90,7 +90,7 @@ class SpvBlockchain( } } - override fun getNonce(): Single { + override fun getNonce(defaultBlockParameter: DefaultBlockParameter): Single { TODO("not implemented") } From 4809afa3f60579be19ecf08934dd89f99e115c4c Mon Sep 17 00:00:00 2001 From: chyngyz Date: Fri, 10 Feb 2023 18:46:20 +0600 Subject: [PATCH 2/3] Remove field `nonce` from `TransactionData' --- .../horizontalsystems/ethereumkit/models/TransactionData.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/models/TransactionData.kt b/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/models/TransactionData.kt index 09f8da35..9c01f9e0 100644 --- a/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/models/TransactionData.kt +++ b/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/models/TransactionData.kt @@ -7,13 +7,12 @@ import java.util.* data class TransactionData( val to: Address, val value: BigInteger, - val input: ByteArray, - val nonce: Long? = null + val input: ByteArray ) { override fun equals(other: Any?): Boolean { return when { this === other -> true - other is TransactionData -> to == other.to && value == other.value && input.contentEquals(other.input) && nonce == other.nonce + other is TransactionData -> to == other.to && value == other.value && input.contentEquals(other.input) else -> false } } From 9184e77950e42a991c65a03a7105cb7f09721cc2 Mon Sep 17 00:00:00 2001 From: chyngyz Date: Tue, 14 Feb 2023 12:42:15 +0600 Subject: [PATCH 3/3] Remove parameter `nonce` from `L1FeeProvider.getL1Fee()' - hard-code it to 1 --- .../ethereumkit/core/rollup/L1FeeProvider.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/core/rollup/L1FeeProvider.kt b/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/core/rollup/L1FeeProvider.kt index 53035c60..2df39703 100644 --- a/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/core/rollup/L1FeeProvider.kt +++ b/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/core/rollup/L1FeeProvider.kt @@ -20,12 +20,12 @@ class L1FeeProvider( override fun getArguments() = listOf(transaction) } - fun getL1Fee(gasPrice: GasPrice, gasLimit: Long, to: Address, value: BigInteger, data: ByteArray, nonce: Long?): Single { - val rawTransaction = RawTransaction(gasPrice, gasLimit, to, value, nonce ?: 1, data) + fun getL1Fee(gasPrice: GasPrice, gasLimit: Long, to: Address, value: BigInteger, data: ByteArray): Single { + val rawTransaction = RawTransaction(gasPrice, gasLimit, to, value, 1, data) val encoded = TransactionBuilder.encode(rawTransaction, null, evmKit.chain.id) - val data = L1FeeMethod(encoded).encodedABI() + val feeMethodABI = L1FeeMethod(encoded).encodedABI() - return evmKit.call(contractAddress, data) + return evmKit.call(contractAddress, feeMethodABI) .map { it.sliceArray(IntRange(0, 31)).toBigInteger() } }