Skip to content

Commit 873576c

Browse files
authored
Merge pull request #116 from hyperledger/removeEpirus
update web3j, removed epirus, updater fix
2 parents c4ef2f5 + c236d2a commit 873576c

File tree

7 files changed

+96
-368
lines changed

7 files changed

+96
-368
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
1111

1212
### Features
1313

14-
*
14+
* Updated web3j to 4.12.2 and removed Epirus [#116](https://github.com/hyperledger/web3j-cli/pull/116)
1515

1616
### BREAKING CHANGES
1717

build.gradle

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,14 @@ plugins {
1111
id "de.undercouch.download" version "4.1.2"
1212
id "de.marcphilipp.nexus-publish" version "0.4.0"
1313
id 'io.codearte.nexus-staging' version '0.30.0'
14-
// TODO decide if kept or not
15-
// id "com.jfrog.bintray" version "1.8.4"
1614
}
1715

1816
description 'Web3j command line tools'
1917
mainClassName = 'org.web3j.console.Web3j'
2018
applicationName = 'web3j'
2119

2220
ext {
23-
web3jVersion = '4.12.1'
21+
web3jVersion = '4.12.2'
2422
picocli = '4.7.6'
2523
slf4jVersion = '2.0.13'
2624
junitVersion = '5.9.3'
@@ -30,7 +28,6 @@ ext {
3028
wireMockVersion = '3.6.0'
3129
kotlinLoggin = '3.0.5'
3230
dockerJavaVersion = '3.3.6'
33-
web3jEpirusVersion = '0.0.6'
3431
log4jVersion = '2.23.1'
3532
semverVersion = '0.10.2'
3633
commonsLangVersion = '3.14.0'
@@ -91,7 +88,6 @@ dependencies {
9188
"org.web3j:core:$web3jVersion",
9289
"org.web3j:crypto:$web3jVersion",
9390
"org.web3j:hosted-providers:$web3jVersion",
94-
"io.epirus:epirus-web3j:$web3jEpirusVersion",
9591
"info.picocli:picocli:$picocli",
9692
"com.squareup:kotlinpoet:$kotlinPoetVersion",
9793
"com.squareup:javapoet:$javaPoetVersion",

src/main/java/org/web3j/console/services/Updater.java

Lines changed: 25 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,74 +15,60 @@
1515
import java.io.IOException;
1616

1717
import com.github.zafarkhaja.semver.Version;
18-
import com.google.gson.JsonElement;
1918
import com.google.gson.JsonObject;
2019
import com.google.gson.JsonParser;
2120
import okhttp3.*;
2221

2322
import org.web3j.console.utils.CliVersion;
24-
import org.web3j.console.utils.OSUtils;
2523

2624
import static org.web3j.console.config.ConfigManager.config;
2725

2826
public class Updater {
29-
private static final String DEFAULT_UPDATE_URL =
30-
"https://internal.services.web3labs.com/api/epirus/versions/latest";
27+
private static final String GITHUB_API_URL =
28+
"https://api.github.com/repos/hyperledger/web3j-cli/releases/latest";
3129

3230
public static void promptIfUpdateAvailable() throws IOException {
33-
String version = CliVersion.getVersion();
34-
if (config.getLatestVersion() != null
35-
&& Version.valueOf(config.getLatestVersion()).greaterThan(Version.valueOf(version))
31+
String version = CliVersion.getVersion(); // Get current version from CLI
32+
String latestVersion = getLatestVersionFromGitHub(); // Fetch latest version from GitHub
33+
34+
if (latestVersion != null
35+
&& Version.valueOf(latestVersion).greaterThan(Version.valueOf(version))
3636
&& !version.contains("SNAPSHOT")) {
3737
System.out.println(
3838
String.format(
3939
"Your current Web3j version is: "
4040
+ version
4141
+ ". The latest Version is: "
42-
+ config.getLatestVersion()
42+
+ latestVersion
4343
+ ". To update, run: %s",
4444
config.getUpdatePrompt()));
4545
}
4646
}
4747

4848
public static void onlineUpdateCheck() {
49-
onlineUpdateCheck(DEFAULT_UPDATE_URL);
49+
try {
50+
promptIfUpdateAvailable();
51+
} catch (IOException e) {
52+
throw new RuntimeException(e);
53+
}
5054
}
5155

52-
public static void onlineUpdateCheck(String updateUrl) {
56+
public static String getLatestVersionFromGitHub() {
5357
OkHttpClient client = new OkHttpClient();
58+
Request request = new Request.Builder().url(GITHUB_API_URL).get().build();
5459

55-
RequestBody updateBody =
56-
new MultipartBody.Builder()
57-
.setType(MultipartBody.FORM)
58-
.addFormDataPart("os", OSUtils.determineOS().toString())
59-
.addFormDataPart("clientId", config.getClientId())
60-
.addFormDataPart("data", "update_check")
61-
.build();
62-
63-
Request updateCheckRequest = new Request.Builder().url(updateUrl).post(updateBody).build();
64-
65-
try {
66-
Response sendRawResponse = client.newCall(updateCheckRequest).execute();
67-
JsonElement element;
68-
ResponseBody body;
69-
if (sendRawResponse.code() == 200
70-
&& (body = sendRawResponse.body()) != null
71-
&& (element = JsonParser.parseString(body.string())) != null
72-
&& element.isJsonObject()) {
73-
JsonObject rootObj = element.getAsJsonObject().get("latest").getAsJsonObject();
74-
String latestVersion = rootObj.get("version").getAsString();
75-
if (!latestVersion.equals(CliVersion.getVersion())) {
76-
config.setLatestVersion(latestVersion);
77-
config.setUpdatePrompt(
78-
rootObj.get(
79-
OSUtils.determineOS() == OSUtils.OS.WINDOWS
80-
? "install_win"
81-
: "install_unix")
82-
.getAsString());
60+
try (Response response = client.newCall(request).execute()) {
61+
if (response.isSuccessful()) {
62+
ResponseBody body = response.body();
63+
if (body != null) {
64+
JsonObject jsonObject = JsonParser.parseString(body.string()).getAsJsonObject();
65+
String tagName = jsonObject.get("tag_name").getAsString();
66+
return tagName.replace("v", "");
8367
}
8468
}
85-
} catch (Exception ignored) {
69+
} catch (IOException e) {
70+
e.printStackTrace();
8671
}
72+
return null;
8773
}
8874
}

src/main/java/org/web3j/console/wallet/Faucet.java

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/main/java/org/web3j/console/wallet/WalletCommand.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
WalletCreateCommand.class,
3030
WalletUpdateCommand.class,
3131
WalletSendCommand.class,
32-
WalletImportCommand.class,
33-
WalletFundCommand.class
32+
WalletImportCommand.class
3433
},
3534
versionProvider = Web3jVersionProvider.class,
3635
synopsisHeading = "%n",

0 commit comments

Comments
 (0)