require 'socket'
require 'digest'
require 'net/http'
require 'json'
require 'time'
require 'colorize'
username = "revox"
minerId = "None"
$VERBOSE = nil
puts("\n ‖ Minimal DUCO-S1 Ruby Miner")
puts(" ‖ Duino-Coin community 2020-2022")
puts(" ‖ https://github.com/revoxhere/duino-coin\n\n")
url = 'https://raw.githubusercontent.com/revoxhere/duino-coin/gh-pages/serverip.txt'
uri = URI(url)
response = Net::HTTP.get(uri)
response = response.split("\n")
serverip = response[0]
serverport = response[1]
sharecount = 0
s = TCPSocket.open(serverip, serverport)
SERVER_VER = s.gets(3)
puts(" net ".colorize(:color => :white, :background => :blue) + " Connected".colorize(:color => :yellow) + " to the master Duino-Coin server ("+ SERVER_VER+ ")")
puts(" cpu ".colorize(:color => :white, :background => :yellow) + " Mining thread is starting".colorize(:color => :yellow) + " using DUCO-S1 algorithm")
loop do
s.puts("JOB,"+String(username)+",MEDIUM,")
job = s.read(87)
job = job.split(',')
difficulty = job[2]
timeStart = Process.clock_gettime(Process::CLOCK_MONOTONIC)
for result in 0..100 * Integer(difficulty) + 1 do
sha1 = Digest::SHA1.hexdigest String(String(job[0])+String(result))
if sha1 == String(job[1])
timeStop = Process.clock_gettime(Process::CLOCK_MONOTONIC)
timeDiff = timeStop - timeStart
hashrate = result / timeDiff
s.write(String(result) + "," + String(hashrate) + ",Minimal Ruby Miner (DUCO-S1)," + String(minerId))
SHAREFEED = s.read(4)
sharecount += 1
if SHAREFEED == "GOOD" or SHAREFEED == "BLOCK"
puts(" cpu ".colorize(:color => :white, :background => :yellow) + " Accepted".colorize(:color => :green) + " share #" + String(sharecount) + ", speed: " + String(Integer(hashrate / 1000)) + "kH/s @ diff " + String(difficulty))
break
if SHAREFEED == "INVU"
puts "Invalid username!"
exit
if SHAREFEED == "BAD"
puts(" cpu ".colorize(:color => :white, :background => :yellow) + " Rejected".colorize(:color => :red) + " share #" + String(sharecount) + ", speed: " + String(Integer(hashrate / 1000)) + "kH/s @ diff " + String(difficulty))
break
end
end
end
end
end
end