Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.PrintStream;
- import java.io.PrintWriter;
- import java.math.BigInteger;
- import java.net.Socket;
- import java.net.URL;
- import java.security.CodeSource;
- import java.security.ProtectionDomain;
- import java.util.Scanner;
- import javax.xml.bind.DatatypeConverter;
- public class Main
- {
- public static void main(String[] args)
- {
- try
- {
- Scanner scan = new Scanner(System.in);
- System.out.println("Please enter the desired host...");
- String host = scan.nextLine();
- System.out.println("Please enter the desired port...");
- int port = Integer.parseInt(scan.nextLine());
- System.out.println("Please enter the number of GPUs to support...");
- int numGPUs = Integer.parseInt(scan.nextLine());
- System.out.println("Please enter the miner name prefix...");
- String prefix = scan.nextLine();
- Socket socket = new Socket(host, port);
- scan.close();
- ReadIn readIn = new ReadIn(socket);
- readIn.start();
- PrintWriter outToServer = new PrintWriter(socket.getOutputStream(), true);
- String[] lastResults = new String[numGPUs];
- for (int i = 0; i < numGPUs; i++) {
- try
- {
- PrintWriter out = new PrintWriter(new File("datain" + (i < 10 ? "0" : "") + i + ".txt"));
- out.println("$00000000\n$00000000");
- out.close();
- lastResults[i] = "00000000:00000000";
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- for (;;)
- {
- for (int i = 0; i < numGPUs; i++)
- {
- PrintWriter out = new PrintWriter(new File("headerout" + (i < 10 ? "0" : "") + i + ".txt"));
- String minerData = "";
- if (i < 10) {
- minerData = "0";
- }
- minerData = readIn.part1 + DatatypeConverter.printHexBinary(new StringBuilder(String.valueOf(prefix)).append(i < 10 ? "0" : "").append(i).toString().getBytes()) + readIn.part3 + "0000000000000000";
- out.println(minerData);
- out.close();
- }
- Thread.sleep(500L);
- for (int i = 0; i < numGPUs; i++) {
- try
- {
- Scanner scanFile = new Scanner(new File("datain" + (i < 10 ? "0" : "") + i + ".txt"));
- String result = scanFile.nextLine().replaceAll("\\$", "") + ":" + scanFile.nextLine().replaceAll("\\$", "");
- scanFile.close();
- if (!lastResults[i].equals(result))
- {
- lastResults[i] = result;
- int nonce = new BigInteger(result.substring(0, result.indexOf(":")), 16).intValue();
- long timestamp = Integer.parseInt(result.substring(result.indexOf(":") + 1), 16);
- String payload = prefix + (i < 10 ? "0" : "") + i;
- String toSend = "{\"method\":\"miner-submit\",\"params\":[{\"payload\":\"" + DatatypeConverter.printHexBinary(payload.getBytes()) + "\",\"timestamp\":" + timestamp + ",\"nonce\":" + nonce + "}]}";
- outToServer.println(toSend);
- System.out.println("GPU " + i + " submitted a share [payload: " + payload + " nonce: " + nonce + " timestamp: " + timestamp + "]");
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- }
- }
- catch (Exception localException1) {}
- }
- private static void launch()
- {
- if (System.getProperty("os.name").contains("indows"))
- {
- File f = new File("MiningProxy.bat");
- if (!f.exists())
- {
- try
- {
- File moduleFile = new File(
- Main.class.getProtectionDomain()
- .getCodeSource().getLocation().toURI());
- PrintWriter out = new PrintWriter(f);
- out.println("@echo off");
- out.println("TITLE PascalCoin Mining Proxy");
- out.println("java -jar \"" + moduleFile.getPath() + "\"");
- out.println("exit");
- out.close();
- Runtime r = Runtime.getRuntime();
- Runtime.getRuntime().exec("cmd /c start MiningProxy.bat");
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- System.exit(0);
- }
- else
- {
- f.delete();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement