Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update web3j, removed epirus, updater fix #116

Merged
merged 4 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 1 addition & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@ plugins {
id "de.undercouch.download" version "4.1.2"
id "de.marcphilipp.nexus-publish" version "0.4.0"
id 'io.codearte.nexus-staging' version '0.30.0'
// TODO decide if kept or not
// id "com.jfrog.bintray" version "1.8.4"
}

description 'Web3j command line tools'
mainClassName = 'org.web3j.console.Web3j'
applicationName = 'web3j'

ext {
web3jVersion = '4.12.1'
web3jVersion = '4.12.2'
picocli = '4.7.6'
slf4jVersion = '2.0.13'
junitVersion = '5.9.3'
Expand All @@ -30,7 +28,6 @@ ext {
wireMockVersion = '3.6.0'
kotlinLoggin = '3.0.5'
dockerJavaVersion = '3.3.6'
web3jEpirusVersion = '0.0.6'
log4jVersion = '2.23.1'
semverVersion = '0.10.2'
commonsLangVersion = '3.14.0'
Expand Down Expand Up @@ -91,7 +88,6 @@ dependencies {
"org.web3j:core:$web3jVersion",
"org.web3j:crypto:$web3jVersion",
"org.web3j:hosted-providers:$web3jVersion",
"io.epirus:epirus-web3j:$web3jEpirusVersion",
"info.picocli:picocli:$picocli",
"com.squareup:kotlinpoet:$kotlinPoetVersion",
"com.squareup:javapoet:$javaPoetVersion",
Expand Down
64 changes: 25 additions & 39 deletions src/main/java/org/web3j/console/services/Updater.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,74 +15,60 @@
import java.io.IOException;

import com.github.zafarkhaja.semver.Version;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import okhttp3.*;

import org.web3j.console.utils.CliVersion;
import org.web3j.console.utils.OSUtils;

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

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

public static void promptIfUpdateAvailable() throws IOException {
String version = CliVersion.getVersion();
if (config.getLatestVersion() != null
&& Version.valueOf(config.getLatestVersion()).greaterThan(Version.valueOf(version))
String version = CliVersion.getVersion(); // Get current version from CLI
String latestVersion = getLatestVersionFromGitHub(); // Fetch latest version from GitHub

if (latestVersion != null
&& Version.valueOf(latestVersion).greaterThan(Version.valueOf(version))
&& !version.contains("SNAPSHOT")) {
System.out.println(
String.format(
"Your current Web3j version is: "
+ version
+ ". The latest Version is: "
+ config.getLatestVersion()
+ latestVersion
+ ". To update, run: %s",
config.getUpdatePrompt()));
}
}

public static void onlineUpdateCheck() {
onlineUpdateCheck(DEFAULT_UPDATE_URL);
try {
promptIfUpdateAvailable();
} catch (IOException e) {
throw new RuntimeException(e);
}
}

public static void onlineUpdateCheck(String updateUrl) {
public static String getLatestVersionFromGitHub() {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url(GITHUB_API_URL).get().build();

RequestBody updateBody =
new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("os", OSUtils.determineOS().toString())
.addFormDataPart("clientId", config.getClientId())
.addFormDataPart("data", "update_check")
.build();

Request updateCheckRequest = new Request.Builder().url(updateUrl).post(updateBody).build();

try {
Response sendRawResponse = client.newCall(updateCheckRequest).execute();
JsonElement element;
ResponseBody body;
if (sendRawResponse.code() == 200
&& (body = sendRawResponse.body()) != null
&& (element = JsonParser.parseString(body.string())) != null
&& element.isJsonObject()) {
JsonObject rootObj = element.getAsJsonObject().get("latest").getAsJsonObject();
String latestVersion = rootObj.get("version").getAsString();
if (!latestVersion.equals(CliVersion.getVersion())) {
config.setLatestVersion(latestVersion);
config.setUpdatePrompt(
rootObj.get(
OSUtils.determineOS() == OSUtils.OS.WINDOWS
? "install_win"
: "install_unix")
.getAsString());
try (Response response = client.newCall(request).execute()) {
if (response.isSuccessful()) {
ResponseBody body = response.body();
if (body != null) {
JsonObject jsonObject = JsonParser.parseString(body.string()).getAsJsonObject();
String tagName = jsonObject.get("tag_name").getAsString();
return tagName.replace("v", "");
}
}
} catch (Exception ignored) {
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
32 changes: 0 additions & 32 deletions src/main/java/org/web3j/console/wallet/Faucet.java

This file was deleted.

3 changes: 1 addition & 2 deletions src/main/java/org/web3j/console/wallet/WalletCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
WalletCreateCommand.class,
WalletUpdateCommand.class,
WalletSendCommand.class,
WalletImportCommand.class,
WalletFundCommand.class
WalletImportCommand.class
},
versionProvider = Web3jVersionProvider.class,
synopsisHeading = "%n",
Expand Down
Loading