Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nonce related changes #272

Merged
merged 3 commits into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ class RpcBlockchain(
.map { transaction }
}

override fun getNonce(): Single<Long> {
return syncer.single(GetTransactionCountJsonRpc(address, DefaultBlockParameter.Pending))
override fun getNonce(defaultBlockParameter: DefaultBlockParameter): Single<Long> {
return syncer.single(GetTransactionCountJsonRpc(address, defaultBlockParameter))
}

override fun estimateGas(to: Address?, amount: BigInteger?, gasLimit: Long?, gasPrice: GasPrice, data: ByteArray?): Single<Long> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ class EthereumKit(
transactionSyncManager.sync()
}

fun getNonce(defaultBlockParameter: DefaultBlockParameter): Single<Long> {
return blockchain.getNonce(defaultBlockParameter)
}
fun getFullTransactionsFlowable(tags: List<List<String>>): Flowable<List<FullTransaction>> {
return transactionManager.getFullTransactionsFlowable(tags)
}
Expand Down Expand Up @@ -194,7 +197,7 @@ class EthereumKit(
gasLimit: Long,
nonce: Long? = null
): Single<RawTransaction> {
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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ interface IBlockchain {
val accountState: AccountState?

fun send(rawTransaction: RawTransaction, signature: Signature): Single<Transaction>
fun getNonce(): Single<Long>
fun getNonce(defaultBlockParameter: DefaultBlockParameter): 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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<BigInteger> {
val rawTransaction = RawTransaction(gasPrice, gasLimit, to, value, nonce ?: 1, data)
fun getL1Fee(gasPrice: GasPrice, gasLimit: Long, to: Address, value: BigInteger, data: ByteArray): Single<BigInteger> {
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() }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class SpvBlockchain(
}
}

override fun getNonce(): Single<Long> {
override fun getNonce(defaultBlockParameter: DefaultBlockParameter): Single<Long> {
TODO("not implemented")
}

Expand Down