Skip to content

Commit b9b143c

Browse files
authored
Merge pull request #45 from iExecBlockchainComputing/hotfix/3.0.5
Release version 3.0.5
2 parents 3a48ef8 + e6f3bec commit b9b143c

File tree

5 files changed

+51
-4
lines changed

5 files changed

+51
-4
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [[3.0.5]](https://github.com/iExecBlockchainComputing/iexec-commons-poco/releases/tag/v3.0.5) 2023-06-26
6+
7+
### Bug Fixes
8+
- Fix regression on dataset URI decryption in `TaskDescription`. The regression concerned bad interpretation of IPFS MultiAddress URIs. (#45)
9+
510
## [[3.0.4]](https://github.com/iExecBlockchainComputing/iexec-commons-poco/releases/tag/v3.0.4) 2023-06-23
611

712
### Bug Fixes

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version=3.0.4
1+
version=3.0.5
22

33
nexusUser
44
nexusPassword

src/main/java/com/iexec/commons/poco/task/TaskDescription.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.iexec.commons.poco.tee.TeeFramework;
2424
import com.iexec.commons.poco.tee.TeeUtils;
2525
import com.iexec.commons.poco.utils.BytesUtils;
26+
import com.iexec.commons.poco.utils.MultiAddressHelper;
2627
import lombok.Builder;
2728
import lombok.Value;
2829
import org.apache.commons.lang3.StringUtils;
@@ -141,7 +142,7 @@ public static TaskDescription toTaskDescription(String chainTaskId,
141142
String datasetChecksum = "";
142143
if (chainDeal.containsDataset()) {
143144
datasetAddress = chainDeal.getChainDataset().getChainDatasetId();
144-
datasetUri = BytesUtils.hexStringToAscii(
145+
datasetUri = MultiAddressHelper.convertToURI(
145146
chainDeal.getChainDataset().getUri());
146147
datasetName = chainDeal.getChainDataset().getName();
147148
datasetChecksum = chainDeal.getChainDataset().getChecksum();

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import io.ipfs.multiaddr.MultiAddress;
2020
import org.apache.commons.lang3.StringUtils;
21+
import org.web3j.utils.Numeric;
2122

2223
import java.util.List;
2324

@@ -33,6 +34,25 @@ private MultiAddressHelper() {
3334
throw new UnsupportedOperationException();
3435
}
3536

37+
/**
38+
* Converts the hexadecimal String stored in an on-chain deal to a human-readable format.
39+
* <p>
40+
* IPFS addresses are stored in a specific format and have to be converted with the {@link MultiAddress} constructor.
41+
* If a {@link MultiAddress} instance can be constructed, the URI it represents has been successfully converted.
42+
* In other cases, the value is considered to be a string encoded in hexadecimal and will be converted with
43+
* {@link BytesUtils#hexStringToAscii(String)}.
44+
*
45+
* @param hexaString String to convert
46+
* @return Conversion result
47+
*/
48+
public static String convertToURI(String hexaString) {
49+
try {
50+
return new MultiAddress(Numeric.hexStringToByteArray(hexaString)).toString();
51+
} catch (Exception e) {
52+
return BytesUtils.hexStringToAscii(hexaString);
53+
}
54+
}
55+
3656
public static boolean isMultiAddress(String uri) {
3757
if (StringUtils.isBlank(uri)) {
3858
return false;

src/test/java/com/iexec/commons/poco/utils/MultiAddressHelperTests.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,32 @@
2121
import org.junit.jupiter.params.provider.NullAndEmptySource;
2222
import org.junit.jupiter.params.provider.ValueSource;
2323

24-
import static org.junit.jupiter.api.Assertions.assertFalse;
25-
import static org.junit.jupiter.api.Assertions.assertTrue;
24+
import static org.junit.jupiter.api.Assertions.*;
2625

2726
class MultiAddressHelperTests {
2827

28+
@Test
29+
void shouldConvertToIPFSAddress() {
30+
String content = MultiAddressHelper.convertToURI("0xa5032212205d008f22f8f878fd58473a634cc73d41049fc0d19b81002eaae221ac5a446a3e");
31+
String expected = "/ipfs/QmUbh7ugQ9WVprTVYjzrCS4d9cCy73zUz4MMchsrqzzu1w";
32+
33+
assertEquals(content, expected);
34+
35+
content = MultiAddressHelper.convertToURI("0xa5032212207237a7f4091a74ae95514890fa86a2e8a36037c350ea71c06a34c8cbe25a5057");
36+
expected = "/ipfs/QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ";
37+
38+
assertEquals(content, expected);
39+
}
40+
41+
@Test
42+
void shouldConvertToHTTPAddress() {
43+
// this is hexa value of an HTTP address in String format, not in multiaddress format!
44+
String content = MultiAddressHelper.convertToURI("0x68747470733a2f2f676174657761792e697066732e696f2f697066732f516d5732575169376a36633755674a546172416374703774444e696b453442327158744643664c506473676154512f6361742e6a7067");
45+
String expected = "https://gateway.ipfs.io/ipfs/QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ/cat.jpg";
46+
47+
assertEquals(content, expected);
48+
}
49+
2950
@Test
3051
void shouldBeMultiAddress() {
3152
assertTrue(MultiAddressHelper.isMultiAddress("/ipfs/QmUbh7ugQ9WVprTVYjzrCS4d9cCy73zUz4MMchsrqzzu1w"));

0 commit comments

Comments
 (0)