Various line/import cleanup and move AddressState to core-package

This commit is contained in:
nicksavers 2014-05-28 15:57:26 +02:00
parent df38d1b6b3
commit cb5d611b10
11 changed files with 23 additions and 37 deletions

View File

@ -1,4 +1,4 @@
package org.ethereum.wallet; package org.ethereum.core;
import org.ethereum.crypto.ECKey; import org.ethereum.crypto.ECKey;
import org.ethereum.util.Utils; import org.ethereum.util.Utils;
@ -10,23 +10,19 @@ import java.math.BigInteger;
* User: Roman Mandeleil * User: Roman Mandeleil
* Created on: 21/05/2014 10:43 * Created on: 21/05/2014 10:43
*/ */
public class AddressState { public class AddressState {
private ECKey ecKey; private ECKey ecKey;
private BigInteger nonce; private BigInteger nonce;
private BigInteger balance; private BigInteger balance;
public AddressState() { public AddressState() {
ecKey = new ECKey(Utils.getRandom()); ecKey = new ECKey(Utils.getRandom());
nonce = BigInteger.ZERO; nonce = BigInteger.ZERO;
balance = BigInteger.ZERO; balance = BigInteger.ZERO;
} }
public AddressState(ECKey ecKey) { public AddressState(ECKey ecKey) {
this(); this();
this.ecKey = ecKey; this.ecKey = ecKey;
} }
@ -56,6 +52,4 @@ public class AddressState {
public void addToBalance(BigInteger value){ public void addToBalance(BigInteger value){
balance = balance.add(value); balance = balance.add(value);
} }
} }

View File

@ -1,7 +1,6 @@
package org.ethereum.core; package org.ethereum.core;
import org.ethereum.crypto.ECKey; import org.ethereum.crypto.ECKey;
import org.ethereum.wallet.AddressState;
import org.spongycastle.util.encoders.Hex; import org.spongycastle.util.encoders.Hex;
import org.w3c.dom.*; import org.w3c.dom.*;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
@ -14,6 +13,7 @@ import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory; import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource; import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamResult;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.math.BigInteger; import java.math.BigInteger;
@ -71,23 +71,19 @@ public class Wallet {
return rows.get(address); return rows.get(address);
} }
public BigInteger getBalance(byte[] addressBytes){ public BigInteger getBalance(byte[] addressBytes){
String address = Hex.toHexString(addressBytes); String address = Hex.toHexString(addressBytes);
return rows.get(address).getBalance(); return rows.get(address).getBalance();
} }
public BigInteger totalBalance(){ public BigInteger totalBalance(){
BigInteger sum = BigInteger.ZERO; BigInteger sum = BigInteger.ZERO;
for (AddressState addressState : rows.values()){ for (AddressState addressState : rows.values()){
sum = sum.add(addressState.getBalance()); sum = sum.add(addressState.getBalance());
} }
return sum; return sum;
} }
public void applyTransaction(Transaction transaction){ public void applyTransaction(Transaction transaction){
transactionMap.put(new BigInteger(transaction.getHash()), transaction ); transactionMap.put(new BigInteger(transaction.getHash()), transaction );
@ -140,7 +136,7 @@ public class Wallet {
*/ */
public void load() throws IOException, SAXException, ParserConfigurationException { public void load() throws IOException, SAXException, ParserConfigurationException {
/** /**
<wallet high="8933"> <wallet high="8933">
<row id=1> <row id=1>
@ -154,7 +150,7 @@ public class Wallet {
<value>900099909<value/> <value>900099909<value/>
</row> </row>
</wallet> </wallet>
*/ */
String dir = System.getProperty("user.dir"); String dir = System.getProperty("user.dir");

View File

@ -1,11 +1,11 @@
package org.ethereum.gui; package org.ethereum.gui;
import org.ethereum.core.AddressState;
import org.ethereum.core.Transaction; import org.ethereum.core.Transaction;
import org.ethereum.manager.MainData; import org.ethereum.manager.MainData;
import org.ethereum.net.client.ClientPeer; import org.ethereum.net.client.ClientPeer;
import org.ethereum.util.ByteUtil; import org.ethereum.util.ByteUtil;
import org.ethereum.util.Utils; import org.ethereum.util.Utils;
import org.ethereum.wallet.AddressState;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.spongycastle.util.BigIntegers; import org.spongycastle.util.BigIntegers;
@ -16,6 +16,7 @@ import javax.swing.border.Border;
import javax.swing.plaf.ComboBoxUI; import javax.swing.plaf.ComboBoxUI;
import javax.swing.plaf.basic.BasicComboBoxUI; import javax.swing.plaf.basic.BasicComboBoxUI;
import javax.swing.plaf.basic.BasicComboPopup; import javax.swing.plaf.basic.BasicComboPopup;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;

View File

@ -1,10 +1,10 @@
package org.ethereum.gui; package org.ethereum.gui;
import org.ethereum.core.AddressState;
import org.ethereum.core.Transaction; import org.ethereum.core.Transaction;
import org.ethereum.manager.MainData; import org.ethereum.manager.MainData;
import org.ethereum.net.client.ClientPeer; import org.ethereum.net.client.ClientPeer;
import org.ethereum.util.Utils; import org.ethereum.util.Utils;
import org.ethereum.wallet.AddressState;
import org.spongycastle.util.BigIntegers; import org.spongycastle.util.BigIntegers;
import org.spongycastle.util.encoders.Hex; import org.spongycastle.util.encoders.Hex;
@ -13,6 +13,7 @@ import javax.swing.border.Border;
import javax.swing.plaf.ComboBoxUI; import javax.swing.plaf.ComboBoxUI;
import javax.swing.plaf.basic.BasicComboBoxUI; import javax.swing.plaf.basic.BasicComboBoxUI;
import javax.swing.plaf.basic.BasicComboPopup; import javax.swing.plaf.basic.BasicComboPopup;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;

View File

@ -1,12 +1,9 @@
package org.ethereum.gui; package org.ethereum.gui;
import com.google.common.primitives.Longs; import org.ethereum.core.AddressState;
import org.ethereum.core.Transaction; import org.ethereum.core.Transaction;
import org.ethereum.manager.MainData; import org.ethereum.manager.MainData;
import org.ethereum.net.client.ClientPeer; import org.ethereum.net.client.ClientPeer;
import org.ethereum.net.submit.TransactionExecutor;
import org.ethereum.net.submit.TransactionTask;
import org.ethereum.wallet.AddressState;
import org.spongycastle.util.BigIntegers; import org.spongycastle.util.BigIntegers;
import org.spongycastle.util.encoders.Hex; import org.spongycastle.util.encoders.Hex;
@ -16,16 +13,10 @@ import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.math.BigInteger; import java.math.BigInteger;
import java.net.URL; import java.net.URL;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import javax.swing.*; import javax.swing.*;
import static org.ethereum.config.SystemProperties.CONFIG;
/** /**
* www.ethereumJ.com * www.ethereumJ.com
* User: Roman Mandeleil * User: Roman Mandeleil
@ -210,8 +201,6 @@ class PayOutDialog extends JDialog implements MessageAwareDialog{
alertStatusMsg("The address can't afford this transaction"); alertStatusMsg("The address can't afford this transaction");
return false; return false;
} }
return true; return true;
} }
@ -270,7 +259,6 @@ class PayOutDialog extends JDialog implements MessageAwareDialog{
}); });
} }
public static void main(String args[]) { public static void main(String args[]) {
AddressState as = new AddressState(); AddressState as = new AddressState();
PayOutDialog pod = new PayOutDialog(null, as); PayOutDialog pod = new PayOutDialog(null, as);

View File

@ -1,13 +1,14 @@
package org.ethereum.gui; package org.ethereum.gui;
import org.ethereum.core.AddressState;
import org.ethereum.util.Utils; import org.ethereum.util.Utils;
import org.ethereum.wallet.AddressState;
import org.spongycastle.util.encoders.Hex; import org.spongycastle.util.encoders.Hex;
import javax.swing.*; import javax.swing.*;
import javax.swing.border.Border; import javax.swing.border.Border;
import javax.swing.border.CompoundBorder; import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder; import javax.swing.border.EmptyBorder;
import java.awt.*; import java.awt.*;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;

View File

@ -1,10 +1,11 @@
package org.ethereum.gui; package org.ethereum.gui;
import org.ethereum.core.AddressState;
import org.ethereum.core.Wallet; import org.ethereum.core.Wallet;
import org.ethereum.manager.MainData; import org.ethereum.manager.MainData;
import org.ethereum.wallet.AddressState;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;

View File

@ -6,6 +6,8 @@ import java.net.UnknownHostException;
import java.util.*; import java.util.*;
import com.maxmind.geoip.Location; import com.maxmind.geoip.Location;
import org.ethereum.core.AddressState;
import org.ethereum.core.Block; import org.ethereum.core.Block;
import org.ethereum.core.Transaction; import org.ethereum.core.Transaction;
import org.ethereum.core.Wallet; import org.ethereum.core.Wallet;
@ -17,7 +19,6 @@ import org.ethereum.net.client.PeerData;
import org.ethereum.net.message.StaticMessages; import org.ethereum.net.message.StaticMessages;
import org.ethereum.net.peerdiscovery.PeerDiscovery; import org.ethereum.net.peerdiscovery.PeerDiscovery;
import org.ethereum.net.submit.PendingTransaction; import org.ethereum.net.submit.PendingTransaction;
import org.ethereum.wallet.AddressState;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.spongycastle.util.encoders.Hex; import org.spongycastle.util.encoders.Hex;
@ -150,7 +151,6 @@ public class MainData {
* 2) the dialog send the transaction to a net * 2) the dialog send the transaction to a net
* 3) wherever the transaction got for the wire in will change to approve state * 3) wherever the transaction got for the wire in will change to approve state
* 4) only after the approve a) Wallet state changes * 4) only after the approve a) Wallet state changes
*
* 5) After the block is received with that tx the pending been clean up * 5) After the block is received with that tx the pending been clean up
*/ */
public PendingTransaction addPendingTransaction(Transaction transaction) { public PendingTransaction addPendingTransaction(Transaction transaction) {

View File

@ -4,8 +4,6 @@ import org.ethereum.core.Genesis;
import org.ethereum.crypto.HashUtil; import org.ethereum.crypto.HashUtil;
import org.spongycastle.util.encoders.Hex; import org.spongycastle.util.encoders.Hex;
import static org.ethereum.config.SystemProperties.CONFIG;
/** /**
* www.ethereumJ.com * www.ethereumJ.com
* User: Roman Mandeleil * User: Roman Mandeleil

View File

@ -29,6 +29,13 @@ public class Utils {
return (new BigInteger(1, numberBytes)).toString(); return (new BigInteger(1, numberBytes)).toString();
} }
/**
* Return formatted Date String: yyyy.MM.dd HH:mm:ss
* Based on Unix's time() input in seconds
*
* @param timestamp seconds since start of Unix-time
* @return String formatted as - yyyy.MM.dd HH:mm:ss
*/
public static String longToDateTime(long timestamp) { public static String longToDateTime(long timestamp) {
Date date = new Date(timestamp * 1000); Date date = new Date(timestamp * 1000);
DateFormat formatter = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss"); DateFormat formatter = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
@ -43,7 +50,6 @@ public class Utils {
static BigInteger _1000_ = new BigInteger("1000"); static BigInteger _1000_ = new BigInteger("1000");
public static String getValueShortString(BigInteger number){ public static String getValueShortString(BigInteger number){
BigInteger result = number; BigInteger result = number;
int pow = 0; int pow = 0;
while (result.compareTo(_1000_) == 1 || result.compareTo(_1000_) == 0){ while (result.compareTo(_1000_) == 1 || result.compareTo(_1000_) == 0){

View File

@ -2,12 +2,12 @@ package org.ethereum.core;
import org.ethereum.crypto.ECKey; import org.ethereum.crypto.ECKey;
import org.ethereum.crypto.HashUtil; import org.ethereum.crypto.HashUtil;
import org.ethereum.wallet.AddressState;
import org.junit.Test; import org.junit.Test;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerException;
import java.io.IOException; import java.io.IOException;
import java.math.BigInteger; import java.math.BigInteger;