Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions src/main/java/com/iexec/commons/poco/chain/ChainUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2023 IEXEC BLOCKCHAIN TECH
* Copyright 2020-2025 IEXEC BLOCKCHAIN TECH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,7 +16,8 @@

package com.iexec.commons.poco.chain;

import com.iexec.commons.poco.utils.BytesUtils;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.bouncycastle.util.Arrays;
import org.web3j.crypto.Hash;
Expand All @@ -28,14 +29,11 @@
import java.math.BigInteger;

@Slf4j
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class ChainUtils {

private ChainUtils() {
throw new UnsupportedOperationException();
}

public static String generateChainTaskId(String dealId, int taskIndex) {
byte[] dealIdBytes32 = BytesUtils.stringToBytes(dealId);
byte[] dealIdBytes32 = Numeric.hexStringToByteArray(dealId);
if (dealIdBytes32.length != 32) {
return null;
}
Expand All @@ -46,7 +44,7 @@ public static String generateChainTaskId(String dealId, int taskIndex) {
}
//concatenate bytes with same size only
byte[] concatenate = Arrays.concatenate(dealIdBytes32, taskIndexBytes32);
return Hash.sha3(BytesUtils.bytesToString(concatenate));
return Numeric.toHexString(Hash.sha3(concatenate));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ Optional<TaskDescription> repeatGetTaskDescriptionFromChain(final String chainTa
String.format("getChainApp() [address:%s]", chainDeal.getDappPointer()))
.orElse(null);

final ChainDataset chainDataset = new Retryer<Optional<ChainDataset>>()
final ChainDataset chainDataset = !chainDeal.containsDataset() ? null : new Retryer<Optional<ChainDataset>>()
.repeatCall(() -> getChainDataset(chainDeal.getDataPointer()),
Optional::isEmpty,
retryDelay, maxRetry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public String sendCall(String to, String data, DefaultBlockParameter defaultBloc
if (ethCall.hasError()) {
decodeAndThrowEvmRpcError(ethCall.getError(), "ethCall");
}
log.debug("ethCall [value:{}]", ethCall.getValue());
log.trace("ethCall [value:{}]", ethCall.getValue());
return ethCall.getValue();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public String sendCall(final String from, final String to, final String data, fi
if (ethCall.hasError()) {
decodeAndThrowEvmRpcError(ethCall.getError());
}
log.debug("ethCall [value:{}]", ethCall.getValue());
log.trace("ethCall [value:{}]", ethCall.getValue());
return ethCall.getValue();
}

Expand Down
21 changes: 10 additions & 11 deletions src/main/java/com/iexec/commons/poco/utils/HashUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2023 IEXEC BLOCKCHAIN TECH
* Copyright 2020-2025 IEXEC BLOCKCHAIN TECH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,32 +16,31 @@

package com.iexec.commons.poco.utils;


import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.bouncycastle.util.Arrays;
import org.web3j.crypto.Hash;
import org.web3j.utils.Numeric;

import java.nio.charset.StandardCharsets;
import java.util.Objects;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class HashUtils {

private HashUtils() {
throw new UnsupportedOperationException();
}

public static String concatenateAndHash(String... hexaString) {
// convert
byte[] res = new byte[0];
for (String str : hexaString) {
res = org.bouncycastle.util.Arrays.concatenate(res, BytesUtils.stringToBytes(str));
res = Arrays.concatenate(res, Numeric.hexStringToByteArray(str));
}
// Hash the result and convert to String
return Numeric.toHexString(Hash.sha3(res));
}

/**
* Generates SHA-256 digest for the given UTF-8 string.
*
*
* @param utf8String
* @return SHA-256 digest in hex string format,
* e.g: 0x66daf4e6810d83d4859846a5df1afabf88c9fda135bc732ea977f25348d98ede
Expand All @@ -54,7 +53,7 @@ public static String sha256(String utf8String) {

/**
* Generates SHA-256 digest for the given byte array.
*
*
* @param bytes
* @return SHA-256 digest in hex string format,
* e.g: 0x66daf4e6810d83d4859846a5df1afabf88c9fda135bc732ea977f25348d98ede
Expand All @@ -63,5 +62,5 @@ public static String sha256(byte[] bytes) {
byte[] hexBytes = Hash.sha256(bytes);
return Numeric.toHexString(hexBytes);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ private ChainDeal getMockDeal() {
.chainApp(ChainApp.builder().multiaddr("").build())
.chainCategory(ChainCategory.builder().build())
.dappPointer("0x1")
.dataPointer(BytesUtils.EMPTY_ADDRESS)
.dataPointer("0x2")
.category(BigInteger.ZERO)
.params(DealParams.builder().build())
.startTime(BigInteger.TEN)
Expand Down