Skip to content

Commit dcb8a50

Browse files
authored
Remove dead code in IexecHubService and CommandStorage (#133)
1 parent 15fac26 commit dcb8a50

File tree

4 files changed

+15
-47
lines changed

4 files changed

+15
-47
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file.
1212

1313
- Remove `/tasks/{chainTaskId}` endpoint, the adapter must only call `initialize` and `finalize` **PoCo** methods. (#130)
1414
- Remove `/broker/orders/match` endpoint, `matchOrders` must be done through the **Market API**. (#131)
15+
- Remove dead code in `IexecHubService` and `CommandStorage`. (#133)
1516

1617
## [[8.3.0]](https://github.com/iExecBlockchainComputing/iexec-blockchain-adapter-api/releases/tag/v8.3.0) 2024-01-10
1718

src/main/java/com/iexec/blockchain/command/generic/CommandStorage.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2023 IEXEC BLOCKCHAIN TECH
2+
* Copyright 2020-2024 IEXEC BLOCKCHAIN TECH
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@
1919
import com.iexec.blockchain.api.CommandStatus;
2020
import lombok.NonNull;
2121
import lombok.extern.slf4j.Slf4j;
22-
import org.apache.commons.lang3.StringUtils;
2322
import org.web3j.protocol.core.methods.response.TransactionReceipt;
2423

2524
import java.time.Instant;
@@ -69,7 +68,6 @@ public boolean updateToReceived(A args) {
6968
public boolean updateToProcessing(String chainObjectId) {
7069
Optional<C> localCommand = commandRepository
7170
.findByChainObjectId(chainObjectId)
72-
.filter(command -> command.getStatus() != null)
7371
.filter(command -> command.getStatus() == CommandStatus.RECEIVED);
7472
if (localCommand.isEmpty()) {
7573
return false;
@@ -93,27 +91,21 @@ public void updateToFinal(String chainObjectId,
9391
@NonNull TransactionReceipt receipt) {
9492
Optional<C> localCommand = commandRepository
9593
.findByChainObjectId(chainObjectId)
96-
.filter(command -> command.getStatus() != null)
9794
.filter(command -> command.getStatus() == CommandStatus.PROCESSING);
9895
if (localCommand.isEmpty()) {
9996
return;
10097
}
10198
C command = localCommand.get();
10299

103100
CommandStatus status;
104-
if (StringUtils.isNotEmpty(receipt.getStatus())
105-
&& receipt.getStatus().equals("0x1")) {
101+
if (receipt.isStatusOK()) {
106102
status = CommandStatus.SUCCESS;
107-
log.info("Success command with transaction receipt " +
108-
"[chainObjectId:{}, command:{}, receipt:{}]",
109-
chainObjectId,
110-
command.getClass().getSimpleName(),
111-
receipt);
103+
log.info("Success command with transaction receipt [chainObjectId:{}, command:{}, receipt:{}]",
104+
chainObjectId, command.getClass().getSimpleName(), receipt);
112105
} else {
113106
status = CommandStatus.FAILURE;
114-
log.info("Failure after transaction sent [chainObjectId:{}, " +
115-
"command:{}, receipt:{}]", chainObjectId,
116-
command.getClass().getSimpleName(), receipt);
107+
log.info("Failure after transaction sent [chainObjectId:{}, command:{}, receipt:{}]",
108+
chainObjectId, command.getClass().getSimpleName(), receipt);
117109
}
118110
command.setStatus(status);
119111
command.setTransactionReceipt(receipt);

src/main/java/com/iexec/blockchain/tool/IexecHubService.java

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2023 IEXEC BLOCKCHAIN TECH
2+
* Copyright 2020-2024 IEXEC BLOCKCHAIN TECH
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,9 +16,11 @@
1616

1717
package com.iexec.blockchain.tool;
1818

19-
import com.iexec.common.utils.EthAddress;
2019
import com.iexec.common.worker.result.ResultUtils;
21-
import com.iexec.commons.poco.chain.*;
20+
import com.iexec.commons.poco.chain.ChainDeal;
21+
import com.iexec.commons.poco.chain.ChainTask;
22+
import com.iexec.commons.poco.chain.ChainTaskStatus;
23+
import com.iexec.commons.poco.chain.IexecHubAbstractService;
2224
import com.iexec.commons.poco.utils.BytesUtils;
2325
import org.apache.commons.lang3.StringUtils;
2426
import org.springframework.stereotype.Service;
@@ -46,20 +48,11 @@ public IexecHubService(CredentialsService credentialsService,
4648
);
4749
}
4850

49-
public static boolean isSignature(String hexString) {
50-
return !StringUtils.isEmpty(hexString) &&
51-
BytesUtils.stringToBytes(hexString).length == 65; // 32 + 32 + 1
52-
}
53-
5451
public static boolean isByte32(String hexString) {
5552
return !StringUtils.isEmpty(hexString) &&
5653
BytesUtils.stringToBytes(hexString).length == 32;
5754
}
5855

59-
public static boolean isAddress(String hexString) {
60-
return EthAddress.validate(hexString);
61-
}
62-
6356
public TransactionReceipt initializeTask(String chainDealId,
6457
int taskIndex) throws Exception {
6558
addLatency();
@@ -200,22 +193,4 @@ public Date getContributionDeadline(ChainDeal chainDeal) {
200193
return new Date(startTime + maxTime * maxNbOfPeriods);
201194
}
202195

203-
public boolean hasEnoughStakeToContribute(String chainDealId, String workerWallet) {
204-
Optional<ChainAccount> optionalChainAccount = getChainAccount(workerWallet);
205-
Optional<ChainDeal> optionalChainDeal = getChainDeal(chainDealId);
206-
if (optionalChainAccount.isEmpty() || optionalChainDeal.isEmpty()) {
207-
return false;
208-
}
209-
return optionalChainAccount.get().getDeposit() >= optionalChainDeal.get().getWorkerStake().longValue();
210-
}
211-
212-
public boolean isContributionUnsetToContribute(String chainTaskId, String workerWallet) {
213-
Optional<ChainContribution> optionalContribution =
214-
getChainContribution(chainTaskId, workerWallet);
215-
if (optionalContribution.isEmpty()) return false;
216-
217-
ChainContribution chainContribution = optionalContribution.get();
218-
return chainContribution.getStatus().equals(ChainContributionStatus.UNSET);
219-
}
220-
221196
}

src/test/java/com/iexec/blockchain/command/task/initialize/TaskInitializeStorageTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021-2023 IEXEC BLOCKCHAIN TECH
2+
* Copyright 2021-2024 IEXEC BLOCKCHAIN TECH
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -117,7 +117,7 @@ void shouldNotSetProcessingSinceBadStatus() {
117117
@Test
118118
void shouldSetFinalSuccess() {
119119
TransactionReceipt receipt = mock(TransactionReceipt.class);
120-
when(receipt.getStatus()).thenReturn("0x1");
120+
when(receipt.isStatusOK()).thenReturn(true);
121121
TaskInitialize taskInitialize = new TaskInitialize();
122122
taskInitialize.setStatus(CommandStatus.PROCESSING);
123123
when(repository.findByChainObjectId(CHAIN_TASK_ID))
@@ -138,7 +138,7 @@ void shouldSetFinalSuccess() {
138138
@Test
139139
void shouldSetFinalFailure() {
140140
TransactionReceipt receipt = mock(TransactionReceipt.class);
141-
when(receipt.getStatus()).thenReturn("0x0");
141+
when(receipt.isStatusOK()).thenReturn(false);
142142
TaskInitialize taskInitialize = new TaskInitialize();
143143
taskInitialize.setStatus(CommandStatus.PROCESSING);
144144
when(repository.findByChainObjectId(CHAIN_TASK_ID))

0 commit comments

Comments
 (0)