diff --git a/ethereumj-core/pom.xml b/ethereumj-core/pom.xml index b1dd82d4..b00cb91a 100644 --- a/ethereumj-core/pom.xml +++ b/ethereumj-core/pom.xml @@ -175,6 +175,7 @@ mvn clean package -Dmaven.test.skip=true org.apache.maven.plugins maven-jar-plugin + 2.4 diff --git a/ethereumj-core/src/main/java/org/ethereum/core/Block.java b/ethereumj-core/src/main/java/org/ethereum/core/Block.java index f1d36e84..392f5433 100644 --- a/ethereumj-core/src/main/java/org/ethereum/core/Block.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/Block.java @@ -6,6 +6,7 @@ import org.ethereum.util.RLP; import org.ethereum.util.RLPElement; import org.ethereum.util.RLPItem; import org.ethereum.util.RLPList; +import org.ethereum.util.Utils; import java.math.BigInteger; import java.util.ArrayList; @@ -129,7 +130,7 @@ public class Block { this.minGasPrice = gpBytes == null ? 0 : (new BigInteger(1, gpBytes)).longValue(); this.gasLimit = glBytes == null ? 0 : (new BigInteger(1, glBytes)).longValue(); this.gasUsed = guBytes == null ? 0 : (new BigInteger(1, guBytes)).longValue(); - this.timestamp = tsBytes == null ? 0 : (new BigInteger(1, tsBytes)).longValue(); + this.timestamp = tsBytes == null ? 0 : (new BigInteger(tsBytes)).longValue(); this.extraData = ((RLPItem) header.get(11)).getRLPData(); this.nonce = ((RLPItem) header.get(12)).getRLPData(); @@ -270,7 +271,7 @@ public class Block { toStringBuff.append(" minGasPrice=" + minGasPrice).append("\n"); toStringBuff.append(" gasLimit=" + gasLimit).append("\n"); toStringBuff.append(" gasUsed=" + gasUsed).append("\n"); - toStringBuff.append(" timestamp=" + timestamp).append("\n"); + toStringBuff.append(" timestamp=" + timestamp + " (" + Utils.longToDateTime(timestamp) + ")").append("\n"); toStringBuff.append(" extraData=" + ByteUtil.toHexString(extraData)).append("\n"); toStringBuff.append(" nonce=" + ByteUtil.toHexString(nonce)).append("\n"); diff --git a/ethereumj-core/src/main/java/org/ethereum/util/ByteUtil.java b/ethereumj-core/src/main/java/org/ethereum/util/ByteUtil.java index 85699fa7..378e1f8b 100644 --- a/ethereumj-core/src/main/java/org/ethereum/util/ByteUtil.java +++ b/ethereumj-core/src/main/java/org/ethereum/util/ByteUtil.java @@ -27,9 +27,8 @@ public class ByteUtil { * @return numBytes byte long array. */ public static byte[] bigIntegerToBytes(BigInteger b, int numBytes) { - if (b == null) { - return null; - } + if (b == null) + return null; byte[] bytes = new byte[numBytes]; byte[] biBytes = b.toByteArray(); int start = (biBytes.length == numBytes + 1) ? 1 : 0; @@ -85,7 +84,6 @@ public class ByteUtil { return new BigInteger(1, b).intValue(); } - /** * Calculate the number of bytes need * to encode the number @@ -93,69 +91,60 @@ public class ByteUtil { * @param val - number * @return number of min bytes used to encode the number */ - public static int numBytes(String val){ + public static int numBytes(String val) { BigInteger bInt = new BigInteger(val); int bytes = 0; - while(!bInt.equals(BigInteger.ZERO)){ - + while(!bInt.equals(BigInteger.ZERO)) { bInt = bInt.shiftRight(8); ++bytes; } - if (bytes == 0) ++bytes; - return bytes; } - /** * @param arg - not more that 32 bits - * @return - byts of the value pad with complete to 32 zeroes + * @return - bytes of the value pad with complete to 32 zeroes */ - public static byte[] encodeValFor32Bits(Object arg){ + public static byte[] encodeValFor32Bits(Object arg) { - byte[] data; + byte[] data; - // check if the string is numeric - if (arg.toString().trim().matches("-?\\d+(\\.\\d+)?")){ + // check if the string is numeric + if (arg.toString().trim().matches("-?\\d+(\\.\\d+)?")) { + data = new BigInteger(arg.toString().trim()).toByteArray(); + } else { + data = arg.toString().trim().getBytes(); + } - data = new BigInteger(arg.toString().trim()).toByteArray(); - }else{ - data = arg.toString().trim().getBytes(); - } + if (data.length > 32) + throw new RuntimeException("values can't be more than 32 bits"); - if (data.length > 32) throw new Error("values can't be more than 32 bits"); + byte[] val = new byte[32]; - byte[] val = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; + int j = 0; + for (int i = data.length; i > 0; --i) { + val[31 - j] = data[i - 1]; + ++j; + } + return val; + } - int j = 0; - for (int i = data.length; i > 0; --i){ - val[31 - j] = data[i-1]; - ++j; - } - - return val; - } - - - /** - * encode the values and concatenate together - */ - public static byte[] encodeDataList(Object... args){ - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - for (Object arg : args){ - - byte[] val = encodeValFor32Bits(arg); - try { - baos.write(val); - } catch (IOException e) { - throw new Error("Happen something that should never happen ", e); - } - } - - return baos.toByteArray(); - } -} + /** + * encode the values and concatenate together + */ + public static byte[] encodeDataList(Object... args) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + for (Object arg : args) { + byte[] val = encodeValFor32Bits(arg); + try { + baos.write(val); + } catch (IOException e) { + throw new Error("Happen something that should never happen ", e); + } + } + return baos.toByteArray(); + } +} \ No newline at end of file diff --git a/ethereumj-core/src/main/java/org/ethereum/util/Utils.java b/ethereumj-core/src/main/java/org/ethereum/util/Utils.java index 0d395d5b..88c6feb3 100644 --- a/ethereumj-core/src/main/java/org/ethereum/util/Utils.java +++ b/ethereumj-core/src/main/java/org/ethereum/util/Utils.java @@ -3,6 +3,9 @@ package org.ethereum.util; import java.math.BigInteger; import java.net.URL; import java.security.SecureRandom; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.regex.Pattern; import javax.swing.ImageIcon; @@ -26,6 +29,12 @@ public class Utils { return (new BigInteger(1, numberBytes)).toString(); } + public static String longToDateTime(long timestamp) { + Date date = new Date(timestamp * 1000); + DateFormat formatter = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss"); + return formatter.format(date); + } + public static ImageIcon getImageIcon(String resource){ URL imageURL = ClassLoader.getSystemResource(resource); ImageIcon image = new ImageIcon(imageURL); diff --git a/ethereumj-core/src/main/resources/config/run.sh b/ethereumj-core/src/main/resources/config/run.sh new file mode 100644 index 00000000..cae7f579 --- /dev/null +++ b/ethereumj-core/src/main/resources/config/run.sh @@ -0,0 +1 @@ +java -Dlog4j.configuration=file:./config/log4j.properties -jar ethereumj.jar