Bitcoin pool connection

I am programming a bitcoin miner that works in a pool using the stratum protocol (see the documentation here .

The stratum protocol uses JSON-RPC 2.0 as the encoding and according to the JSON-RPC 2.0 specification (specification here ) I have to use sockets to create a connection to the pool.

My problem is that I can't seem to get a response from the pool. JSON-RPC 2.0 states that for every request object that I send, I should get a response.

Here is my code:

public static void main(String[] args) 
{
    connectToPool("stratum.slushpool.com", 3333);
}    
static void connectToPool(String host, int port)
{
    try
    {
        InetAddress address = InetAddress.getByName(host);
        out.println("Atempting to connect to " + address.toString() + " on port " + port + ".");

        socket = new Socket(address, port);
        String message1 = "{\"jsonrpc\" : \"2.0\", \"id\": 1, \"method\": \"mining.subscribe\", \"params\": []}";

        PrintWriter output = new PrintWriter(socket.getOutputStream(), true);
        BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));

        output.write((message1 + "\\n"));
        out.println(input.readLine());//Hangs here.
    }
    catch (IOException e) 
    {
        out.println(e.getMessage());
        out.println("Error. Can't connect to Pool.");
        System.exit(-2);
    }
}
+4
source share
1 answer

. -, JSON . :

String message1 = "{\"jsonrpc\" : \"2.0\", \"id\": 1, \"method\": \"mining.subscribe\", \"params\": []}";

:

String message1 = "{\"id\":1,\"method\":\"mining.subscribe\",\"params\":[]}";
+2

Source: https://habr.com/ru/post/1675462/


All Articles