Fix null key in Transaction.getSender() Update Log version and removed unused imports

This commit is contained in:
nicksavers 2014-05-23 01:16:20 +02:00
parent 7bd236db23
commit d0fc754f55
22 changed files with 29 additions and 95 deletions

View File

@ -9,7 +9,6 @@
<url>http://www.ethereumj.org</url>
<!--
* To deploy all the classes and dependencies to one jar,
* that's one option to pack stand alone.
mvn clean package dependency:copy-dependencies -Dmaven.test.skip=true
@ -100,7 +99,7 @@ mvn clean package -Dmaven.test.skip=true
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.7</version>
<version>${slf4j.version}</version>
<scope>compile</scope>
</dependency>
@ -109,7 +108,7 @@ mvn clean package -Dmaven.test.skip=true
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.5.6</version>
<version>${slf4j.version}</version>
<scope>runtime</scope>
</dependency>
@ -118,7 +117,7 @@ mvn clean package -Dmaven.test.skip=true
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.5</version>
<version>${slf4j.version}</version>
<scope>runtime</scope>
</dependency>

View File

@ -7,6 +7,8 @@ import org.ethereum.util.ByteUtil;
import org.ethereum.util.RLP;
import org.ethereum.util.RLPItem;
import org.ethereum.util.RLPList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spongycastle.util.BigIntegers;
import java.security.SignatureException;
@ -22,6 +24,8 @@ import java.util.Arrays;
*/
public class Transaction {
Logger logger = LoggerFactory.getLogger(this.getClass());
private static final int CALL_SIZE = 9;
private static final int CONTRACT_SIZE = 10;
@ -183,16 +187,14 @@ public class Transaction {
return ECKey.recoverFromSignature(signature.v, signature, hash, true);
}
public byte[] sender() {
ECKey key = null;
try {
key = ECKey.signatureToKey(getHash(), getSignature().toBase64());
} catch (SignatureException e) {
e.printStackTrace();
}
return key.getAddress();
public byte[] getSender() {
try {
ECKey key = ECKey.signatureToKey(getHash(), getSignature().toBase64());
return key.getAddress();
} catch (SignatureException e) {
logger.error(e.getMessage(), e);
}
return null;
}
public void sign(byte[] privKeyBytes) throws Exception {

View File

@ -37,7 +37,7 @@ public class Wallet {
private HashMap<String, AddressState> rows = new HashMap<String, AddressState>();
private long high;
private List<WalletListener> listeners = new ArrayList();
private List<WalletListener> listeners = new ArrayList<WalletListener>();
public void addNewKey(){
@ -96,7 +96,7 @@ public class Wallet {
for (Transaction tx : transactions){
byte[] senderAddress = tx.sender();
byte[] senderAddress = tx.getSender();
AddressState senderState = rows.get(Hex.toHexString(senderAddress));
if (senderState != null){
BigInteger value = new BigInteger(tx.getValue());
@ -169,9 +169,6 @@ public class Wallet {
// this.importKey(privKey);
// this.setBalance(address, value);
}
}
/**
@ -257,7 +254,6 @@ public class Wallet {
public void valueChanged();
}
public long getHigh() {
return high;
}

View File

@ -2,7 +2,6 @@ package org.ethereum.geodb;
import java.io.File;
import java.net.InetAddress;
import java.net.URISyntaxException;
import java.net.URL;
import com.maxmind.geoip.Location;

View File

@ -1,7 +1,6 @@
package org.ethereum.gui;
import org.ethereum.manager.MainData;
import org.spongycastle.util.encoders.Hex;
import javax.swing.table.AbstractTableModel;
@ -12,8 +11,6 @@ import javax.swing.table.AbstractTableModel;
*/
public class BlockTableModel extends AbstractTableModel {
@Override
public int getRowCount() {

View File

@ -69,17 +69,12 @@ public class ConnectionConsoleWindow extends JFrame implements PeerListener{
Thread t = new Thread() {
public void run() {
// new ClientPeer(thisConsole).connect("54.201.28.117", 30303); // peer discovery
// new ClientPeer(thisConsole).connect("82.217.72.169", 30303); // Nick
// new ClientPeer(thisConsole).connect("131.104.247.135", 30303); // Some dude in Canada
// new ClientPeer(thisConsole).connect("54.204.10.41", 30303);
// new ClientPeer(thisConsole).connect("54.204.10.41", 30303); // CPP: ZeroGox Poc5
// new ClientPeer(thisConsole).connect("54.201.28.117", 30303); // peer discovery
// new ClientPeer(thisConsole).connect("54.204.10.41", 30303);
// new ClientPeer(thisConsole).connect("131.104.247.135", 30303); // Some dude in Canada
// new ClientPeer(thisConsole).connect("82.217.72.169", 30303); // Nick
// new ClientPeer(thisConsole).connect("54.204.10.41", 30303); // CPP: ZeroGox Poc5
new ClientPeer(thisConsole).connect("54.211.14.10", 40404); // RomanJ
// new ClientPeer(thisConsole).connect("192.168.1.102", 30303);
}
};

View File

@ -1,7 +1,6 @@
package org.ethereum.gui;
import org.ethereum.core.Transaction;
import org.ethereum.crypto.HashUtil;
import org.ethereum.manager.MainData;
import org.ethereum.net.client.ClientPeer;
import org.ethereum.wallet.AddressState;

View File

@ -2,7 +2,6 @@ package org.ethereum.gui;
import java.net.InetAddress;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.*;
import javax.swing.ImageIcon;

View File

@ -1,6 +1,5 @@
package org.ethereum.gui;
import org.ethereum.config.SystemProperties;
import org.ethereum.manager.MainData;
import java.awt.*;

View File

@ -8,8 +8,6 @@ import org.slf4j.LoggerFactory;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
@ -36,7 +34,7 @@ public class ToolBar extends JFrame {
introLogger.info("♢ EthereumJ [v0.5.1] ");
introLogger.info("♢ Code by Roman Mandeleil, (c) 2014.");
introLogger.info("♢ Contribution: Nick Savers ");
introLogger.info("♢ Based on a design by Vitaly Buterin.");
introLogger.info("♢ Based on a design by Vitalik Buterin.");
introLogger.info("");
introLogger.info("java.version: " + System.getProperty("java.version"));
introLogger.info("java.home: " + System.getProperty("java.home"));
@ -48,9 +46,6 @@ public class ToolBar extends JFrame {
System.exit(0);
}
final JPanel cp = new JPanel(new FlowLayout());
cp.setBackground(Color.WHITE);
@ -161,7 +156,6 @@ public class ToolBar extends JFrame {
}
});
JToggleButton chainToggle = new JToggleButton();
chainToggle.setIcon(image_4);
chainToggle.setToolTipText("Block Chain");
@ -222,17 +216,14 @@ public class ToolBar extends JFrame {
cp.add(chainToggle);
cp.add(walletToggle);
MainData.instance.toString();
}
public static void main(String args[]){
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new ToolBar().setVisible(true);
}
});
}
}

View File

@ -11,7 +11,6 @@ import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.math.BigInteger;
import java.net.URL;
/**

View File

@ -7,8 +7,6 @@ import javax.swing.border.Border;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.math.BigInteger;

View File

@ -18,7 +18,6 @@ import org.ethereum.net.client.ClientPeer;
import org.ethereum.net.client.PeerData;
import org.ethereum.net.message.StaticMessages;
import org.ethereum.net.peerdiscovery.PeerDiscovery;
import org.ethereum.net.peerdiscovery.WorkerThread;
import org.ethereum.wallet.AddressState;
import org.spongycastle.util.encoders.Hex;
@ -49,7 +48,7 @@ public class MainData {
wallet.importKey(cowAddr);
AddressState state = wallet.getAddressState(key.getAddress());
state.addToBalance(new BigInteger("1606938044258990275541962092341162602522202993782792835301376"));
state.addToBalance(BigInteger.valueOf(2).pow(200)); // 1606938044258990275541962092341162602522202993782792835301376
wallet.importKey(HashUtil.sha3("cat".getBytes()));
peerDiscovery = new PeerDiscovery(peers);

View File

@ -6,7 +6,6 @@ import java.util.List;
import static org.ethereum.net.Command.BLOCKS;
import org.ethereum.core.Block;
import org.ethereum.core.Transaction;
import org.ethereum.net.Command;
import org.ethereum.util.RLPItem;
import org.ethereum.util.RLPList;

View File

@ -23,7 +23,7 @@ public class StaticMessages {
byte[] peerIdBytes = HashUtil.randomPeerId();
HELLO_MESSAGE = new HelloMessage((byte)0x11, (byte)0x00, "EthereumJ [v0.5.1] by RomanJ ",
HELLO_MESSAGE = new HelloMessage((byte)0x11, (byte)0x00, "EthereumJ [v0.5.1] by RomanJ",
(byte)0b00000111, (short)30303, peerIdBytes);
}

View File

@ -1,7 +1,5 @@
package org.ethereum.net.peerdiscovery;
import org.ethereum.config.SystemProperties;
import org.ethereum.net.client.PeerData;
import java.util.List;

View File

@ -5,19 +5,13 @@ import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.timeout.ReadTimeoutHandler;
import org.ethereum.config.SystemProperties;
import org.ethereum.gui.PeerListener;
import org.ethereum.manager.MainData;
import org.ethereum.net.client.EthereumFrameDecoder;
import org.ethereum.net.client.PeerData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import static org.ethereum.config.SystemProperties.config;
/**
* www.ethereumJ.com
* User: Roman Mandeleil
@ -59,7 +53,6 @@ public class PeerTaster {
}
});
// Start the client.
b.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, config.peerDiscoveryTimeout());
ChannelFuture f = b.connect(host, port).sync(); // (5)

View File

@ -1,18 +1,11 @@
package org.ethereum.serpent;
import org.antlr.mojo.antlr4.Antlr4ErrorLog;
import org.antlr.mojo.antlr4.Antlr4Mojo;
import java.io.File;
import org.antlr.v4.Tool;
import org.antlr.v4.codegen.CodeGenerator;
import org.antlr.v4.tool.Grammar;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import java.io.*;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
/**
* www.ethereumJ.com
* User: Roman Mandeleil
@ -20,27 +13,19 @@ import java.util.Map;
*/
public class ParserGenerator {
public static void main(String args[]) throws MojoFailureException, MojoExecutionException {
String userDir = System.getProperty("user.dir");
String grammarName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g4";
File inputDir = new File(userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\");
String options[] = {grammarName, "-visitor", "-package", "org.ethereum.serpent"};
Tool tool = new Tool(options);
tool.outputDirectory = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\";
tool.processGrammarsOnCommandLine();
// org.antlr.Tool.main(new String[]{userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g4"});
// org.antlr.Tool.main(new String[]{userDir + "\\src\\main\\java\\samples\\antlr\\PyEsque.g"});

View File

@ -2,8 +2,6 @@ package org.ethereum.util;
import java.util.ArrayList;
import org.spongycastle.util.encoders.Hex;
/**
* www.ethereumJ.com
* User: Roman Mandeleil

View File

@ -157,7 +157,7 @@ public class TransactionTest {
byte[] encodedTxBytes = Hex.decode("f86f81018609184e72a0008242559479b08ad8787060333663d19704909ee7b1903e58893635c9adc5dea00000801ba056f49cb76f7daadd0e7eb523a8c942a2b510f450185c93a3e2e51a749642f0efa03374f71fa8855212d8c369be6ced2801a8a7b6d7cea3a578623ad34feceef12f");
Transaction tx = new Transaction(encodedTxBytes);
System.out.println(Hex.toHexString( tx.sender() ));
System.out.println(Hex.toHexString( tx.getSender() ));
System.out.println(Hex.toHexString( tx.getHash() ));
System.out.println(Hex.toHexString( tx.getEncoded() ));
}

View File

@ -737,7 +737,6 @@ public class SerpentCompileTest {
Assert.assertEquals(expected, result);
}
@Test // if elif else test 13
public void test28(){
@ -775,7 +774,6 @@ public class SerpentCompileTest {
Assert.assertEquals(expected, result);
}
@Test // if elif else test 14
public void test29(){
@ -913,7 +911,6 @@ public class SerpentCompileTest {
Assert.fail("Should be indent error thrown");
}
@Test // if elif else test 19
public void test34(){
@ -957,8 +954,6 @@ public class SerpentCompileTest {
Assert.assertEquals(expected, result);
}
@Test // if elif else test 20
public void test35(){
@ -1003,7 +998,6 @@ public class SerpentCompileTest {
Assert.assertEquals(expected, result);
}
@Test // while test 1
public void test36(){
@ -1075,7 +1069,6 @@ public class SerpentCompileTest {
Assert.assertEquals(expected, result);
}
@Test // while test 3
public void test38(){
@ -1218,11 +1211,8 @@ public class SerpentCompileTest {
Assert.assertEquals(expected, result);
}
/*
*
a = msg.datasize
b = msg.sender
c = msg.value

View File

@ -1,6 +1,5 @@
package org.ethereum.util;
import junit.framework.Assert;
import org.junit.Test;
import org.spongycastle.util.encoders.Hex;