Advertisement
Guest User

Main.class

a guest
Jan 27th, 2017
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.29 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.PrintStream;
  3. import java.io.PrintWriter;
  4. import java.math.BigInteger;
  5. import java.net.Socket;
  6. import java.net.URL;
  7. import java.security.CodeSource;
  8. import java.security.ProtectionDomain;
  9. import java.util.Scanner;
  10. import javax.xml.bind.DatatypeConverter;
  11.  
  12. public class Main
  13. {
  14.   public static void main(String[] args)
  15.   {
  16.    
  17.     try
  18.     {
  19.       Scanner scan = new Scanner(System.in);
  20.       System.out.println("Please enter the desired host...");
  21.       String host = scan.nextLine();
  22.       System.out.println("Please enter the desired port...");
  23.       int port = Integer.parseInt(scan.nextLine());
  24.       System.out.println("Please enter the number of GPUs to support...");
  25.       int numGPUs = Integer.parseInt(scan.nextLine());
  26.       System.out.println("Please enter the miner name prefix...");
  27.       String prefix = scan.nextLine();
  28.       Socket socket = new Socket(host, port);
  29.      
  30.       scan.close();
  31.      
  32.       ReadIn readIn = new ReadIn(socket);
  33.       readIn.start();
  34.      
  35.       PrintWriter outToServer = new PrintWriter(socket.getOutputStream(), true);
  36.      
  37.       String[] lastResults = new String[numGPUs];
  38.       for (int i = 0; i < numGPUs; i++) {
  39.         try
  40.         {
  41.           PrintWriter out = new PrintWriter(new File("datain" + (i < 10 ? "0" : "") + i + ".txt"));
  42.           out.println("$00000000\n$00000000");
  43.           out.close();
  44.           lastResults[i] = "00000000:00000000";
  45.         }
  46.         catch (Exception e)
  47.         {
  48.           e.printStackTrace();
  49.         }
  50.       }
  51.       for (;;)
  52.       {
  53.         for (int i = 0; i < numGPUs; i++)
  54.         {
  55.           PrintWriter out = new PrintWriter(new File("headerout" + (i < 10 ? "0" : "") + i + ".txt"));
  56.           String minerData = "";
  57.           if (i < 10) {
  58.             minerData = "0";
  59.           }
  60.           minerData = readIn.part1 + DatatypeConverter.printHexBinary(new StringBuilder(String.valueOf(prefix)).append(i < 10 ? "0" : "").append(i).toString().getBytes()) + readIn.part3 + "0000000000000000";
  61.           out.println(minerData);
  62.           out.close();
  63.         }
  64.         Thread.sleep(500L);
  65.         for (int i = 0; i < numGPUs; i++) {
  66.           try
  67.           {
  68.             Scanner scanFile = new Scanner(new File("datain" + (i < 10 ? "0" : "") + i + ".txt"));
  69.             String result = scanFile.nextLine().replaceAll("\\$", "") + ":" + scanFile.nextLine().replaceAll("\\$", "");
  70.             scanFile.close();
  71.             if (!lastResults[i].equals(result))
  72.             {
  73.               lastResults[i] = result;
  74.               int nonce = new BigInteger(result.substring(0, result.indexOf(":")), 16).intValue();
  75.               long timestamp = Integer.parseInt(result.substring(result.indexOf(":") + 1), 16);
  76.               String payload = prefix + (i < 10 ? "0" : "") + i;
  77.               String toSend = "{\"method\":\"miner-submit\",\"params\":[{\"payload\":\"" + DatatypeConverter.printHexBinary(payload.getBytes()) + "\",\"timestamp\":" + timestamp + ",\"nonce\":" + nonce + "}]}";
  78.               outToServer.println(toSend);
  79.               System.out.println("GPU " + i + " submitted a share [payload: " + payload + " nonce: " + nonce + " timestamp: " + timestamp + "]");
  80.             }
  81.           }
  82.           catch (Exception e)
  83.           {
  84.             e.printStackTrace();
  85.           }
  86.         }
  87.       }
  88.     }
  89.     catch (Exception localException1) {}
  90.   }
  91.  
  92.   private static void launch()
  93.   {
  94.     if (System.getProperty("os.name").contains("indows"))
  95.     {
  96.       File f = new File("MiningProxy.bat");
  97.       if (!f.exists())
  98.       {
  99.         try
  100.         {
  101.           File moduleFile = new File(
  102.             Main.class.getProtectionDomain()
  103.             .getCodeSource().getLocation().toURI());
  104.           PrintWriter out = new PrintWriter(f);
  105.           out.println("@echo off");
  106.           out.println("TITLE PascalCoin Mining Proxy");
  107.           out.println("java -jar \"" + moduleFile.getPath() + "\"");
  108.           out.println("exit");
  109.           out.close();
  110.           Runtime r = Runtime.getRuntime();
  111.           Runtime.getRuntime().exec("cmd /c start MiningProxy.bat");
  112.         }
  113.         catch (Exception e)
  114.         {
  115.           e.printStackTrace();
  116.         }
  117.         System.exit(0);
  118.       }
  119.       else
  120.       {
  121.         f.delete();
  122.       }
  123.     }
  124.   }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement