From 03cc9c587cae67c6fd65d82328c4977dea74cb95 Mon Sep 17 00:00:00 2001
From: Conor
Date: Fri, 11 Nov 2016 09:57:00 +1100
Subject: [PATCH] 1. Solidity generator: fixed issue where no-arg constructor
functions were not being generated correctly. 2. Updated Solidity generator.
3. Added logic to test for file existence with wallet tools before asking
for password. 4. Fixed bug in wallet file generator where 12 hour clocks we
being used in filename. 5. Bumped version.
---
README.rst | 4 ++--
build.gradle | 2 +-
docs/source/getting_started.rst | 4 ++--
.../SolidityFunctionWrapperGenerator.java | 21 ++++++++++++++-----
src/main/java/org/web3j/console/Runner.java | 4 ++--
.../java/org/web3j/console/WalletManager.java | 7 +++++++
.../java/org/web3j/console/WalletRunner.java | 4 ++++
.../java/org/web3j/console/WalletUpdater.java | 2 +-
.../java/org/web3j/crypto/WalletUtils.java | 2 +-
9 files changed, 36 insertions(+), 14 deletions(-)
diff --git a/README.rst b/README.rst
index bc66bbed5..ef66b1cc8 100644
--- a/README.rst
+++ b/README.rst
@@ -69,7 +69,7 @@ Maven
org.web3j
core
- 1.0.3
+ 1.0.4
Gradle
@@ -77,7 +77,7 @@ Gradle
.. code-block:: groovy
- compile ('org.web3j:core:1.0.3')
+ compile ('org.web3j:core:1.0.4')
Start a client
diff --git a/build.gradle b/build.gradle
index 1c25b2579..e22bacdf5 100644
--- a/build.gradle
+++ b/build.gradle
@@ -26,7 +26,7 @@ apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'application'
group 'org.web3j'
-version '1.0.3'
+version '1.0.4'
sourceCompatibility = 1.8
diff --git a/docs/source/getting_started.rst b/docs/source/getting_started.rst
index 9985ba7db..edd571ee9 100644
--- a/docs/source/getting_started.rst
+++ b/docs/source/getting_started.rst
@@ -11,7 +11,7 @@ Maven
org.web3j
core
- 1.0.3
+ 1.0.4
Gradle
@@ -19,7 +19,7 @@ Gradle
.. code-block:: groovy
- compile ('org.web3j:core:1.0.3')
+ compile ('org.web3j:core:1.0.4')
Start a client
diff --git a/src/main/java/org/web3j/codegen/SolidityFunctionWrapperGenerator.java b/src/main/java/org/web3j/codegen/SolidityFunctionWrapperGenerator.java
index c4ae2e0fb..3bd17e673 100644
--- a/src/main/java/org/web3j/codegen/SolidityFunctionWrapperGenerator.java
+++ b/src/main/java/org/web3j/codegen/SolidityFunctionWrapperGenerator.java
@@ -27,6 +27,8 @@
import org.web3j.protocol.core.methods.response.AbiDefinition;
import org.web3j.protocol.core.methods.response.TransactionReceipt;
+import static org.web3j.utils.Collection.tail;
+
/**
* Java wrapper source code generator for Solidity ABI format.
*/
@@ -43,7 +45,7 @@ public class SolidityFunctionWrapperGenerator extends Generator {
"Please use {@link " + SolidityFunctionWrapperGenerator.class.getName() +
"} to update.
\n";
- private static final String USAGE = "solidity " +
+ private static final String USAGE = "solidity generate " +
".bin .abi " +
"[-p|--package ] " +
"-o|--output ";
@@ -65,6 +67,14 @@ private SolidityFunctionWrapperGenerator(
this.basePackageName = basePackageName;
}
+ public static void run(String[] args) throws Exception {
+ if (args.length < 1 || !args[0].equals("generate")) {
+ exitError(USAGE);
+ } else {
+ main(tail(args));
+ }
+ }
+
public static void main(String[] args) throws Exception {
if (args.length != 6) {
@@ -244,11 +254,12 @@ private static MethodSpec buildDeploy(
"$T.asList($L)" +
")",
String.class, FunctionEncoder.class, Arrays.class, inputParams);
+ methodBuilder.addStatement("return deployAsync($L.class, $L, $L, $L, encodedConstructor, $L)",
+ className, WEB3J, CREDENTIALS, BINARY, INITIAL_VALUE);
+ } else {
+ methodBuilder.addStatement("return deployAsync($L.class, $L, $L, $L, \"\", $L)",
+ className, WEB3J, CREDENTIALS, BINARY, INITIAL_VALUE);
}
-
- methodBuilder.addStatement("return deployAsync($L.class, $L, $L, $L, encodedConstructor, $L)",
- className, WEB3J, CREDENTIALS, BINARY, INITIAL_VALUE);
-
return methodBuilder.build();
}
diff --git a/src/main/java/org/web3j/console/Runner.java b/src/main/java/org/web3j/console/Runner.java
index 18bf22d4e..fef01c58f 100644
--- a/src/main/java/org/web3j/console/Runner.java
+++ b/src/main/java/org/web3j/console/Runner.java
@@ -30,10 +30,10 @@ public static void main(String[] args) throws Exception {
} else {
switch (args[0]) {
case "wallet":
- WalletRunner.main(tail(args));
+ WalletRunner.run(tail(args));
break;
case "solidity":
- SolidityFunctionWrapperGenerator.main(tail(args));
+ SolidityFunctionWrapperGenerator.run(tail(args));
break;
default:
Console.exitError(USAGE);
diff --git a/src/main/java/org/web3j/console/WalletManager.java b/src/main/java/org/web3j/console/WalletManager.java
index c9b0d70da..b76f609e3 100644
--- a/src/main/java/org/web3j/console/WalletManager.java
+++ b/src/main/java/org/web3j/console/WalletManager.java
@@ -70,6 +70,13 @@ File createDir(String destinationDir) {
}
Credentials getCredentials(File walletFile) {
+ if (!walletFile.exists() || !walletFile.isFile()) {
+ exitError("Unable to read wallet file: " + walletFile);
+ }
+ return loadWalletFile(walletFile);
+ }
+
+ private Credentials loadWalletFile(File walletFile) {
while (true) {
char[] password = console.readPassword(
"Please enter your existing your wallet file password: ");
diff --git a/src/main/java/org/web3j/console/WalletRunner.java b/src/main/java/org/web3j/console/WalletRunner.java
index 1257f2244..f7254e896 100644
--- a/src/main/java/org/web3j/console/WalletRunner.java
+++ b/src/main/java/org/web3j/console/WalletRunner.java
@@ -10,6 +10,10 @@
public class WalletRunner {
private static final String USAGE = "wallet create|update|send";
+ public static void run(String[] args) {
+ main(args);
+ }
+
public static void main(String[] args) {
if (args.length < 1) {
Console.exitError(USAGE);
diff --git a/src/main/java/org/web3j/console/WalletUpdater.java b/src/main/java/org/web3j/console/WalletUpdater.java
index 7b0a0b27e..98ee7d061 100644
--- a/src/main/java/org/web3j/console/WalletUpdater.java
+++ b/src/main/java/org/web3j/console/WalletUpdater.java
@@ -48,7 +48,7 @@ private void run(String walletFileLocation) {
if (!walletFile.delete()) {
exitError("Unable to remove wallet file\n");
} else {
- console.printf("File successfully removed\n");
+ console.printf("Deleted previous wallet file: %s\n", walletFile.getName());
}
}
}
diff --git a/src/main/java/org/web3j/crypto/WalletUtils.java b/src/main/java/org/web3j/crypto/WalletUtils.java
index c8251963f..1fbbc1c58 100644
--- a/src/main/java/org/web3j/crypto/WalletUtils.java
+++ b/src/main/java/org/web3j/crypto/WalletUtils.java
@@ -55,7 +55,7 @@ public static Credentials loadCredentials(String password, File source)
private static String getWalletFileName(WalletFile walletFile) {
DateTimeFormatter format = DateTimeFormatter.ofPattern(
- "'UTC--'yyyy-MM-dd'T'hh-mm-ss.nVV'--'");
+ "'UTC--'yyyy-MM-dd'T'HH-mm-ss.nVV'--'");
ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
return now.format(format) + walletFile.getAddress() + ".json";