java - Crypto Miner using - Stratum Mining Protocol -
i newbie , trying write crypto miner in java .. using stratum protocol .. below java code .. not sure how mining job notification?
1) connected pool using - mining.subscribe 2) , requested mining authorization - mining.authorize
then how notify response - can please help.
stratum protocol says *"server start sending notifications mining jobs server sends 1 job almost instantly after subscription. small engineering note: there's reason why first job not included directly in subscription response - miner need handle 1 response type in 2 different way; firstly subscription response , standalone notification. hook job processing json-rpc notification sounds bit better me."*
static boolean connect2pool(string server, int port) { string message1 = "{\"id\":1,\"method\":\"mining.subscribe\",\"params\":[]}"; 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 connect " + address.tostring() + " on port " + port + "."); // connect socket socket = new socket(); socket.connect(new inetsocketaddress(server, port)); = 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 response: " + 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 response: " + json.tostring()); result=true; } is.close(); os.close(); socket.close(); } catch (ioexception e) { system.out.println(e.getmessage()); system.out.println("not able connect 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
Comments
Post a Comment