java stratum не работает
Я пытаюсь написать криптовалюту Java (я знаю, что это не будет самым быстрым)
Кажется, у меня все нормально, но у меня проблемы с получением первой работы. согласно спецификации страты (насколько я понимаю) https://slushpool.com/help/manual/stratum-protocol Я должен получить первую работу почти сразу.
package network;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import org.json.JSONException;
import org.json.JSONObject;
public class stratum {
public static void main(String[] args)
{
connect2Pool("stratum.slushpool.com", 3333);
}
static boolean connect2Pool(String SERVER, int PORT)
{
String message1 = "{\"id\":1,\"method\":\"mining.subscribe\",\"params\":[]}";
String PASSWORD = "thisisok";
String USERNAME = "n1ghtowl";
String WORKER = "worker1";
String authorizemessage = "{\"params\": [\"" + USERNAME + "." + WORKER + "\", \"" + PASSWORD + "\"], \"id\": 2, \"method\": \"mining.authorize\"}";
boolean result = false;
DataInputStream is;
DataOutputStream os;
try
{
InetAddress address = InetAddress.getByName(SERVER);
System.out.println("Atempting to connect to " + address.toString() + " on port " + PORT + ".");
// connect
Socket socket = new Socket();
socket.connect(new InetSocketAddress(SERVER, PORT));
is = new DataInputStream(socket.getInputStream());
os = new DataOutputStream(socket.getOutputStream());
PrintWriter pw = new PrintWriter(os);
pw.println(message1); //connect
pw.flush();
//read response
BufferedReader in = new BufferedReader(new InputStreamReader(is));
JSONObject json = new JSONObject(in.readLine());
if(!json.has("result")) {
System.out.println("no reult");
result=false;
}else {
System.out.println("json response1: " + json.toString());
result=true;
}
pw.println (authorizemessage); //authorize
pw.flush();
//read response
in = new BufferedReader(new InputStreamReader(is));
json = new JSONObject(in.readLine());
if(!json.has("result")) {
System.out.println("no reult");
result=false;
}else {
System.out.println("json response2: " + json.toString());
result=true;
}
// trying to get first job
json = new JSONObject(in.readLine());
if(!json.has("result")) {
System.out.println("missing job");
result=false;
}else {
System.out.println("json response3: " + json.toString());
result=true;
}
is.close();
os.close();
socket.close();
} catch (IOException e) {
System.out.println(e.getMessage());
System.out.println("Not able to connect to pool");
System.exit(-2);
} catch (JSONException e) {
System.out.println(e.getMessage());
System.out.println("JSON not good.");
System.exit(-2);
}
return result;
} //end of connect2Pool
}