Skip to content

Commit fac2605

Browse files
authored
Rename tool package to chain package (#155)
1 parent 84e15e8 commit fac2605

25 files changed

+250
-165
lines changed

CHANGELOG.md

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

99
- Use poco-chain with poco v5.5.0 and voucher v1.0.0 in tests. (#152)
10+
- Rename `tool` package to `chain` package. (#155)
1011

1112
### Dependency Upgrades
1213

src/itest/java/com/iexec/blockchain/IntegrationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
import com.iexec.blockchain.api.BlockchainAdapterApiClient;
2020
import com.iexec.blockchain.api.BlockchainAdapterApiClientBuilder;
2121
import com.iexec.blockchain.broker.BrokerService;
22-
import com.iexec.blockchain.tool.ChainConfig;
23-
import com.iexec.blockchain.tool.IexecHubService;
22+
import com.iexec.blockchain.chain.ChainConfig;
23+
import com.iexec.blockchain.chain.IexecHubService;
2424
import com.iexec.common.chain.adapter.args.TaskFinalizeArgs;
2525
import com.iexec.common.sdk.broker.BrokerOrder;
2626
import com.iexec.commons.poco.chain.*;

src/main/java/com/iexec/blockchain/broker/BrokerService.java

Lines changed: 5 additions & 5 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,7 +16,7 @@
1616

1717
package com.iexec.blockchain.broker;
1818

19-
import com.iexec.blockchain.tool.IexecHubService;
19+
import com.iexec.blockchain.chain.IexecHubService;
2020
import com.iexec.common.sdk.broker.BrokerOrder;
2121
import com.iexec.commons.poco.chain.ChainAccount;
2222
import com.iexec.commons.poco.order.AppOrder;
@@ -65,7 +65,7 @@ void checkBrokerOrder(BrokerOrder brokerOrder) {
6565

6666
checkRequestOrder(requestOrder);
6767
checkAssetOrder(requestOrder.getApp(), appOrder.getApp(), appOrder.getAppprice(), "App");
68-
checkAssetOrder(requestOrder.getWorkerpool(), workerpoolOrder.getWorkerpool(), workerpoolOrder.getWorkerpoolprice(),"Workerpool");
68+
checkAssetOrder(requestOrder.getWorkerpool(), workerpoolOrder.getWorkerpool(), workerpoolOrder.getWorkerpoolprice(), "Workerpool");
6969
if (withDataset(requestOrder.getDataset())) {
7070
Objects.requireNonNull(datasetOrder, "Dataset order cannot be null");
7171
checkAssetOrder(requestOrder.getDataset(), datasetOrder.getDataset(), datasetOrder.getDatasetprice(), "Dataset");
@@ -82,7 +82,7 @@ void checkRequestOrder(RequestOrder requestOrder) {
8282
}
8383

8484
void checkAssetOrder(String requestOrderAddress, String assetAddress, BigInteger assetPrice, String assetType) {
85-
Objects.requireNonNull(requestOrderAddress, assetType + " address cannot be null in request order");
85+
Objects.requireNonNull(requestOrderAddress, assetType + " address cannot be null in request order");
8686
Objects.requireNonNull(assetAddress, assetType + " address cannot be null");
8787
Objects.requireNonNull(assetPrice, assetType + " price cannot be null");
8888
if (!requestOrderAddress.equalsIgnoreCase(assetAddress)) {
@@ -208,7 +208,7 @@ boolean hasRequesterDepositedEnough(long deposit, long appPrice, long workerpool
208208
* @param datasetAddress Dataset address to check
209209
* @return true if a dataset is part of the request, false otherwise.
210210
*/
211-
boolean withDataset(String datasetAddress) {
211+
boolean withDataset(String datasetAddress) {
212212
return StringUtils.isNotEmpty(datasetAddress) && !datasetAddress.equals(BytesUtils.EMPTY_ADDRESS);
213213
}
214214

src/main/java/com/iexec/blockchain/tool/ChainConfig.java renamed to src/main/java/com/iexec/blockchain/chain/ChainConfig.java

Lines changed: 2 additions & 2 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.
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.iexec.blockchain.tool;
17+
package com.iexec.blockchain.chain;
1818

1919
import com.iexec.common.chain.validation.ValidNonZeroEthereumAddress;
2020
import lombok.Builder;

src/main/java/com/iexec/blockchain/tool/IexecHubService.java renamed to src/main/java/com/iexec/blockchain/chain/IexecHubService.java

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.iexec.blockchain.tool;
17+
package com.iexec.blockchain.chain;
1818

1919
import com.iexec.common.worker.result.ResultUtils;
2020
import com.iexec.commons.poco.chain.*;
@@ -28,30 +28,29 @@
2828
import java.time.Instant;
2929
import java.time.temporal.ChronoUnit;
3030
import java.util.Date;
31-
import java.util.Optional;
3231

3332
import static com.iexec.commons.poco.utils.BytesUtils.stringToBytes;
3433

3534
@Service
3635
public class IexecHubService extends IexecHubAbstractService {
3736

38-
public IexecHubService(SignerService signerService,
39-
Web3jService web3jService,
40-
ChainConfig chainConfig) {
37+
public IexecHubService(final SignerService signerService,
38+
final Web3jService web3jService,
39+
final ChainConfig chainConfig) {
4140
super(
4241
signerService.getCredentials(),
4342
web3jService,
4443
chainConfig.getHubAddress()
4544
);
4645
}
4746

48-
public static boolean isByte32(String hexString) {
47+
public static boolean isByte32(final String hexString) {
4948
return !StringUtils.isEmpty(hexString) &&
5049
BytesUtils.stringToBytes(hexString).length == 32;
5150
}
5251

53-
public TransactionReceipt initializeTask(String chainDealId,
54-
int taskIndex) throws Exception {
52+
public TransactionReceipt initializeTask(final String chainDealId,
53+
final int taskIndex) throws Exception {
5554
addLatency();
5655
return iexecHubContract
5756
.initialize(
@@ -60,13 +59,13 @@ public TransactionReceipt initializeTask(String chainDealId,
6059
.send();
6160
}
6261

63-
public TransactionReceipt contribute(String chainTaskId,
64-
String resultDigest,
65-
String workerpoolSignature,
66-
String enclaveChallenge,
67-
String enclaveSignature) throws Exception {
68-
String resultHash = ResultUtils.computeResultHash(chainTaskId, resultDigest);
69-
String resultSeal =
62+
public TransactionReceipt contribute(final String chainTaskId,
63+
final String resultDigest,
64+
final String workerpoolSignature,
65+
final String enclaveChallenge,
66+
final String enclaveSignature) throws Exception {
67+
final String resultHash = ResultUtils.computeResultHash(chainTaskId, resultDigest);
68+
final String resultSeal =
7069
ResultUtils.computeResultSeal(credentials.getAddress(),
7170
chainTaskId,
7271
resultDigest);
@@ -83,18 +82,18 @@ public TransactionReceipt contribute(String chainTaskId,
8382
}
8483

8584

86-
public TransactionReceipt reveal(String chainTaskId,
87-
String resultDigest) throws Exception {
85+
public TransactionReceipt reveal(final String chainTaskId,
86+
final String resultDigest) throws Exception {
8887
return iexecHubContract
8988
.reveal(
9089
stringToBytes(chainTaskId),
9190
stringToBytes(resultDigest))
9291
.send();
9392
}
9493

95-
public TransactionReceipt finalizeTask(String chainTaskId,
96-
String resultLink,
97-
String callbackData) throws Exception {
94+
public TransactionReceipt finalizeTask(final String chainTaskId,
95+
final String resultLink,
96+
final String callbackData) throws Exception {
9897
addLatency();
9998
byte[] results = StringUtils.isNotEmpty(resultLink) ?
10099
resultLink.getBytes(StandardCharsets.UTF_8) : new byte[0];
@@ -131,16 +130,14 @@ public boolean hasEnoughGas() {
131130
}
132131

133132
/**
134-
* Check if the task is defined onchain and
135-
* has the status {@link ChainTaskStatus#UNSET}.
133+
* Check if the task is defined on-chain and has the {@link ChainTaskStatus#UNSET} status.
136134
*
137135
* @param chainTaskId blockchain ID of the task
138136
* @return true if the task is found with the status UNSET, false otherwise.
139137
*/
140-
public boolean isTaskInUnsetStatusOnChain(String chainTaskId) {
141-
final Optional<ChainTask> chainTask = getChainTask(chainTaskId);
142-
return chainTask.isEmpty()
143-
|| ChainTaskStatus.UNSET.equals(chainTask.get().getStatus());
138+
public boolean isTaskInUnsetStatusOnChain(final String chainTaskId) {
139+
final ChainTask chainTask = getChainTask(chainTaskId).orElse(null);
140+
return chainTask == null || chainTask.getStatus() == ChainTaskStatus.UNSET;
144141
}
145142

146143
/**
@@ -150,7 +147,7 @@ public boolean isTaskInUnsetStatusOnChain(String chainTaskId) {
150147
* @param chainDealId blockchain ID of the deal
151148
* @return true if deadline is not reached, false otherwise.
152149
*/
153-
public boolean isBeforeContributionDeadline(String chainDealId) {
150+
public boolean isBeforeContributionDeadline(final String chainDealId) {
154151
return getChainDeal(chainDealId)
155152
.map(this::isBeforeContributionDeadline)
156153
.orElse(false);
@@ -163,14 +160,15 @@ public boolean isBeforeContributionDeadline(String chainDealId) {
163160
* @param chainDeal blockchain ID of the deal
164161
* @return true if deadline is not reached, false otherwise.
165162
*/
166-
private boolean isBeforeContributionDeadline(ChainDeal chainDeal) {
163+
private boolean isBeforeContributionDeadline(final ChainDeal chainDeal) {
167164
return getContributionDeadline(chainDeal)
168165
.after(new Date());
169166
}
170167

171168
/**
172-
* <p> Get deal's contribution deadline date. The deadline
173-
* is calculated as follow:
169+
* Get deal's contribution deadline date.
170+
* <p>
171+
* The deadline is calculated as follows:
174172
* start + maxCategoryTime * maxNbOfPeriods.
175173
*
176174
* <ul>
@@ -182,7 +180,7 @@ private boolean isBeforeContributionDeadline(ChainDeal chainDeal) {
182180
* @param chainDeal blockchain ID of the deal
183181
* @return contribution deadline
184182
*/
185-
public Date getContributionDeadline(ChainDeal chainDeal) {
183+
private Date getContributionDeadline(final ChainDeal chainDeal) {
186184
long startTime = chainDeal.getStartTime().longValue() * 1000;
187185
long maxTime = chainDeal.getChainCategory().getMaxExecutionTime();
188186
long maxNbOfPeriods = getMaxNbOfPeriodsForConsensus();

src/main/java/com/iexec/blockchain/tool/QueueService.java renamed to src/main/java/com/iexec/blockchain/chain/QueueService.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
1-
package com.iexec.blockchain.tool;
1+
/*
2+
* Copyright 2021-2024 IEXEC BLOCKCHAIN TECH
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.iexec.blockchain.chain;
218

319
import lombok.EqualsAndHashCode;
420
import org.springframework.beans.factory.annotation.Value;
@@ -85,6 +101,7 @@ public int compareTo(@NotNull BlockchainAction other) {
85101
@EqualsAndHashCode(callSuper = true)
86102
static class TaskWithPriority<T> extends FutureTask<T> implements Comparable<TaskWithPriority<?>> {
87103
private final BlockchainAction action;
104+
88105
TaskWithPriority(Runnable task) {
89106
super(task, null);
90107
this.action = (BlockchainAction) task;

src/main/java/com/iexec/blockchain/tool/WalletConfiguration.java renamed to src/main/java/com/iexec/blockchain/chain/WalletConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.iexec.blockchain.tool;
17+
package com.iexec.blockchain.chain;
1818

1919
import com.iexec.commons.poco.chain.SignerService;
2020
import lombok.Value;

src/main/java/com/iexec/blockchain/tool/Web3jService.java renamed to src/main/java/com/iexec/blockchain/chain/Web3jService.java

Lines changed: 2 additions & 2 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.
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.iexec.blockchain.tool;
17+
package com.iexec.blockchain.chain;
1818

1919
import com.iexec.commons.poco.chain.Web3jAbstractService;
2020
import org.springframework.stereotype.Service;

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616

1717
package com.iexec.blockchain.command.generic;
1818

19-
2019
import com.iexec.blockchain.api.CommandStatus;
21-
import com.iexec.blockchain.tool.QueueService;
20+
import com.iexec.blockchain.chain.QueueService;
2221
import lombok.extern.slf4j.Slf4j;
2322
import org.web3j.protocol.core.methods.response.TransactionReceipt;
2423

src/main/java/com/iexec/blockchain/command/task/finalize/TaskFinalizeBlockchainService.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616

1717
package com.iexec.blockchain.command.task.finalize;
1818

19-
19+
import com.iexec.blockchain.chain.IexecHubService;
2020
import com.iexec.blockchain.command.generic.CommandBlockchain;
21-
import com.iexec.blockchain.tool.IexecHubService;
2221
import com.iexec.commons.poco.chain.ChainTask;
2322
import com.iexec.commons.poco.chain.ChainTaskStatus;
2423
import lombok.extern.slf4j.Slf4j;

0 commit comments

Comments
 (0)