Skip to content

Commit 5471a27

Browse files
committed
Move RetryPolicies to separate file
1 parent 57b706e commit 5471a27

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

src/main/kotlin/org/komputing/fauceth/TransactionSender.kt

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package org.komputing.fauceth
22

3-
import com.github.michaelbull.retry.ContinueRetrying
4-
import com.github.michaelbull.retry.StopRetrying
5-
import com.github.michaelbull.retry.policy.RetryPolicy
63
import com.github.michaelbull.retry.policy.decorrelatedJitterBackoff
74
import com.github.michaelbull.retry.policy.limitAttempts
85
import com.github.michaelbull.retry.policy.plus
@@ -19,10 +16,11 @@ import org.kethereum.model.Address
1916
import org.kethereum.model.ChainId
2017
import org.kethereum.model.createEmptyTransaction
2118
import org.kethereum.rpc.EthereumRPCException
19+
import org.komputing.fauceth.util.handle1559NotAvailable
2220
import org.komputing.fauceth.util.log
21+
import org.komputing.fauceth.util.noRetryWhenKnown
2322
import org.walleth.khex.toHexString
2423
import java.io.IOException
25-
import java.lang.IllegalStateException
2624
import java.math.BigDecimal
2725
import java.math.BigInteger
2826
import java.math.BigInteger.*
@@ -46,9 +44,6 @@ suspend fun sendTransaction(address: Address, txChain: ExtendedChainInfo): Strin
4644
txChain.rpc.estimateGas(tx) ?: throw EthereumRPCException("Could not estimate gas limit", 404)
4745
}
4846
if (txChain.useEIP1559) {
49-
val handle1559NotAvailable: RetryPolicy<Throwable> = {
50-
if (reason is EthereumRPCException && (reason.message == "the method eth_feeHistory does not exist/is not available") || (reason.message == "rpc method is not whitelisted")) StopRetrying else ContinueRetrying
51-
}
5247

5348
if (tx.maxPriorityFeePerGas == null || System.currentTimeMillis() - (tx.creationEpochSecond ?: System.currentTimeMillis()) > 20000) {
5449
try {
@@ -106,9 +101,6 @@ suspend fun sendTransaction(address: Address, txChain: ExtendedChainInfo): Strin
106101
txHashList.add(hash.toHexString())
107102

108103
try {
109-
val noRetryWhenKnown: RetryPolicy<Throwable> = {
110-
if (reason is EthereumRPCException && reason.message == "already known") StopRetrying else ContinueRetrying
111-
}
112104

113105
retry(limitAttempts(5) + noRetryWhenKnown + decorrelatedJitterBackoff(base = 10L, max = 5000L)) {
114106
val res = txChain.rpc.sendRawTransaction(encodedTransaction.toHexString())
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.komputing.fauceth.util
2+
3+
import com.github.michaelbull.retry.ContinueRetrying
4+
import com.github.michaelbull.retry.StopRetrying
5+
import com.github.michaelbull.retry.policy.RetryPolicy
6+
import org.kethereum.rpc.EthereumRPCException
7+
8+
val handle1559NotAvailable: RetryPolicy<Throwable> = {
9+
if (reason is EthereumRPCException &&
10+
(reason.message == "the method eth_feeHistory does not exist/is not available") ||
11+
(reason.message == "rpc method is not whitelisted")
12+
) StopRetrying else ContinueRetrying
13+
}
14+
15+
val noRetryWhenKnown: RetryPolicy<Throwable> = {
16+
if (reason is EthereumRPCException && reason.message == "already known") StopRetrying else ContinueRetrying
17+
}

0 commit comments

Comments
 (0)