minor fixes

This commit is contained in:
romanman 2014-10-28 23:25:45 -05:00
parent 561c4f2f86
commit 5f413d0ffb
4 changed files with 64 additions and 61 deletions

View File

@ -142,8 +142,11 @@ public class EthereumImpl implements Ethereum {
public PeerClient getDefaultPeer(){ public PeerClient getDefaultPeer(){
PeerClient peer = WorldManager.getInstance().getActivePeer(); PeerClient peer = WorldManager.getInstance().getActivePeer();
if (peer == null) if (peer == null){
peer = new PeerClient(); peer = new PeerClient();
WorldManager.getInstance().setActivePeer(peer);
}
return peer; return peer;
} }

View File

@ -1,55 +1,55 @@
package org.ethereum.jsontestsuite; package org.ethereum.jsontestsuite;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.nio.file.Files; import java.nio.file.Files;
public class JSONReader { public class JSONReader {
public static String loadJSON(String filename) { public static String loadJSON(String filename) {
// return getFromLocal(filename); // return getFromLocal(filename);
String json = getFromUrl("https://raw.githubusercontent.com/ethereum/tests/develop/" + filename); String json = getFromUrl("https://raw.githubusercontent.com/ethereum/tests/develop/" + filename);
return json == "" ? json = getFromLocal(filename) : json; return json == "" ? json = getFromLocal(filename) : json;
} }
public static String getFromLocal(String filename) { public static String getFromLocal(String filename) {
System.out.println("Loading local file: " + filename); System.out.println("Loading local file: " + filename);
try { try {
URL vmtest = ClassLoader.getSystemResource("jsontestsuite/" + filename); URL vmtest = ClassLoader.getSystemResource("jsontestsuite/" + filename);
File vmTestFile = new File(vmtest.toURI()); File vmTestFile = new File(vmtest.toURI());
return new String(Files.readAllBytes(vmTestFile.toPath())); return new String(Files.readAllBytes(vmTestFile.toPath()));
} catch (URISyntaxException | IOException e) { } catch (URISyntaxException | IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
return ""; return "";
} }
public static String getFromUrl(String urlToRead) { public static String getFromUrl(String urlToRead) {
URL url; URL url;
HttpURLConnection conn; HttpURLConnection conn;
BufferedReader rd; BufferedReader rd;
String line; String line;
String result = ""; String result = "";
try { try {
url = new URL(urlToRead); url = new URL(urlToRead);
conn = (HttpURLConnection) url.openConnection(); conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET"); conn.setRequestMethod("GET");
conn.setConnectTimeout(3000); conn.setConnectTimeout(3000);
rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ((line = rd.readLine()) != null) { while ((line = rd.readLine()) != null) {
result += line; result += line;
} }
rd.close(); rd.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();
} }
return result; return result;
} }
} }

View File

@ -15,7 +15,6 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
/** /**
* www.ethergit.com
* *
* @author: Roman Mandeleil * @author: Roman Mandeleil
* Created on: 15/10/2014 12:34 * Created on: 15/10/2014 12:34

View File

@ -76,12 +76,13 @@ public class ConnectionConsoleWindow extends JFrame implements PeerListener {
Thread t = new Thread() { Thread t = new Thread() {
public void run() { public void run() {
PeerClient clientPeer = UIEthereumManager.ethereum.getDefaultPeer();
clientPeer.setPeerListener(thisConsole); UIEthereumManager.ethereum.connect(SystemProperties.CONFIG.activePeerIP(),
clientPeer.connect(SystemProperties.CONFIG.activePeerIP(), SystemProperties.CONFIG.activePeerPort());
SystemProperties.CONFIG.activePeerPort());
} }
}; };
UIEthereumManager.ethereum.getDefaultPeer().setPeerListener(this);
t.start(); t.start();
} }