Skip to content

Commit 6157056

Browse files
authored
feat: add PollingTransactionReceiptProcessor as a protected field in IexecHubAbstractService (#142)
This will be used in other components to query the blockchain network for TransactionReceipt
1 parent df64394 commit 6157056

File tree

3 files changed

+16
-34
lines changed

3 files changed

+16
-34
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ dependencies {
3434
implementation platform('org.springframework.boot:spring-boot-dependencies:3.3.8')
3535

3636
// web3j
37-
api 'org.web3j:core:4.12.3'
37+
api 'org.web3j:core:4.13.0'
3838

3939
// apache commons.lang3
4040
implementation 'org.apache.commons:commons-lang3'

src/main/java/com/iexec/commons/poco/chain/IexecHubAbstractService.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.web3j.tuples.generated.Tuple3;
3131
import org.web3j.tx.RawTransactionManager;
3232
import org.web3j.tx.gas.ContractGasProvider;
33+
import org.web3j.tx.response.PollingTransactionReceiptProcessor;
3334
import org.web3j.utils.Numeric;
3435

3536
import java.io.IOException;
@@ -41,8 +42,6 @@
4142
import static com.iexec.commons.poco.encoding.AccessorsEncoder.*;
4243
import static com.iexec.commons.poco.tee.TeeEnclaveConfiguration.buildEnclaveConfigurationFromJsonString;
4344
import static com.iexec.commons.poco.utils.BytesUtils.isNonZeroedBytes32;
44-
import static org.web3j.tx.TransactionManager.DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH;
45-
4645

4746
/*
4847
* Contracts (located at *.contract.generated) which are used in this service are generated from:
@@ -52,13 +51,15 @@
5251
@Slf4j
5352
public abstract class IexecHubAbstractService {
5453

54+
public static final int POLLING_ATTEMPTS_PER_TX_HASH = 12;
5555
public static final int NB_BLOCKS_TO_WAIT_PER_RETRY = 6;
5656
public static final int MAX_RETRIES = 3;
5757

5858
protected final Credentials credentials;
5959
private final String iexecHubAddress;
60-
private final RawTransactionManager txManager;
61-
protected IexecHubContract iexecHubContract;
60+
protected final RawTransactionManager txManager;
61+
protected final PollingTransactionReceiptProcessor txReceiptProcessor;
62+
protected final IexecHubContract iexecHubContract;
6263
private final Web3jAbstractService web3jAbstractService;
6364
private long maxNbOfPeriodsForConsensus = -1;
6465
private final long retryDelay;// ms
@@ -94,12 +95,17 @@ protected IexecHubAbstractService(
9495
this.retryDelay = nbBlocksToWaitPerRetry * this.web3jAbstractService.getBlockTime().toMillis();
9596
this.maxRetries = maxRetries;
9697

98+
txReceiptProcessor = new PollingTransactionReceiptProcessor(
99+
web3jAbstractService.getWeb3j(),
100+
web3jAbstractService.getBlockTime().toMillis(),
101+
POLLING_ATTEMPTS_PER_TX_HASH
102+
);
103+
97104
txManager = new RawTransactionManager(
98105
web3jAbstractService.getWeb3j(),
99106
credentials,
100107
web3jAbstractService.getChainId(),
101-
DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH,
102-
web3jAbstractService.getBlockTime().toMillis()
108+
txReceiptProcessor
103109
);
104110

105111
iexecHubContract = getHubContract(web3jAbstractService.getContractGasProvider());

src/main/java/com/iexec/commons/poco/chain/Web3jAbstractService.java

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.iexec.commons.poco.chain;
1818

19-
import com.iexec.commons.poco.encoding.PoCoDataEncoder;
2019
import com.iexec.commons.poco.utils.WaitUtils;
2120
import jakarta.annotation.PostConstruct;
2221
import lombok.Getter;
@@ -27,6 +26,8 @@
2726
import org.web3j.protocol.core.methods.response.TransactionReceipt;
2827
import org.web3j.protocol.http.HttpService;
2928
import org.web3j.tx.gas.ContractGasProvider;
29+
import org.web3j.tx.gas.DynamicGasProvider;
30+
import org.web3j.tx.gas.PriorityGasProvider;
3031
import org.web3j.utils.Async;
3132

3233
import java.io.IOException;
@@ -93,7 +94,7 @@ protected Web3jAbstractService(
9394
this.gasPriceCap = gasPriceCap;
9495
this.isSidechain = isSidechain;
9596
this.web3j = Web3j.build(new HttpService(chainNodeAddress), this.blockTime.toMillis(), Async.defaultExecutorService());
96-
this.contractGasProvider = getWritingContractGasProvider();
97+
this.contractGasProvider = new DynamicGasProvider(web3j, PriorityGasProvider.Priority.CUSTOM, BigDecimal.valueOf(gasPriceMultiplier));
9798
}
9899

99100
@PostConstruct
@@ -271,31 +272,6 @@ public BigInteger getUserGasPrice() {
271272
return getUserGasPrice(gasPriceMultiplier, gasPriceCap);
272273
}
273274

274-
private ContractGasProvider getWritingContractGasProvider() {
275-
return new ContractGasProvider() {
276-
277-
@Override
278-
public BigInteger getGasPrice(String s) {
279-
return getUserGasPrice(gasPriceMultiplier, gasPriceCap);
280-
}
281-
282-
@Override
283-
public BigInteger getGasPrice() {
284-
return getUserGasPrice(gasPriceMultiplier, gasPriceCap);
285-
}
286-
287-
@Override
288-
public BigInteger getGasLimit(String functionName) {
289-
return PoCoDataEncoder.getGasLimitForFunction(functionName);
290-
}
291-
292-
@Override
293-
public BigInteger getGasLimit() {
294-
return BigInteger.valueOf(GAS_LIMIT_CAP);
295-
}
296-
};
297-
}
298-
299275
/**
300276
* Repeat a check until a condition is met or the max number of tries have been done.
301277
* <p>

0 commit comments

Comments
 (0)