reverting for java7

This commit is contained in:
Roman Mandeleil 2014-12-30 13:45:16 +02:00
parent 0f98cbcb8b
commit c95f5ea75f
33 changed files with 420 additions and 294 deletions

View File

@ -7,7 +7,7 @@ allprojects {
subprojects {
apply plugin: 'java'
sourceCompatibility = 1.8
sourceCompatibility = 1.7
group = 'org.ethereum'
version = '0.7.14-SNAPSHOT'

View File

@ -13,17 +13,21 @@ plugins {
mainClassName = 'org.ethereum.Start'
ext.generatedSrcDir = file('src/gen/java')
sourceSets.main.java.srcDirs += generatedSrcDir
antlr4 {
extraArgs = ['-package', 'org.ethereum.serpent']
output = file("${generatedSrcDir}/org/ethereum/serpent")
}
compileJava.dependsOn antlr4
configurations {
compile.extendsFrom antlr4
}

View File

@ -26,7 +26,7 @@ public class Account {
private byte[] address;
private Set<Transaction> pendingTransactions =
Collections.synchronizedSet(new HashSet<>());
Collections.synchronizedSet(new HashSet<Transaction>());
@Autowired
WorldManager worldManager;

View File

@ -82,7 +82,7 @@ public class Wallet {
Account account = new Account();
String address = Hex.toHexString(account.getEcKey().getAddress());
rows.put(address, account);
listeners.forEach(Wallet.WalletListener::valueChanged);
for (WalletListener listener : listeners) listener.valueChanged();
}
public void importKey(byte[] privKey) {
@ -157,7 +157,9 @@ public class Wallet {
}
public void addTransactions(List<Transaction> transactions) {
transactions.forEach(this::addTransaction);
for (Transaction transaction : transactions) {
this.addTransaction(transaction);
}
}
public void removeTransactions(List<Transaction> transactions) {
@ -207,7 +209,9 @@ public class Wallet {
public void processBlock(Block block) {
getAccountCollection().forEach(org.ethereum.core.Account::clearAllPendingTransactions);
for (Account account : getAccountCollection()){
account.clearAllPendingTransactions();
}
notifyListeners();
}
@ -340,7 +344,8 @@ public class Wallet {
}
private void notifyListeners() {
listeners.forEach(Wallet.WalletListener::valueChanged);
for (WalletListener listener : listeners)
listener.valueChanged();
}
public interface WalletListener {

View File

@ -74,7 +74,9 @@ public class BlockStore {
setParameter("limit", block.getNumber() - qty).
setMaxResults(qty).list();
hashes.addAll(result.stream().collect(Collectors.toList()));
for (byte[] h : result){
hashes.add(h);
}
return hashes;
}

View File

@ -61,11 +61,13 @@ public class EthereumImpl implements Ethereum {
}
@PostConstruct
public void init() {
public void init(){
worldManager.loadBlockchain();
if (CONFIG.listenPort() > 0) {
if (CONFIG.listenPort() > 0){
Executors.newSingleThreadExecutor().submit(
() -> peerServer.start(CONFIG.listenPort())
new Runnable() { public void run() {
peerServer.start(CONFIG.listenPort());
}}
);
}
}

View File

@ -153,13 +153,13 @@ public class AccountState {
checked.add(key);
}
expectedKeys.stream()
.filter(key -> !checked.contains(key))
.forEach(key -> {
String formatedString = String.format("Account: %s: doesn't exist expected storage key: %s",
Hex.toHexString(this.address), key.toString());
results.add(formatedString);
});
for (DataWord key : expectedKeys){
if (!checked.contains(key)){
String formatedString = String.format("Account: %s: doesn't exist expected storage key: %s",
Hex.toHexString(this.address), key.toString());
results.add(formatedString);
}
}
return results;
}

View File

@ -1,9 +1,6 @@
package org.ethereum.manager;
import org.ethereum.core.Block;
import org.ethereum.core.Genesis;
import org.ethereum.core.Transaction;
import org.ethereum.core.Wallet;
import org.ethereum.core.*;
import org.ethereum.crypto.HashUtil;
import org.ethereum.db.BlockStore;
import org.ethereum.facade.Blockchain;
@ -70,7 +67,7 @@ public class WorldManager {
@Autowired
private AdminInfo adminInfo;
private final Set<Transaction> pendingTransactions = Collections.synchronizedSet(new HashSet<>());
private final Set<Transaction> pendingTransactions = Collections.synchronizedSet(new HashSet<Transaction>());
@Autowired
private EthereumListener listener;
@ -170,7 +167,7 @@ public class WorldManager {
repository.addBalance(Hex.decode(address), Genesis.PREMINE_AMOUNT);
}
blockStore.saveBlock(Genesis.getInstance(), new ArrayList<>());
blockStore.saveBlock(Genesis.getInstance(), new ArrayList<TransactionReceipt>());
blockchain.setBestBlock(Genesis.getInstance());
blockchain.setTotalDifficulty(BigInteger.ZERO);

View File

@ -43,17 +43,15 @@ public class BlockHashesMessage extends EthMessage {
parsed = true;
}
private void encode() {
List<byte[]> encodedElements = new ArrayList<>();
encodedElements.add(RLP.encodeByte(BLOCK_HASHES.asByte()));
encodedElements.addAll(
blockHashes.stream()
.map(RLP::encodeElement)
.collect(Collectors.toList()));
byte[][] encodedElementArray = encodedElements
.toArray(new byte[encodedElements.size()][]);
this.encoded = RLP.encodeList(encodedElementArray);
}
private void encode() {
List<byte[]> encodedElements = new ArrayList<>();
encodedElements.add(RLP.encodeByte(BLOCK_HASHES.asByte()));
for (byte[] blockHash : blockHashes)
encodedElements.add(RLP.encodeElement(blockHash));
byte[][] encodedElementArray = encodedElements
.toArray(new byte[encodedElements.size()][]);
this.encoded = RLP.encodeList(encodedElementArray);
}
@Override

View File

@ -46,10 +46,9 @@ public class BlocksMessage extends EthMessage {
List<byte[]> encodedElements = new Vector<>();
encodedElements.add(RLP.encodeByte(BLOCKS.asByte()));
encodedElements.addAll(
blocks.stream()
.map(Block::getEncoded)
.collect(Collectors.toList()));
for (Block block : blocks){
encodedElements.add(block.getEncoded());
}
byte[][] encodedElementArray = encodedElements
.toArray(new byte[encodedElements.size()][]);

View File

@ -41,17 +41,15 @@ public class GetBlocksMessage extends EthMessage {
parsed = true;
}
private void encode() {
List<byte[]> encodedElements = new ArrayList<>();
encodedElements.add(RLP.encodeByte(GET_BLOCKS.asByte()));
encodedElements.addAll(
blockHashes.stream()
.map(RLP::encodeElement)
.collect(Collectors.toList()));
byte[][] encodedElementArray = encodedElements
.toArray(new byte[encodedElements.size()][]);
this.encoded = RLP.encodeList(encodedElementArray);
}
private void encode() {
List<byte[]> encodedElements = new ArrayList<>();
encodedElements.add(RLP.encodeByte(GET_BLOCKS.asByte()));
for (byte[] hash : blockHashes)
encodedElements.add(RLP.encodeElement(hash));
byte[][] encodedElementArray = encodedElements
.toArray(new byte[encodedElements.size()][]);
this.encoded = RLP.encodeList(encodedElementArray);
}
@Override
public byte[] getEncoded() {

View File

@ -50,14 +50,12 @@ public class TransactionsMessage extends EthMessage {
}
private void encode() {
List<byte[]> encodedElements = new ArrayList<>();
encodedElements.add(RLP.encodeByte(TRANSACTIONS.asByte()));
encodedElements.addAll(
transactions.stream()
.map(Transaction::getEncoded)
.collect(Collectors.toList()));
byte[][] encodedElementArray = encodedElements
.toArray(new byte[encodedElements.size()][]);
List<byte[]> encodedElements = new ArrayList<>();
encodedElements.add(RLP.encodeByte(TRANSACTIONS.asByte()));
for (Transaction tx : transactions)
encodedElements.add(tx.getEncoded());
byte[][] encodedElementArray = encodedElements
.toArray(new byte[encodedElements.size()][]);
this.encoded = RLP.encodeList(encodedElementArray);
}

View File

@ -207,28 +207,31 @@ public class P2pHandler extends SimpleChannelInboundHandler<P2pMessage> {
private void setHandshake(HelloMessage msg, ChannelHandlerContext ctx) {
this.handshakeHelloMessage = msg;
if (msg.getP2PVersion() != P2pHandler.VERSION)
msgQueue.sendMessage(new DisconnectMessage(ReasonCode.INCOMPATIBLE_PROTOCOL));
else {
List<Capability> capInCommon = new ArrayList<>();
msg.getCapabilities().stream()
.filter(capability -> HELLO_MESSAGE.getCapabilities().contains(capability))
.forEach(capability -> {
if (capability.getName().equals(Capability.ETH)) {
// Activate EthHandler for this peer
EthHandler ethHandler =
(EthHandler) ctx.pipeline().get(Capability.ETH);
if (msg.getP2PVersion() != P2pHandler.VERSION)
msgQueue.sendMessage(new DisconnectMessage(ReasonCode.INCOMPATIBLE_PROTOCOL));
else {
List<Capability> capInCommon = new ArrayList<>();
for (Capability capability : msg.getCapabilities()) {
if (HELLO_MESSAGE.getCapabilities().contains(capability)) {
if (capability.getName().equals(Capability.ETH)){
ethHandler.setPeerId(msg.getPeerId());
ethHandler.activate();
} else if (capability.getName().equals(Capability.SHH)) {
// Activate ShhHandler for this peer
ShhHandler shhHandler =
(ShhHandler) ctx.pipeline().get(Capability.SHH);
shhHandler.activate();
}
capInCommon.add(capability);
});
// Activate EthHandler for this peer
EthHandler ethHandler =
(EthHandler)ctx.pipeline().get(Capability.ETH);
ethHandler.setPeerId(msg.getPeerId());
ethHandler.activate();
}
else if (capability.getName().equals(Capability.SHH)){
// Activate ShhHandler for this peer
ShhHandler shhHandler =
(ShhHandler)ctx.pipeline().get(Capability.SHH);
shhHandler.activate();
}
capInCommon.add(capability);
}
}
adaptMessageIds(capInCommon);
InetAddress address = ((InetSocketAddress) ctx.channel().remoteAddress()).getAddress();

View File

@ -38,7 +38,7 @@ public class PeerDiscovery {
private static final Logger logger = LoggerFactory.getLogger("peerdiscovery");
private final Set<PeerInfo> peers = Collections.synchronizedSet(new HashSet<>());
private final Set<PeerInfo> peers = Collections.synchronizedSet(new HashSet<PeerInfo>());
private PeerMonitorThread monitor;
private ThreadFactory threadFactory;
@ -59,10 +59,10 @@ public class PeerDiscovery {
// Get the ThreadFactory implementation to use
threadFactory = Executors.defaultThreadFactory();
// creating the ThreadPoolExecutor
executorPool = new ThreadPoolExecutor(CONFIG.peerDiscoveryWorkers(),
CONFIG.peerDiscoveryWorkers(), 10, TimeUnit.SECONDS, new ArrayBlockingQueue<>(
1000), threadFactory, rejectionHandler);
// creating the ThreadPoolExecutor
executorPool = new ThreadPoolExecutor(CONFIG.peerDiscoveryWorkers(),
CONFIG.peerDiscoveryWorkers(), 10, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(
1000), threadFactory, rejectionHandler);
// start the monitoring thread
monitor = new PeerMonitorThread(executorPool, 1, this);

View File

@ -32,7 +32,7 @@ public class ChannelManager {
private static final Logger logger = LoggerFactory.getLogger("net");
Timer inactivesCollector = new Timer("inactivesCollector");
List<Channel> channels = Collections.synchronizedList(new ArrayList<>());
List<Channel> channels = Collections.synchronizedList(new ArrayList<Channel>());
Map<ByteArrayWrapper, Block> blockCache = new HashMap<>();
@ -108,7 +108,9 @@ public class ChannelManager {
}
public void reconnect(){
channels.forEach(c -> c.p2pHandler.sendDisconnect());
for (Channel channel : channels){
channel.p2pHandler.sendDisconnect();
}
}
public void ethSync() {

View File

@ -11,10 +11,7 @@ import org.slf4j.LoggerFactory;
import org.spongycastle.util.encoders.Hex;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;
import static java.util.Arrays.copyOfRange;
@ -437,10 +434,14 @@ public class TrieImpl implements Trie {
this.scanTree(this.getRootHash(), collectAction);
Set<byte[]> hashSet = collectAction.getCollectedHashes();
Map<ByteArrayWrapper, Node> nodes = this.getCache().getNodes();
Set<ByteArrayWrapper> toRemoveSet = nodes.keySet().stream()
.filter(key -> !hashSet.contains(key.getData()))
.collect(Collectors.toSet());
Map<ByteArrayWrapper, Node> nodes = this.getCache().getNodes();
Set<ByteArrayWrapper> toRemoveSet = new HashSet<>();
for (ByteArrayWrapper key : nodes.keySet()) {
if (!hashSet.contains(key.getData())) {
toRemoveSet.add(key);
}
}
for (ByteArrayWrapper key : toRemoveSet) {

View File

@ -130,21 +130,24 @@ public abstract class FastByteComparisons {
*/
static final int BYTE_ARRAY_BASE_OFFSET;
static {
theUnsafe = (Unsafe) AccessController.doPrivileged(
(PrivilegedAction<Object>) () -> {
try {
Field f = Unsafe.class.getDeclaredField("theUnsafe");
f.setAccessible(true);
return f.get(null);
} catch (NoSuchFieldException e) {
// It doesn't matter what we throw;
// it's swallowed in getBestComparer().
throw new Error();
} catch (IllegalAccessException e) {
throw new Error();
}
});
static {
theUnsafe = (Unsafe) AccessController.doPrivileged(
new PrivilegedAction<Object>() {
@Override
public Object run() {
try {
Field f = Unsafe.class.getDeclaredField("theUnsafe");
f.setAccessible(true);
return f.get(null);
} catch (NoSuchFieldException e) {
// It doesn't matter what we throw;
// it's swallowed in getBestComparer().
throw new Error();
} catch (IllegalAccessException e) {
throw new Error();
}
}
});
BYTE_ARRAY_BASE_OFFSET = theUnsafe.arrayBaseOffset(byte[].class);

View File

@ -24,9 +24,11 @@ public class RLPList extends ArrayList<RLPElement> implements RLPElement {
throw new RuntimeException("RLPElement object can't be null");
if (element instanceof RLPList) {
RLPList rlpList = (RLPList) element;
System.out.print("[");
rlpList.forEach(org.ethereum.util.RLPList::recursivePrint);
RLPList rlpList = (RLPList) element;
System.out.print("[");
for (RLPElement singleElement : rlpList) {
recursivePrint(singleElement);
}
System.out.print("]");
} else {
String hex = ByteUtil.toHexString(element.getRLPData());

View File

@ -46,9 +46,9 @@ public class LogInfo {
}
public LogInfo(byte[] address, List<DataWord> topics, byte[] data) {
this.address = (address != null) ? address : new byte[]{};
this.topics = (topics != null) ? topics : new ArrayList<>();
this.data = (data != null) ? data : new byte[]{};
this.address = (address != null) ? address : new byte[]{} ;
this.topics = (topics != null) ? topics : new ArrayList<DataWord>();
this.data = (data != null) ? data : new byte[]{} ;
}
public byte[] getAddress() {

View File

@ -26,6 +26,7 @@ import java.math.BigInteger;
import java.security.SignatureException;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.Executors;
import static com.google.common.base.Preconditions.checkNotNull;
@ -174,7 +175,12 @@ public class ECKeyTest {
final ECKey key = new ECKey();
for (byte i = 0; i < ITERATIONS; i++) {
final byte[] hash = HashUtil.sha3(new byte[]{i});
sigFutures.add(executor.submit(() -> key.doSign(hash)));
sigFutures.add(executor.submit(new Callable<ECDSASignature>() {
@Override
public ECKey.ECDSASignature call() throws Exception {
return key.doSign(hash);
}
}));
}
List<ECKey.ECDSASignature> sigs = Futures.allAsList(sigFutures).get();
for (ECKey.ECDSASignature signature : sigs) {

View File

@ -77,8 +77,10 @@ public class GitHubJSONTestSuite {
TestRunner runner = new TestRunner();
List<String> result = runner.runTestCase(testCase);
if (!result.isEmpty()) {
result.forEach(logger::info);
if (!result.isEmpty()){
for (String single : result){
logger.info(single);
}
}
Assert.assertTrue(result.isEmpty());
@ -107,8 +109,10 @@ public class GitHubJSONTestSuite {
TestRunner runner = new TestRunner();
List<String> result = runner.runTestCase(testCase);
if (!result.isEmpty()) {
result.forEach(logger::info);
if (!result.isEmpty()){
for (String single : result){
logger.info(single);
}
}
Assert.assertTrue(result.isEmpty());
@ -131,8 +135,10 @@ public class GitHubJSONTestSuite {
TestRunner runner = new TestRunner();
List<String> result = runner.runTestCase(testCase);
if (!result.isEmpty()) {
result.forEach(logger::info);
if (!result.isEmpty()){
for (String single : result){
logger.info(single);
}
}
Assert.assertTrue(result.isEmpty());

View File

@ -38,7 +38,7 @@ public class AccountsListWindow extends JFrame {
tblAccountsDataTable = new JTable();
adapter = new AccountsDataAdapter(new ArrayList<>());
adapter = new AccountsDataAdapter(new ArrayList<DataClass>());
tblAccountsDataTable.setModel(adapter);
JScrollPane scrollPane = new JScrollPane(tblAccountsDataTable);

View File

@ -823,16 +823,19 @@ public class BlockChainTable extends JFrame implements ActionListener {
transactionPanel.add(nonce, c);
JButton data = new JButton("Data");
data.addActionListener(event -> {
if (transactionDataWindow == null)
transactionDataWindow = new TransactionData(blockchainTable);
transactionDataWindow.setData(transaction.getData());
transactionDataWindow.setVisible(true);
transactionDataWindow.highlightText(findText.getText(), painter);
data.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
if (transactionDataWindow == null)
transactionDataWindow = new TransactionData(blockchainTable);
transactionDataWindow.setData(transaction.getData());
transactionDataWindow.setVisible(true);
transactionDataWindow.highlightText(findText.getText(), painter);
}
});
data.setFont(plain);
if (findText.getText().length() > 0 && ByteUtil.toHexString(transaction.getData()).contains(findText.getText
())) {
if (findText.getText().length() > 0 && ByteUtil.toHexString(transaction.getData()).contains(findText.getText())) {
data.setBackground(HILIT_COLOR);
}
c.gridx = 3;

View File

@ -89,12 +89,14 @@ public class ConnectionConsoleWindow extends JFrame {
UIEthereumManager.ethereum.addListener(new EthereumListenerAdapter() {
@Override
public void trace(final String output) {
SwingUtilities.invokeLater(() -> {
textArea.append(output);
textArea.append("\n");
SwingUtilities.invokeLater(new Runnable() {
public void run() {
textArea.append(output);
textArea.append("\n");
if (autoScroll)
textArea.setCaretPosition(textArea.getText().length());
if (autoScroll)
textArea.setCaretPosition(textArea.getText().length());
}
});
}
});
@ -145,10 +147,14 @@ public class ConnectionConsoleWindow extends JFrame {
});
}
public static void main(String[] args) {
// Start all Swing applications on the EDT.
SwingUtilities.invokeLater(() -> new ConnectionConsoleWindow(null).setVisible(true));
}
public static void main(String[] args) {
// Start all Swing applications on the EDT.
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new ConnectionConsoleWindow(null).setVisible(true);
}
});
}
}

View File

@ -70,7 +70,11 @@ class ContractCallDialog extends JDialog implements MessageAwareDialog {
@Override
public void focusLost(FocusEvent e) {
SwingUtilities.invokeLater(ContractCallDialog.this::populateContractDetails);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
populateContractDetails();
}
});
}
});

View File

@ -235,9 +235,11 @@ class PayOutDialog extends JDialog implements MessageAwareDialog {
inputMap.put(stroke, "ESCAPE");
rootPane.getActionMap().put("ESCAPE", actionListener);
SwingUtilities.invokeLater(() -> {
setSize(500, 255);
setVisible(true);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
setSize(500, 255);
setVisible(true);
}
});
@ -248,22 +250,26 @@ class PayOutDialog extends JDialog implements MessageAwareDialog {
final PayOutDialog dialog = this;
SwingUtilities.invokeLater(() -> {
dialog.statusMsg.setForeground(Color.GREEN.darker().darker());
dialog.statusMsg.setText(text);
dialog.revalidate();
dialog.repaint();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
dialog.statusMsg.setForeground(Color.GREEN.darker().darker());
dialog.statusMsg.setText(text);
dialog.revalidate();
dialog.repaint();
}
});
}
public void alertStatusMsg(final String text) {
final PayOutDialog dialog = this;
SwingUtilities.invokeLater(() -> {
dialog.statusMsg.setForeground(Color.RED);
dialog.statusMsg.setText(text);
dialog.revalidate();
dialog.repaint();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
dialog.statusMsg.setForeground(Color.RED);
dialog.statusMsg.setText(text);
dialog.revalidate();
dialog.repaint();
}
});
}

View File

@ -79,8 +79,12 @@ public class PeerInfoWindow extends JFrame {
});
}
public static void main(String[] args) {
// Start all Swing applications on the EDT.
SwingUtilities.invokeLater(() -> new PeerInfoWindow(null).setVisible(true));
}
public static void main(String[] args) {
// Start all Swing applications on the EDT.
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new PeerInfoWindow(null).setVisible(true);
}
});
}
}

View File

@ -32,11 +32,16 @@ public class PeersTableModel extends AbstractTableModel {
updater.scheduleAtFixedRate(new TimerTask() {
public void run() {
SwingUtilities.invokeLater(
PeersTableModel.this::updateModel
new Runnable() {
@Override
public void run() {
updateModel();
}
}
);
}
}, 0, 100);
}
}
}, 0, 100);
}
public String getColumnName(int column) {
if (column == 0) return "Location";

View File

@ -64,7 +64,11 @@ public class PeersTableWindow extends JFrame {
PeersTableModel model = (PeersTableModel) table.getModel();
if (me.getClickCount() == 2) {
final PeersTableModel.PeerInfo peerInfo = model.getPeerInfo(row);
SwingUtilities.invokeLater(() -> new PeerInfoWindow(peerInfo).setVisible(true));
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new PeerInfoWindow(peerInfo).setVisible(true);
}
});
System.out.println(peerInfo);
}
}

View File

@ -190,6 +190,10 @@ public class ProgramPlayDialog extends JPanel implements ActionListener,
// final byte[] code = SerpentCompiler.compileAssemblyToMachine(asmCode);
final byte[] code = Hex.decode("7f4e616d65526567000000000000000000000000000000000000000000000000003057307f4e616d6552656700000000000000000000000000000000000000000000000000573360455760415160566000396000f20036602259604556330e0f600f5933ff33560f601e5960003356576000335700604158600035560f602b590033560f60365960003356573360003557600035335700");
SwingUtilities.invokeLater(() -> createAndShowGUI(code, null, null));
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI(code, null, null);
}
});
}
}

View File

@ -13,11 +13,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.*;
import java.io.BufferedWriter;
import java.io.File;
@ -274,22 +270,25 @@ public class SerpentEditor extends JFrame {
put(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_DOWN_MASK),
"OpenFileButton");
mainContentPane.getActionMap().put("OpenFileButton", openFile);
mainContentPane.getActionMap().put("OpenFileButton",openFile);
button.addActionListener(e -> {
File file = callFileChooser();
try {
if (file == null)
return;
String content = new Scanner(file).useDelimiter("\\Z").next();
codeArea.setText(content);
} catch (FileNotFoundException e1) {
logger.error(e1.getMessage(), e1);
} catch (java.util.NoSuchElementException e2) {
// don't worry it's just the file is empty
codeArea.setText("");
}
});
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
File file = callFileChooser();
try {
if (file == null)
return;
String content = new Scanner(file).useDelimiter("\\Z").next();
codeArea.setText(content);
} catch (FileNotFoundException e1) {
logger.error(e1.getMessage(), e1);
} catch (java.util.NoSuchElementException e2) {
// don't worry it's just the file is empty
codeArea.setText("");
}
}
});
toolbar.add(button);
}
@ -327,31 +326,34 @@ public class SerpentEditor extends JFrame {
mainContentPane.getActionMap().put("OpenSaveButton", saveFile);
button.addActionListener(e -> {
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
File file = null;
File file = null;
if (e.getModifiers() == (InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK)) {
file = callFileChooser();
if (file == null)
return;
} else if (fileChooser == null
|| fileChooser.getSelectedFile() == null) {
file = callFileChooser();
if (file == null)
return;
} else {
file = fileChooser.getSelectedFile();
}
if (e.getModifiers() == (InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK)) {
file = callFileChooser();
if (file == null)
return;
} else if (fileChooser == null
|| fileChooser.getSelectedFile() == null) {
file = callFileChooser();
if (file == null)
return;
} else {
file = fileChooser.getSelectedFile();
}
try {
BufferedWriter out = new BufferedWriter(new FileWriter(file), 32768);
out.write(codeArea.getText());
out.close();
} catch (IOException e1) {
logger.error(e1.getMessage(), e1);
}
});
try {
BufferedWriter out = new BufferedWriter(new FileWriter(file), 32768);
out.write(codeArea.getText());
out.close();
} catch (IOException e1) {
logger.error(e1.getMessage(), e1);
}
}
});
toolbar.add(button);
}
toolbar.addSeparator();
@ -377,7 +379,12 @@ public class SerpentEditor extends JFrame {
mainContentPane.getActionMap().put("CompileButton", compile);
button.addActionListener(e -> compileCode());
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
compileCode();
}
});
toolbar.add(button);
}
@ -403,12 +410,14 @@ public class SerpentEditor extends JFrame {
mainContentPane.getActionMap().put("DeployButton", deploy);
button.addActionListener(e -> {
byte[] machineCode = prepareCodeForSend();
if (machineCode == null) return;
ContractSubmitDialog payOutDialog =
new ContractSubmitDialog((Frame) SwingUtilities.getAncestorOfClass(JFrame.class,
contentPane), machineCode);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
byte[] machineCode = prepareCodeForSend();
if (machineCode == null) return;
ContractSubmitDialog payOutDialog =
new ContractSubmitDialog((Frame) SwingUtilities.getAncestorOfClass(JFrame.class,
contentPane), machineCode);
}
});
toolbar.add(button);
}
@ -435,11 +444,13 @@ public class SerpentEditor extends JFrame {
mainContentPane.getActionMap().put("CallButton", call);
button.addActionListener(e -> {
ContractCallDialog payOutDialog = new ContractCallDialog(
(Frame) SwingUtilities.getAncestorOfClass(
JFrame.class, contentPane));
});
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ContractCallDialog payOutDialog = new ContractCallDialog(
(Frame) SwingUtilities.getAncestorOfClass(
JFrame.class, contentPane));
}
});
toolbar.add(button);
}
this.contentPane.add(toolbar, BorderLayout.EAST);
@ -473,6 +484,10 @@ public class SerpentEditor extends JFrame {
public static void main(String[] args) {
// Start all Swing applications on the EDT.
SwingUtilities.invokeLater(() -> new SerpentEditor(null).setVisible(true));
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new SerpentEditor(null).setVisible(true);
}
});
}
}
}

View File

@ -10,8 +10,7 @@ import org.ethereum.vm.Program;
import org.spongycastle.util.encoders.Hex;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.*;
import java.math.BigInteger;
@ -66,11 +65,18 @@ public class StateExplorerWindow extends JFrame {
btnListAccounts.setBorderPainted(false);
btnListAccounts.setFocusPainted(false);
btnListAccounts.setCursor(new Cursor(Cursor.HAND_CURSOR));
btnListAccounts.addItemListener(e -> SwingUtilities.invokeLater(() -> {
if (accountsListWindow == null)
accountsListWindow = new AccountsListWindow();
accountsListWindow.setVisible(true);
}));
btnListAccounts.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
if(accountsListWindow == null)
accountsListWindow = new AccountsListWindow();
accountsListWindow.setVisible(true);
}
});
}
});
horizontalBox.add(btnListAccounts);
@ -125,11 +131,13 @@ public class StateExplorerWindow extends JFrame {
l1.setAlignmentX(Component.CENTER_ALIGNMENT);
JComboBox cmbKey = new JComboBox(dataTypes);
cmbKey.setSelectedIndex(1);
cmbKey.addActionListener(e -> {
JComboBox cmb = (JComboBox) e.getSource();
DataEncodingType t = DataEncodingType.getTypeFromString((String) cmb.getSelectedItem());
dataModel.setKeyEncoding(t);
});
cmbKey.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JComboBox cmb = (JComboBox) e.getSource();
DataEncodingType t = DataEncodingType.getTypeFromString((String) cmb.getSelectedItem());
dataModel.setKeyEncoding(t);
}
});
VBox1.add(l1);
VBox1.add(cmbKey);
@ -139,11 +147,13 @@ public class StateExplorerWindow extends JFrame {
l2.setAlignmentX(Component.CENTER_ALIGNMENT);
JComboBox cmbValue = new JComboBox(dataTypes);
cmbValue.setSelectedIndex(1);
cmbValue.addActionListener(e -> {
JComboBox cmb = (JComboBox) e.getSource();
DataEncodingType t = DataEncodingType.getTypeFromString((String) cmb.getSelectedItem());
dataModel.setValueEncoding(t);
});
cmbValue.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JComboBox cmb = (JComboBox) e.getSource();
DataEncodingType t = DataEncodingType.getTypeFromString((String) cmb.getSelectedItem());
dataModel.setValueEncoding(t);
}
});
VBox2.add(l2);
VBox2.add(cmbValue);
@ -304,6 +314,10 @@ public class StateExplorerWindow extends JFrame {
public static void main(String[] args) {
// Start all Swing applications on the EDT.
SwingUtilities.invokeLater(() -> new StateExplorerWindow(null).setVisible(true));
}
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new StateExplorerWindow(null).setVisible(true);
}
});
}
}

View File

@ -9,6 +9,7 @@ import org.slf4j.LoggerFactory;
import java.awt.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
@ -107,15 +108,20 @@ public class ToolBar extends JFrame {
editorToggle.setBorderPainted(false);
editorToggle.setFocusPainted(false);
editorToggle.setCursor(new Cursor(Cursor.HAND_CURSOR));
editorToggle.addItemListener(e -> {
if (e.getStateChange() == ItemEvent.SELECTED) {
SwingUtilities.invokeLater(() -> {
if (serpentEditor == null)
serpentEditor = new SerpentEditor(ToolBar.this);
serpentEditor.setVisible(true);
});
} else if (e.getStateChange() == ItemEvent.DESELECTED) {
serpentEditor.setVisible(false);
editorToggle.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
if (serpentEditor == null)
serpentEditor = new SerpentEditor(ToolBar.this);
serpentEditor.setVisible(true);
}
});
} else if (e.getStateChange() == ItemEvent.DESELECTED) {
serpentEditor.setVisible(false);
}
}
});
@ -127,15 +133,20 @@ public class ToolBar extends JFrame {
logToggle.setBorderPainted(false);
logToggle.setFocusPainted(false);
logToggle.setCursor(new Cursor(Cursor.HAND_CURSOR));
logToggle.addItemListener(e -> {
if (e.getStateChange() == ItemEvent.SELECTED) {
SwingUtilities.invokeLater(() -> {
if (connectionConsoleWindow == null)
connectionConsoleWindow = new ConnectionConsoleWindow(ToolBar.this);
connectionConsoleWindow.setVisible(true);
});
} else if (e.getStateChange() == ItemEvent.DESELECTED) {
connectionConsoleWindow.setVisible(false);
logToggle.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
if (connectionConsoleWindow == null)
connectionConsoleWindow = new ConnectionConsoleWindow(ToolBar.this);
connectionConsoleWindow.setVisible(true);
}
});
} else if (e.getStateChange() == ItemEvent.DESELECTED) {
connectionConsoleWindow.setVisible(false);
}
}
});
@ -147,15 +158,20 @@ public class ToolBar extends JFrame {
peersToggle.setBorderPainted(false);
peersToggle.setFocusPainted(false);
peersToggle.setCursor(new Cursor(Cursor.HAND_CURSOR));
peersToggle.addItemListener(e -> {
if (e.getStateChange() == ItemEvent.SELECTED) {
SwingUtilities.invokeLater(() -> {
if (mainFrame == null)
mainFrame = new PeersTableWindow(ToolBar.this);
mainFrame.setVisible(true);
});
} else if (e.getStateChange() == ItemEvent.DESELECTED) {
mainFrame.setVisible(false);
peersToggle.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
if (mainFrame == null)
mainFrame = new PeersTableWindow(ToolBar.this);
mainFrame.setVisible( true );
}
});
} else if (e.getStateChange() == ItemEvent.DESELECTED) {
mainFrame.setVisible( false );
}
}
});
@ -167,16 +183,21 @@ public class ToolBar extends JFrame {
chainToggle.setBorderPainted(false);
chainToggle.setFocusPainted(false);
chainToggle.setCursor(new Cursor(Cursor.HAND_CURSOR));
chainToggle.addItemListener(e -> {
if (e.getStateChange() == ItemEvent.SELECTED) {
SwingUtilities.invokeLater(() -> {
chainToggle.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
if (blockchainWindow == null)
blockchainWindow = new BlockChainTable(ToolBar.this);
blockchainWindow.setVisible(true);
});
} else if (e.getStateChange() == ItemEvent.DESELECTED) {
blockchainWindow.setVisible(false);
if (blockchainWindow == null)
blockchainWindow = new BlockChainTable(ToolBar.this);
blockchainWindow.setVisible(true);
}
});
} else if (e.getStateChange() == ItemEvent.DESELECTED) {
blockchainWindow.setVisible(false);
}
}
});
@ -189,15 +210,20 @@ public class ToolBar extends JFrame {
walletToggle.setFocusPainted(false);
walletToggle.setCursor(new Cursor(Cursor.HAND_CURSOR));
walletToggle.addItemListener(
e -> {
if (e.getStateChange() == ItemEvent.SELECTED) {
SwingUtilities.invokeLater(() -> {
if (walletWindow == null)
walletWindow = new WalletWindow(ToolBar.this);
walletWindow.setVisible(true);
});
} else if (e.getStateChange() == ItemEvent.DESELECTED) {
walletWindow.setVisible(false);
new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
if (walletWindow == null)
walletWindow = new WalletWindow(ToolBar.this);
walletWindow.setVisible(true);
}
});
} else if (e.getStateChange() == ItemEvent.DESELECTED) {
walletWindow.setVisible(false);
}
}
}
);
@ -211,15 +237,20 @@ public class ToolBar extends JFrame {
stateExplorer.setFocusPainted(false);
stateExplorer.setCursor(new Cursor(Cursor.HAND_CURSOR));
stateExplorer.addItemListener(
e -> {
if (e.getStateChange() == ItemEvent.SELECTED) {
SwingUtilities.invokeLater(() -> {
if (stateExplorerWindow == null)
stateExplorerWindow = new StateExplorerWindow(ToolBar.this);
stateExplorerWindow.setVisible(true);
});
} else if (e.getStateChange() == ItemEvent.DESELECTED) {
stateExplorerWindow.setVisible(false);
new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
if (stateExplorerWindow == null)
stateExplorerWindow = new StateExplorerWindow(ToolBar.this);
stateExplorerWindow.setVisible(true);
}
});
} else if (e.getStateChange() == ItemEvent.DESELECTED) {
stateExplorerWindow.setVisible(false);
}
}
}
);
@ -237,6 +268,10 @@ public class ToolBar extends JFrame {
}
public static void main(String args[]) {
SwingUtilities.invokeLater(() -> new ToolBar().setVisible(true));
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new ToolBar().setVisible(true);
}
});
}
}
}