Conflicts:
	src/main/java/org/ethereum/manager/MainData.java
This commit is contained in:
romanman 2014-05-27 10:21:53 +03:00
commit 7262f13181
4 changed files with 53 additions and 98 deletions

View File

@ -125,11 +125,11 @@ public class Block {
byte[] guBytes = ((RLPItem) header.get(9)).getRLPData(); byte[] guBytes = ((RLPItem) header.get(9)).getRLPData();
byte[] tsBytes = ((RLPItem) header.get(10)).getRLPData(); byte[] tsBytes = ((RLPItem) header.get(10)).getRLPData();
this.number = nrBytes == null ? 0 : (new BigInteger(nrBytes)).longValue(); this.number = nrBytes == null ? 0 : (new BigInteger(1, nrBytes)).longValue();
this.minGasPrice = gpBytes == null ? 0 : (new BigInteger(gpBytes)).longValue(); this.minGasPrice = gpBytes == null ? 0 : (new BigInteger(1, gpBytes)).longValue();
this.gasLimit = glBytes == null ? 0 : (new BigInteger(glBytes)).longValue(); this.gasLimit = glBytes == null ? 0 : (new BigInteger(1, glBytes)).longValue();
this.gasUsed = guBytes == null ? 0 : (new BigInteger(guBytes)).longValue(); this.gasUsed = guBytes == null ? 0 : (new BigInteger(1, guBytes)).longValue();
this.timestamp = tsBytes == null ? 0 : (new BigInteger(tsBytes)).longValue(); this.timestamp = tsBytes == null ? 0 : (new BigInteger(1, tsBytes)).longValue();
this.extraData = ((RLPItem) header.get(11)).getRLPData(); this.extraData = ((RLPItem) header.get(11)).getRLPData();
this.nonce = ((RLPItem) header.get(12)).getRLPData(); this.nonce = ((RLPItem) header.get(12)).getRLPData();

View File

@ -11,7 +11,6 @@ import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection; import java.awt.datatransfer.StringSelection;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.beans.PropertyChangeListener;
/** /**
* www.ethereumJ.com * www.ethereumJ.com
@ -26,7 +25,6 @@ public class BlockChainTable extends JFrame {
private int lastFindIndex = 0; private int lastFindIndex = 0;
public BlockChainTable() { public BlockChainTable() {
final BlockChainTable blockChainTable = this; final BlockChainTable blockChainTable = this;
@ -68,7 +66,7 @@ public class BlockChainTable extends JFrame {
table.getColumnModel().getColumn(0).setCellRenderer(new TableCellLongTextRenderer()); table.getColumnModel().getColumn(0).setCellRenderer(new TableCellLongTextRenderer());
table.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_DOWN_MASK), "Copy"); table.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_DOWN_MASK), "Copy");
table.getActionMap().put("Copy", new AbstractAction(){ table.getActionMap().put("Copy", new AbstractAction() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
@ -89,12 +87,12 @@ public class BlockChainTable extends JFrame {
String toFind = JOptionPane.showInputDialog(blockChainTable, "Find:", String toFind = JOptionPane.showInputDialog(blockChainTable, "Find:",
"Find in BlockChain", JOptionPane.QUESTION_MESSAGE); "Find in BlockChain", JOptionPane.QUESTION_MESSAGE);
if (toFind.equals("")){ if (toFind.equals("")) {
lastFindIndex = 0; lastFindIndex = 0;
return; return;
} }
for (int i = lastFindIndex + 1; i < MainData.instance.getAllBlocks().size(); ++i){ for (int i = lastFindIndex + 1; i < MainData.instance.getAllBlocks().size(); ++i) {
if (MainData.instance.getAllBlocks().size() - 1 < i) return; if (MainData.instance.getAllBlocks().size() - 1 < i) return;
Block block = MainData.instance.getAllBlocks().get(i); Block block = MainData.instance.getAllBlocks().get(i);
@ -110,15 +108,12 @@ public class BlockChainTable extends JFrame {
} }
} }
}); });
// Add the table to a scrolling pane // Add the table to a scrolling pane
scrollPane = new JScrollPane(table); scrollPane = new JScrollPane(table);
topPanel.add(scrollPane, BorderLayout.CENTER); topPanel.add(scrollPane, BorderLayout.CENTER);
} }
public static void main(String args[]){ public static void main(String args[]){
BlockChainTable mainFrame = new BlockChainTable(); BlockChainTable mainFrame = new BlockChainTable();
mainFrame.setVisible(true); mainFrame.setVisible(true);
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

View File

@ -22,7 +22,6 @@ import java.math.BigInteger;
import java.net.URL; import java.net.URL;
import java.util.Collection; import java.util.Collection;
/** /**
* www.ethereumJ.com * www.ethereumJ.com
* User: Roman Mandeleil * User: Roman Mandeleil
@ -30,15 +29,11 @@ import java.util.Collection;
*/ */
class ContractCallDialog extends JDialog implements MessageAwareDialog{ class ContractCallDialog extends JDialog implements MessageAwareDialog{
ContractCallDialog dialog; ContractCallDialog dialog;
JComboBox<AddressStateWraper> creatorAddressCombo; JComboBox<AddressStateWraper> creatorAddressCombo;
final JTextField gasInput; final JTextField gasInput;
final JTextField contractAddrInput; final JTextField contractAddrInput;
JTextArea msgDataTA; JTextArea msgDataTA;
JLabel statusMsg = null; JLabel statusMsg = null;
public ContractCallDialog(Frame parent) { public ContractCallDialog(Frame parent) {
@ -87,14 +82,12 @@ class ContractCallDialog extends JDialog implements MessageAwareDialog{
rejectLabel.setBounds(260, 325, 45, 45); rejectLabel.setBounds(260, 325, 45, 45);
this.getContentPane().add(rejectLabel); this.getContentPane().add(rejectLabel);
rejectLabel.setVisible(true); rejectLabel.setVisible(true);
rejectLabel.addMouseListener( rejectLabel.addMouseListener(new MouseAdapter() {
new MouseAdapter() { @Override
@Override public void mouseClicked(MouseEvent e) {
public void mouseClicked(MouseEvent e) { dialog.dispose();
}
dialog.dispose(); });
}}
);
URL approveIconURL = ClassLoader.getSystemResource("buttons/approve.png"); URL approveIconURL = ClassLoader.getSystemResource("buttons/approve.png");
ImageIcon approveIcon = new ImageIcon(approveIconURL); ImageIcon approveIcon = new ImageIcon(approveIconURL);
@ -117,15 +110,13 @@ class ContractCallDialog extends JDialog implements MessageAwareDialog{
gasInput.setText("1000"); gasInput.setText("1000");
JComboBox<AddressStateWraper> creatorAddressCombo = new JComboBox<AddressStateWraper>(){ JComboBox<AddressStateWraper> creatorAddressCombo = new JComboBox<AddressStateWraper>() {
@Override @Override
public ComboBoxUI getUI() { public ComboBoxUI getUI() {
BasicComboBoxUI ui = (BasicComboBoxUI) super.getUI();
BasicComboBoxUI ui = (BasicComboBoxUI)super.getUI(); return super.getUI();
}
return super.getUI(); };
}
};
creatorAddressCombo.setOpaque(true); creatorAddressCombo.setOpaque(true);
creatorAddressCombo.setEnabled(true); creatorAddressCombo.setEnabled(true);
@ -142,22 +133,19 @@ class ContractCallDialog extends JDialog implements MessageAwareDialog{
MainData.instance.getWallet().getAddressStateCollection(); MainData.instance.getWallet().getAddressStateCollection();
for (AddressState addressState : addressStates){ for (AddressState addressState : addressStates){
creatorAddressCombo.addItem(new AddressStateWraper(addressState)); creatorAddressCombo.addItem(new AddressStateWraper(addressState));
} }
creatorAddressCombo.setRenderer(new DefaultListCellRenderer() { creatorAddressCombo.setRenderer(new DefaultListCellRenderer() {
@Override
@Override public void paint(Graphics g) {
public void paint(Graphics g) { setBackground(Color.WHITE);
setBackground(Color.WHITE); setForeground(new Color(143, 170, 220));
setForeground(new Color(143, 170, 220)); setFont(new Font("Monospaced", 0, 13));
setFont(new Font("Monospaced", 0, 13)); setBorder(BorderFactory.createEmptyBorder());
setBorder(BorderFactory.createEmptyBorder()); super.paint(g);
super.paint(g); }
} });
});
creatorAddressCombo.setPopupVisible(false); creatorAddressCombo.setPopupVisible(false);
@ -168,13 +156,10 @@ class ContractCallDialog extends JDialog implements MessageAwareDialog{
list.setSelectionBackground(Color.cyan); list.setSelectionBackground(Color.cyan);
list.setBorder(null); list.setBorder(null);
for (int i = 0; i < creatorAddressCombo.getComponentCount(); i++) for (int i = 0; i < creatorAddressCombo.getComponentCount(); i++) {
{
if (creatorAddressCombo.getComponent(i) instanceof CellRendererPane) { if (creatorAddressCombo.getComponent(i) instanceof CellRendererPane) {
CellRendererPane crp = ((CellRendererPane) (creatorAddressCombo.getComponent(i))); CellRendererPane crp = ((CellRendererPane) (creatorAddressCombo.getComponent(i)));
} }
if (creatorAddressCombo.getComponent(i) instanceof AbstractButton) { if (creatorAddressCombo.getComponent(i) instanceof AbstractButton) {
((AbstractButton) creatorAddressCombo.getComponent(i)).setBorder(line); ((AbstractButton) creatorAddressCombo.getComponent(i)).setBorder(line);
} }
@ -182,7 +167,6 @@ class ContractCallDialog extends JDialog implements MessageAwareDialog{
creatorAddressCombo.setBounds(73, 267, 230, 36); creatorAddressCombo.setBounds(73, 267, 230, 36);
this.getContentPane().add(creatorAddressCombo); this.getContentPane().add(creatorAddressCombo);
this.getContentPane().revalidate(); this.getContentPane().revalidate();
this.getContentPane().repaint(); this.getContentPane().repaint();
this.setResizable(false); this.setResizable(false);
@ -212,7 +196,6 @@ class ContractCallDialog extends JDialog implements MessageAwareDialog{
this.setSize(500, 430); this.setSize(500, 430);
this.setVisible(true); this.setVisible(true);
return rootPane; return rootPane;
} }
@ -226,7 +209,6 @@ class ContractCallDialog extends JDialog implements MessageAwareDialog{
this.statusMsg.setText(text); this.statusMsg.setText(text);
} }
public void submitContract(){ public void submitContract(){
ClientPeer peer = MainData.instance.getActivePeer(); ClientPeer peer = MainData.instance.getActivePeer();
@ -241,7 +223,6 @@ class ContractCallDialog extends JDialog implements MessageAwareDialog{
byte[] contractAddress = Hex.decode( contractAddrInput.getText()); byte[] contractAddress = Hex.decode( contractAddrInput.getText());
AddressState addressState = ((AddressStateWraper)creatorAddressCombo.getSelectedItem()).getAddressState(); AddressState addressState = ((AddressStateWraper)creatorAddressCombo.getSelectedItem()).getAddressState();
byte[] senderPrivKey = addressState.getEcKey().getPrivKeyBytes(); byte[] senderPrivKey = addressState.getEcKey().getPrivKeyBytes();
@ -252,9 +233,8 @@ class ContractCallDialog extends JDialog implements MessageAwareDialog{
byte[] gasValue = BigIntegers.asUnsignedByteArray(gasBI); byte[] gasValue = BigIntegers.asUnsignedByteArray(gasBI);
byte[] endowment = BigIntegers.asUnsignedByteArray(new BigInteger("1000")); byte[] endowment = BigIntegers.asUnsignedByteArray(new BigInteger("1000"));
Transaction tx = new Transaction(nonce, gasPrice, gasValue,
Transaction tx = new Transaction(nonce, gasPrice, gasValue, contractAddress, endowment, data);
contractAddress, endowment, data);
try { try {
tx.sign(senderPrivKey); tx.sign(senderPrivKey);
@ -264,17 +244,12 @@ class ContractCallDialog extends JDialog implements MessageAwareDialog{
return; return;
} }
// SwingWorker // SwingWorker
DialogWorker worker = new DialogWorker(tx, this); DialogWorker worker = new DialogWorker(tx, this);
worker.execute(); worker.execute();
} }
public class AddressStateWraper {
public class AddressStateWraper{
private AddressState addressState; private AddressState addressState;
@ -286,17 +261,14 @@ class ContractCallDialog extends JDialog implements MessageAwareDialog{
return addressState; return addressState;
} }
@Override @Override
public String toString() { public String toString() {
String addressShort = Utils.getAddressShortString(addressState.getEcKey().getAddress()); String addressShort = Utils.getAddressShortString(addressState.getEcKey().getAddress());
String valueShort = Utils.getValueShortString(addressState.getBalance()); String valueShort = Utils.getValueShortString(addressState.getBalance());
String result = String.format(" By: [%s] %s", addressShort,
String result = valueShort);
String.format(" By: [%s] %s", return result;
addressShort, valueShort); }
return result;
}
} }
} }

View File

@ -1,15 +1,12 @@
package org.ethereum.manager; package org.ethereum.manager;
import java.math.BigInteger; import java.math.BigInteger;
import java.net.Inet4Address;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.*; import java.util.*;
import com.maxmind.geoip.Location; import com.maxmind.geoip.Location;
import org.ethereum.config.SystemProperties;
import org.ethereum.core.Block; import org.ethereum.core.Block;
import org.ethereum.core.Genesis;
import org.ethereum.core.Transaction; import org.ethereum.core.Transaction;
import org.ethereum.core.Wallet; import org.ethereum.core.Wallet;
import org.ethereum.crypto.ECKey; import org.ethereum.crypto.ECKey;
@ -60,8 +57,12 @@ public class MainData {
System.exit(-1); System.exit(-1);
} }
<<<<<<< HEAD
PeerData peer = new PeerData( PeerData peer = new PeerData(
ip.getAddress(), port, new byte[]{00}); ip.getAddress(), port, new byte[]{00});
=======
PeerData peer = new PeerData(ip.getAddress(), (short) 30303, new byte[] { 00 });
>>>>>>> d52f5868c293bff76394d6e014833a7dd17b5722
peers.add(peer); peers.add(peer);
byte[] cowAddr = HashUtil.sha3("cow".getBytes()); byte[] cowAddr = HashUtil.sha3("cow".getBytes());
@ -75,7 +76,6 @@ public class MainData {
peerDiscovery = new PeerDiscovery(peers); peerDiscovery = new PeerDiscovery(peers);
} }
public void addBlocks(List<Block> blocks) { public void addBlocks(List<Block> blocks) {
// TODO: redesign this part when the state part and the genesis block is ready // TODO: redesign this part when the state part and the genesis block is ready
@ -109,7 +109,6 @@ public class MainData {
// Remove all pending transactions as they already approved by the net // Remove all pending transactions as they already approved by the net
for (Block block : blocks){ for (Block block : blocks){
for (Transaction tx : block.getTransactionsList()){ for (Transaction tx : block.getTransactionsList()){
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
logger.debug("pending cleanup: tx.hash: [{}]", Hex.toHexString( tx.getHash())); logger.debug("pending cleanup: tx.hash: [{}]", Hex.toHexString( tx.getHash()));
pendingTransactions.remove(tx.getHash()); pendingTransactions.remove(tx.getHash());
@ -141,7 +140,6 @@ public class MainData {
return activePeer; return activePeer;
} }
/* /*
* 1) the dialog put a pending transaction on the list * 1) the dialog put a pending transaction on the list
* 2) the dialog send the transaction to a net * 2) the dialog send the transaction to a net
@ -155,14 +153,12 @@ public class MainData {
BigInteger hash = new BigInteger(transaction.getHash()); BigInteger hash = new BigInteger(transaction.getHash());
PendingTransaction pendingTransaction = pendingTransactions.get(hash); PendingTransaction pendingTransaction = pendingTransactions.get(hash);
if (pendingTransaction != null) if (pendingTransaction != null)
pendingTransaction.incApproved(); pendingTransaction.incApproved();
else{ else {
pendingTransaction = new PendingTransaction(transaction);
pendingTransaction = new PendingTransaction(transaction); pendingTransactions.put(hash, pendingTransaction);
pendingTransactions.put(hash, pendingTransaction); }
}
return pendingTransaction; return pendingTransaction;
} }
@ -171,11 +167,8 @@ public class MainData {
} }
public void updatePeerIsDead(String ip, short port){ public void updatePeerIsDead(String ip, short port){
for (PeerData peer : peers) { for (PeerData peer : peers) {
if (peer.getInetAddress().getHostAddress().equals(ip) && (peer.getPort() == port)){ if (peer.getInetAddress().getHostAddress().equals(ip) && (peer.getPort() == port)){
System.out.println("update peer is dead: " + ip + ":" + port); System.out.println("update peer is dead: " + ip + ":" + port);
peer.setOnline(false); peer.setOnline(false);
break; break;
@ -184,24 +177,19 @@ public class MainData {
} }
public void addPeers(List<PeerData> newPeers){ public void addPeers(List<PeerData> newPeers){
for (PeerData peer : newPeers){ for (PeerData peer : newPeers){
if (this.peers.indexOf(peer) == -1){ if (this.peers.indexOf(peer) == -1){
Location location = IpGeoDB.getLocationForIp(peer.getInetAddress()); Location location = IpGeoDB.getLocationForIp(peer.getInetAddress());
if (location != null){ if (location != null){
this.peers.add(peer); this.peers.add(peer);
if (peerDiscovery.isStarted()) if (peerDiscovery.isStarted())
peerDiscovery.addNewPeerData(peer); peerDiscovery.addNewPeerData(peer);
} }
} }
} }
} }
public void startPeerDiscovery(){ public void startPeerDiscovery(){
peerDiscovery.start(); peerDiscovery.start();
}; };
} }