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 f861f5c7..f1d36e84 100644 --- a/ethereumj-core/src/main/java/org/ethereum/core/Block.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/Block.java @@ -125,11 +125,11 @@ public class Block { byte[] guBytes = ((RLPItem) header.get(9)).getRLPData(); byte[] tsBytes = ((RLPItem) header.get(10)).getRLPData(); - this.number = nrBytes == null ? 0 : (new BigInteger(nrBytes)).longValue(); - this.minGasPrice = gpBytes == null ? 0 : (new BigInteger(gpBytes)).longValue(); - this.gasLimit = glBytes == null ? 0 : (new BigInteger(glBytes)).longValue(); - this.gasUsed = guBytes == null ? 0 : (new BigInteger(guBytes)).longValue(); - this.timestamp = tsBytes == null ? 0 : (new BigInteger(tsBytes)).longValue(); + this.number = nrBytes == null ? 0 : (new BigInteger(1, nrBytes)).longValue(); + 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.extraData = ((RLPItem) header.get(11)).getRLPData(); this.nonce = ((RLPItem) header.get(12)).getRLPData(); diff --git a/ethereumj-core/src/main/java/org/ethereum/gui/BlockChainTable.java b/ethereumj-core/src/main/java/org/ethereum/gui/BlockChainTable.java index 187f426e..9d576a59 100644 --- a/ethereumj-core/src/main/java/org/ethereum/gui/BlockChainTable.java +++ b/ethereumj-core/src/main/java/org/ethereum/gui/BlockChainTable.java @@ -11,7 +11,6 @@ import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.StringSelection; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; -import java.beans.PropertyChangeListener; /** * www.ethereumJ.com @@ -26,7 +25,6 @@ public class BlockChainTable extends JFrame { private int lastFindIndex = 0; - public BlockChainTable() { final BlockChainTable blockChainTable = this; @@ -68,7 +66,7 @@ public class BlockChainTable extends JFrame { table.getColumnModel().getColumn(0).setCellRenderer(new TableCellLongTextRenderer()); 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 public void actionPerformed(ActionEvent e) { @@ -89,12 +87,12 @@ public class BlockChainTable extends JFrame { String toFind = JOptionPane.showInputDialog(blockChainTable, "Find:", "Find in BlockChain", JOptionPane.QUESTION_MESSAGE); - if (toFind.equals("")){ + if (toFind.equals("")) { lastFindIndex = 0; 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; Block block = MainData.instance.getAllBlocks().get(i); @@ -110,15 +108,12 @@ public class BlockChainTable extends JFrame { } } }); - // Add the table to a scrolling pane scrollPane = new JScrollPane(table); topPanel.add(scrollPane, BorderLayout.CENTER); - } public static void main(String args[]){ - BlockChainTable mainFrame = new BlockChainTable(); mainFrame.setVisible(true); mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); diff --git a/ethereumj-core/src/main/java/org/ethereum/gui/ContractCallDialog.java b/ethereumj-core/src/main/java/org/ethereum/gui/ContractCallDialog.java index e4c14470..207c23bd 100644 --- a/ethereumj-core/src/main/java/org/ethereum/gui/ContractCallDialog.java +++ b/ethereumj-core/src/main/java/org/ethereum/gui/ContractCallDialog.java @@ -22,7 +22,6 @@ import java.math.BigInteger; import java.net.URL; import java.util.Collection; - /** * www.ethereumJ.com * User: Roman Mandeleil @@ -30,15 +29,11 @@ import java.util.Collection; */ class ContractCallDialog extends JDialog implements MessageAwareDialog{ - ContractCallDialog dialog; JComboBox creatorAddressCombo; final JTextField gasInput; final JTextField contractAddrInput; JTextArea msgDataTA; - - - JLabel statusMsg = null; public ContractCallDialog(Frame parent) { @@ -87,14 +82,12 @@ class ContractCallDialog extends JDialog implements MessageAwareDialog{ rejectLabel.setBounds(260, 325, 45, 45); this.getContentPane().add(rejectLabel); rejectLabel.setVisible(true); - rejectLabel.addMouseListener( - new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent e) { - - dialog.dispose(); - }} - ); + rejectLabel.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + dialog.dispose(); + } + }); URL approveIconURL = ClassLoader.getSystemResource("buttons/approve.png"); ImageIcon approveIcon = new ImageIcon(approveIconURL); @@ -117,15 +110,13 @@ class ContractCallDialog extends JDialog implements MessageAwareDialog{ gasInput.setText("1000"); - JComboBox creatorAddressCombo = new JComboBox(){ - @Override - public ComboBoxUI getUI() { - - BasicComboBoxUI ui = (BasicComboBoxUI)super.getUI(); - - return super.getUI(); - } - }; + JComboBox creatorAddressCombo = new JComboBox() { + @Override + public ComboBoxUI getUI() { + BasicComboBoxUI ui = (BasicComboBoxUI) super.getUI(); + return super.getUI(); + } + }; creatorAddressCombo.setOpaque(true); creatorAddressCombo.setEnabled(true); @@ -142,22 +133,19 @@ class ContractCallDialog extends JDialog implements MessageAwareDialog{ MainData.instance.getWallet().getAddressStateCollection(); for (AddressState addressState : addressStates){ - creatorAddressCombo.addItem(new AddressStateWraper(addressState)); } - creatorAddressCombo.setRenderer(new DefaultListCellRenderer() { - - @Override - public void paint(Graphics g) { - setBackground(Color.WHITE); - setForeground(new Color(143, 170, 220)); - setFont(new Font("Monospaced", 0, 13)); - setBorder(BorderFactory.createEmptyBorder()); - super.paint(g); - } - - }); + creatorAddressCombo.setRenderer(new DefaultListCellRenderer() { + @Override + public void paint(Graphics g) { + setBackground(Color.WHITE); + setForeground(new Color(143, 170, 220)); + setFont(new Font("Monospaced", 0, 13)); + setBorder(BorderFactory.createEmptyBorder()); + super.paint(g); + } + }); creatorAddressCombo.setPopupVisible(false); @@ -168,13 +156,10 @@ class ContractCallDialog extends JDialog implements MessageAwareDialog{ list.setSelectionBackground(Color.cyan); 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) { - CellRendererPane crp = ((CellRendererPane) (creatorAddressCombo.getComponent(i))); } - if (creatorAddressCombo.getComponent(i) instanceof AbstractButton) { ((AbstractButton) creatorAddressCombo.getComponent(i)).setBorder(line); } @@ -182,7 +167,6 @@ class ContractCallDialog extends JDialog implements MessageAwareDialog{ creatorAddressCombo.setBounds(73, 267, 230, 36); this.getContentPane().add(creatorAddressCombo); - this.getContentPane().revalidate(); this.getContentPane().repaint(); this.setResizable(false); @@ -212,7 +196,6 @@ class ContractCallDialog extends JDialog implements MessageAwareDialog{ this.setSize(500, 430); this.setVisible(true); - return rootPane; } @@ -226,7 +209,6 @@ class ContractCallDialog extends JDialog implements MessageAwareDialog{ this.statusMsg.setText(text); } - public void submitContract(){ ClientPeer peer = MainData.instance.getActivePeer(); @@ -241,7 +223,6 @@ class ContractCallDialog extends JDialog implements MessageAwareDialog{ byte[] contractAddress = Hex.decode( contractAddrInput.getText()); - AddressState addressState = ((AddressStateWraper)creatorAddressCombo.getSelectedItem()).getAddressState(); byte[] senderPrivKey = addressState.getEcKey().getPrivKeyBytes(); @@ -252,9 +233,8 @@ class ContractCallDialog extends JDialog implements MessageAwareDialog{ byte[] gasValue = BigIntegers.asUnsignedByteArray(gasBI); byte[] endowment = BigIntegers.asUnsignedByteArray(new BigInteger("1000")); - - Transaction tx = new Transaction(nonce, gasPrice, gasValue, - contractAddress, endowment, data); + Transaction tx = new Transaction(nonce, gasPrice, gasValue, + contractAddress, endowment, data); try { tx.sign(senderPrivKey); @@ -264,17 +244,12 @@ class ContractCallDialog extends JDialog implements MessageAwareDialog{ return; } - // SwingWorker DialogWorker worker = new DialogWorker(tx, this); worker.execute(); - } - - - - public class AddressStateWraper{ + public class AddressStateWraper { private AddressState addressState; @@ -286,17 +261,14 @@ class ContractCallDialog extends JDialog implements MessageAwareDialog{ return addressState; } - @Override - public String toString() { - String addressShort = Utils.getAddressShortString(addressState.getEcKey().getAddress()); - String valueShort = Utils.getValueShortString(addressState.getBalance()); - - String result = - String.format(" By: [%s] %s", - addressShort, valueShort); - - return result; - } + @Override + public String toString() { + String addressShort = Utils.getAddressShortString(addressState.getEcKey().getAddress()); + String valueShort = Utils.getValueShortString(addressState.getBalance()); + String result = String.format(" By: [%s] %s", addressShort, + valueShort); + return result; + } } } diff --git a/ethereumj-core/src/main/java/org/ethereum/manager/MainData.java b/ethereumj-core/src/main/java/org/ethereum/manager/MainData.java index ae8dbaad..59e7f9aa 100644 --- a/ethereumj-core/src/main/java/org/ethereum/manager/MainData.java +++ b/ethereumj-core/src/main/java/org/ethereum/manager/MainData.java @@ -1,15 +1,12 @@ package org.ethereum.manager; import java.math.BigInteger; -import java.net.Inet4Address; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.*; import com.maxmind.geoip.Location; -import org.ethereum.config.SystemProperties; import org.ethereum.core.Block; -import org.ethereum.core.Genesis; import org.ethereum.core.Transaction; import org.ethereum.core.Wallet; import org.ethereum.crypto.ECKey; @@ -60,8 +57,12 @@ public class MainData { System.exit(-1); } +<<<<<<< HEAD PeerData peer = new PeerData( ip.getAddress(), port, new byte[]{00}); +======= + PeerData peer = new PeerData(ip.getAddress(), (short) 30303, new byte[] { 00 }); +>>>>>>> d52f5868c293bff76394d6e014833a7dd17b5722 peers.add(peer); byte[] cowAddr = HashUtil.sha3("cow".getBytes()); @@ -75,7 +76,6 @@ public class MainData { peerDiscovery = new PeerDiscovery(peers); } - public void addBlocks(List blocks) { // 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 for (Block block : blocks){ for (Transaction tx : block.getTransactionsList()){ - if (logger.isDebugEnabled()) logger.debug("pending cleanup: tx.hash: [{}]", Hex.toHexString( tx.getHash())); pendingTransactions.remove(tx.getHash()); @@ -141,7 +140,6 @@ public class MainData { return activePeer; } - /* * 1) the dialog put a pending transaction on the list * 2) the dialog send the transaction to a net @@ -155,14 +153,12 @@ public class MainData { BigInteger hash = new BigInteger(transaction.getHash()); PendingTransaction pendingTransaction = pendingTransactions.get(hash); - if (pendingTransaction != null) - pendingTransaction.incApproved(); - else{ - - pendingTransaction = new PendingTransaction(transaction); - pendingTransactions.put(hash, pendingTransaction); - } - + if (pendingTransaction != null) + pendingTransaction.incApproved(); + else { + pendingTransaction = new PendingTransaction(transaction); + pendingTransactions.put(hash, pendingTransaction); + } return pendingTransaction; } @@ -171,11 +167,8 @@ public class MainData { } public void updatePeerIsDead(String ip, short port){ - for (PeerData peer : peers) { - if (peer.getInetAddress().getHostAddress().equals(ip) && (peer.getPort() == port)){ - System.out.println("update peer is dead: " + ip + ":" + port); peer.setOnline(false); break; @@ -184,24 +177,19 @@ public class MainData { } public void addPeers(List newPeers){ - for (PeerData peer : newPeers){ if (this.peers.indexOf(peer) == -1){ - Location location = IpGeoDB.getLocationForIp(peer.getInetAddress()); if (location != null){ this.peers.add(peer); - if (peerDiscovery.isStarted()) peerDiscovery.addNewPeerData(peer); } } } - } public void startPeerDiscovery(){ peerDiscovery.start(); }; - }