Post
Topic
Board Mining software (miners)
Re: Simple CPU startum miner Implementation
by
Dherf
on 25/11/2015, 23:47:10 UTC
Here I post what I have done from now on.
I prefer is someone helps me, like, we make it together, so, to make it simple.
The main objective is that I can learn how a miner work creating one.

the code:


Code:
using System;
using System.IO;
using System.Text;
using System.Net.Sockets;
using System.Security.Cryptography;
namespace BitcoinMiner
{
    class MainClass
    {
        static internal string user, pass, pool, poolPort, id, extraNonce1, extraNonce2;
        static internal TcpClient tcp= new TcpClient();

        public static void Main()
        {
            if (!File.Exists("conf.txt"))
            {
                Console.WriteLine("FILE DI CONFIGURAZIONE MANCANTE!");
                Console.ReadLine();
                return;
            }
            else
                Carica();
            Invia("connessione");
            Console.ReadLine();
        }
        static internal void Carica()
        {
            StreamReader sr = new StreamReader("conf.txt");
            pool = sr.ReadLine();
            poolPort = sr.ReadLine();
            user = sr.ReadLine();
            pass = sr.ReadLine();
            sr.Close();
            ScriviLog("Configurazione caricata correttamente.");
        }
        static internal void Invia(string tipo)
        {
            NetworkStream stream;
            switch (tipo)
            {
                case "connessione":
                    {//TCP non funziona!!!! forse serve il sistema delle richieste HTTP!!!!!!!!!!!!
                        ScriviLog("connessione in corso...");
                        tcp.Connect(pool, Convert.ToInt32(poolPort));
                        stream = tcp.GetStream();
                        byte[] a = Encoding.UTF8.GetBytes("{\"id\": 1, \"method\": \"mining.subscribe\", \"params\": []}\\n");
                        stream.Write(a, 0, a.Length);
                        byte[] d = new byte[tcp.ReceiveBufferSize];
                        stream.Read(d, 0, (int)tcp.ReceiveBufferSize);
                        ScriviLog(Encoding.UTF8.GetString(d));
                        stream.Close();
                        break;
                    }
            }
        }
        static internal void ScriviLog(string log)
        {
            Console.WriteLine("[" + DateTime.Now + "] " + log);
        }
    }
}