Skip to content

Commit b48c4ae

Browse files
authored
fix: minor fixes and improvements across several classes (#164)
1 parent c9e4a07 commit b48c4ae

File tree

6 files changed

+20
-23
lines changed

6 files changed

+20
-23
lines changed

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2023 IEXEC BLOCKCHAIN TECH
2+
* Copyright 2020-2025 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,8 @@
1616

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

19-
import com.iexec.commons.poco.utils.BytesUtils;
19+
import lombok.AccessLevel;
20+
import lombok.NoArgsConstructor;
2021
import lombok.extern.slf4j.Slf4j;
2122
import org.bouncycastle.util.Arrays;
2223
import org.web3j.crypto.Hash;
@@ -28,14 +29,11 @@
2829
import java.math.BigInteger;
2930

3031
@Slf4j
32+
@NoArgsConstructor(access = AccessLevel.PRIVATE)
3133
public class ChainUtils {
3234

33-
private ChainUtils() {
34-
throw new UnsupportedOperationException();
35-
}
36-
3735
public static String generateChainTaskId(String dealId, int taskIndex) {
38-
byte[] dealIdBytes32 = BytesUtils.stringToBytes(dealId);
36+
byte[] dealIdBytes32 = Numeric.hexStringToByteArray(dealId);
3937
if (dealIdBytes32.length != 32) {
4038
return null;
4139
}
@@ -46,7 +44,7 @@ public static String generateChainTaskId(String dealId, int taskIndex) {
4644
}
4745
//concatenate bytes with same size only
4846
byte[] concatenate = Arrays.concatenate(dealIdBytes32, taskIndexBytes32);
49-
return Hash.sha3(BytesUtils.bytesToString(concatenate));
47+
return Numeric.toHexString(Hash.sha3(concatenate));
5048
}
5149

5250

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ Optional<TaskDescription> repeatGetTaskDescriptionFromChain(final String chainTa
503503
String.format("getChainApp() [address:%s]", chainDeal.getDappPointer()))
504504
.orElse(null);
505505

506-
final ChainDataset chainDataset = new Retryer<Optional<ChainDataset>>()
506+
final ChainDataset chainDataset = !chainDeal.containsDataset() ? null : new Retryer<Optional<ChainDataset>>()
507507
.repeatCall(() -> getChainDataset(chainDeal.getDataPointer()),
508508
Optional::isEmpty,
509509
retryDelay, maxRetry,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public String sendCall(String to, String data, DefaultBlockParameter defaultBloc
204204
if (ethCall.hasError()) {
205205
decodeAndThrowEvmRpcError(ethCall.getError(), "ethCall");
206206
}
207-
log.debug("ethCall [value:{}]", ethCall.getValue());
207+
log.trace("ethCall [value:{}]", ethCall.getValue());
208208
return ethCall.getValue();
209209
}
210210

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public String sendCall(final String from, final String to, final String data, fi
226226
if (ethCall.hasError()) {
227227
decodeAndThrowEvmRpcError(ethCall.getError());
228228
}
229-
log.debug("ethCall [value:{}]", ethCall.getValue());
229+
log.trace("ethCall [value:{}]", ethCall.getValue());
230230
return ethCall.getValue();
231231
}
232232

src/main/java/com/iexec/commons/poco/utils/HashUtils.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2023 IEXEC BLOCKCHAIN TECH
2+
* Copyright 2020-2025 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,32 +16,31 @@
1616

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

19-
19+
import lombok.AccessLevel;
20+
import lombok.NoArgsConstructor;
21+
import org.bouncycastle.util.Arrays;
2022
import org.web3j.crypto.Hash;
2123
import org.web3j.utils.Numeric;
2224

2325
import java.nio.charset.StandardCharsets;
2426
import java.util.Objects;
2527

28+
@NoArgsConstructor(access = AccessLevel.PRIVATE)
2629
public class HashUtils {
2730

28-
private HashUtils() {
29-
throw new UnsupportedOperationException();
30-
}
31-
3231
public static String concatenateAndHash(String... hexaString) {
3332
// convert
3433
byte[] res = new byte[0];
3534
for (String str : hexaString) {
36-
res = org.bouncycastle.util.Arrays.concatenate(res, BytesUtils.stringToBytes(str));
35+
res = Arrays.concatenate(res, Numeric.hexStringToByteArray(str));
3736
}
3837
// Hash the result and convert to String
3938
return Numeric.toHexString(Hash.sha3(res));
4039
}
41-
40+
4241
/**
4342
* Generates SHA-256 digest for the given UTF-8 string.
44-
*
43+
*
4544
* @param utf8String
4645
* @return SHA-256 digest in hex string format,
4746
* e.g: 0x66daf4e6810d83d4859846a5df1afabf88c9fda135bc732ea977f25348d98ede
@@ -54,7 +53,7 @@ public static String sha256(String utf8String) {
5453

5554
/**
5655
* Generates SHA-256 digest for the given byte array.
57-
*
56+
*
5857
* @param bytes
5958
* @return SHA-256 digest in hex string format,
6059
* e.g: 0x66daf4e6810d83d4859846a5df1afabf88c9fda135bc732ea977f25348d98ede
@@ -63,5 +62,5 @@ public static String sha256(byte[] bytes) {
6362
byte[] hexBytes = Hash.sha256(bytes);
6463
return Numeric.toHexString(hexBytes);
6564
}
66-
65+
6766
}

src/test/java/com/iexec/commons/poco/chain/IexecHubAbstractServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ private ChainDeal getMockDeal() {
297297
.chainApp(ChainApp.builder().multiaddr("").build())
298298
.chainCategory(ChainCategory.builder().build())
299299
.dappPointer("0x1")
300-
.dataPointer(BytesUtils.EMPTY_ADDRESS)
300+
.dataPointer("0x2")
301301
.category(BigInteger.ZERO)
302302
.params(DealParams.builder().build())
303303
.startTime(BigInteger.TEN)

0 commit comments

Comments
 (0)