Advertisement
Ewgeniy

Mime

Jul 14th, 2024 (edited)
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.86 KB | None | 0 0
  1. local component = require("component")
  2. local sha = require("sha2")
  3. local inet = component.internet
  4.  
  5. local username = "HappyWindinkg" -- Ник кошелька Duino Coin
  6.  
  7. while true do
  8.     local socket, reason = inet.connect("149.91.88.18", 6004) -- IP duino-пула - https://server.duinocoin.com/getPool
  9.     if not socket then
  10.         print("Connection failed: " .. reason)
  11.         os.sleep(10) -- Ждем перед повторной попыткой
  12.         goto continue
  13.     end
  14.  
  15.     print("Asking for a new job for user: " .. username)
  16.     socket.write("JOB," .. username .. ",ESP32") -- ESP32 сложность майнинга
  17.     os.sleep(3)
  18.     local job = socket.read()
  19.     if not job then
  20.         print("Failed to read job")
  21.         socket.close()
  22.         os.sleep(10)
  23.         goto continue
  24.     end
  25.  
  26.     print("Raw job received: " .. job)
  27.    
  28.     local newjob = job:sub(4)
  29.     local t = {}
  30.     for s in newjob:gmatch("([^,]+)") do
  31.         t[#t + 1] = s
  32.     end
  33.  
  34.     if #t < 3 then
  35.         print("Invalid job received: " .. job)
  36.         socket.close()
  37.         os.sleep(10)
  38.         goto continue
  39.     end
  40.  
  41.     local lastBlockHash, expectedHash, difficulty = table.unpack(t)
  42.     print("Job received: " .. lastBlockHash .. " " .. expectedHash .. " " .. difficulty)
  43.  
  44.     local range = 100 * tonumber(difficulty) + 1
  45.     local found = false
  46.     for result = 0, range do
  47.         local ducos1 = sha.sha1(lastBlockHash .. tostring(result))
  48.         if ducos1 == expectedHash then
  49.             local send = tostring(result) .. "," .. "LuaMiner 1.0"
  50.             socket.write(send)
  51.             local response = socket.read()
  52.             print("Response: " .. response)
  53.             found = true
  54.             break
  55.         end
  56.     end
  57.  
  58.     if not found then
  59.         print("No valid hash found")
  60.     end
  61.  
  62.     socket.close()
  63.     ::continue::
  64. end
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement