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 49f22253..41b4a45a 100644 --- a/ethereumj-core/src/main/java/org/ethereum/core/Block.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/Block.java @@ -240,6 +240,7 @@ public class Block { return uncleList; } + private StringBuffer toStringBuff = new StringBuffer(); // [parent_hash, uncles_hash, coinbase, state_root, tx_trie_root, // difficulty, number, minGasPrice, gasLimit, gasUsed, timestamp, // extradata, nonce] @@ -247,22 +248,34 @@ public class Block { public String toString() { if (!parsed) parseRLP(); - return "BlockData [" + - " hash=" + Utils.toHexString(hash) + - " parentHash=" + Utils.toHexString(parentHash) + - ", unclesHash=" + Utils.toHexString(unclesHash) + - ", coinbase=" + Utils.toHexString(coinbase) + - ", stateHash=" + Utils.toHexString(stateRoot) + - ", txTrieHash=" + Utils.toHexString(txTrieRoot) + - ", difficulty=" + Utils.toHexString(difficulty) + - ", number=" + number + - ", minGasPrice=" + minGasPrice + - ", gasLimit=" + gasLimit + - ", gasUsed=" + gasUsed + - ", timestamp=" + timestamp + - ", extraData=" + Utils.toHexString(extraData) + - ", nonce=" + Utils.toHexString(nonce) + - ']'; + toStringBuff.setLength(0); + toStringBuff.append("BlockData [\n"); + toStringBuff.append(" hash=" + Utils.toHexString(hash)).append("\n"); + toStringBuff.append(" parentHash=" + Utils.toHexString(parentHash)).append("\n"); + toStringBuff.append(" unclesHash=" + Utils.toHexString(unclesHash)).append("\n"); + toStringBuff.append(" coinbase=" + Utils.toHexString(coinbase)).append("\n"); + toStringBuff.append(" stateHash=" + Utils.toHexString(stateRoot)).append("\n"); + toStringBuff.append(" txTrieHash=" + Utils.toHexString(txTrieRoot)).append("\n"); + toStringBuff.append(" difficulty=" + Utils.toHexString(difficulty)).append("\n"); + toStringBuff.append(" number=" + number).append("\n"); + 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(" extraData=" + Utils.toHexString(extraData)).append("\n"); + toStringBuff.append(" nonce=" + Utils.toHexString(nonce)).append("\n"); + + for (Transaction tx : getTransactionsList()){ + + toStringBuff.append("\n"); + toStringBuff.append( tx.toString() ); + } + + + toStringBuff.append("\n]"); + + + return toStringBuff.toString(); } /** 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 e1a13770..d3af827d 100644 --- a/ethereumj-core/src/main/java/org/ethereum/gui/BlockChainTable.java +++ b/ethereumj-core/src/main/java/org/ethereum/gui/BlockChainTable.java @@ -1,9 +1,17 @@ package org.ethereum.gui; +import org.ethereum.core.Block; +import org.ethereum.manager.MainData; + import javax.swing.*; import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.TableCellRenderer; import java.awt.*; +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 @@ -16,9 +24,13 @@ public class BlockChainTable extends JFrame { private JTable table; private JScrollPane scrollPane; + private int lastFindIndex = 0; + public BlockChainTable() { + final BlockChainTable blockChainTable = this; + setTitle("Block Chain Table"); setSize(700, 400); setLocation(315, 180); @@ -47,15 +59,58 @@ public class BlockChainTable extends JFrame { renderer.setHorizontalAlignment(SwingConstants.LEFT); renderer.setVerticalAlignment(SwingConstants.TOP); - table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setCellSelectionEnabled(true); table.setRowMargin(3); - table.setRowHeight(120); + table.setRowHeight(420); 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(){ + @Override + public void actionPerformed(ActionEvent e) { + + if (MainData.instance.getAllBlocks().size() - 1 < lastFindIndex) return; + + Block block = MainData.instance.getAllBlocks().get(lastFindIndex); + StringSelection stsel = new StringSelection(block.toString()); + Clipboard system = Toolkit.getDefaultToolkit().getSystemClipboard(); + system.setContents(stsel,stsel); + } + } ); + + table.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_F, KeyEvent.CTRL_DOWN_MASK), "Find"); + table.getActionMap().put("Find", new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + + String toFind = JOptionPane.showInputDialog(blockChainTable, "Find:", + "Find in BlockChain", JOptionPane.QUESTION_MESSAGE); + + if (toFind.equals("")){ + lastFindIndex = 0; + return; + } + + 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); + boolean found = block.toString().toLowerCase().contains(toFind.toLowerCase()); + if (found) { + // todo: now we find the first occur + // todo: in the future I should keep + // todo: all of them and allow to jump over them + table.scrollRectToVisible(table.getCellRect(i, 0, true)); + lastFindIndex = i; + break; + } + } + } + }); + // Add the table to a scrolling pane scrollPane = new JScrollPane(table); topPanel.add(scrollPane, BorderLayout.CENTER); diff --git a/ethereumj-core/src/main/java/org/ethereum/net/client/EthereumProtocolHandler.java b/ethereumj-core/src/main/java/org/ethereum/net/client/EthereumProtocolHandler.java index fe2dd24b..6859ba10 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/client/EthereumProtocolHandler.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/client/EthereumProtocolHandler.java @@ -108,7 +108,7 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter { System.out.println("[Send: GET_CHAIN]"); sendGetChain(ctx); } - }, 10000, 10000); + }, 5000, 1000); /* timer.schedule(new TimerTask() {