Tenebra Staking Node for CC: Tweaked

September 18, 2023 ยท View on GitHub

--[[ Tenebra Staking Node for CC: Tweaked by AlexDevs ]]--

local args = {...}

local defaultSyncNode = "https://tenebra.lil.gay" local privateKey = args[1] local syncNode = args[2] or defaultSyncNode

if not privateKey then print("Usage: tenebra [sync node]") return end

local function getWsUrl() local h, err = http.post(syncNode .. "/ws/start", '{"is_sussy": true}')

if not h then
	error(err, 0)
end

local result = textutils.unserializeJSON(h.readAll())
h.close()

return result.url

end

local ws local function main() print("Connecting to", syncNode)

local url = getWsUrl()
ws = http.websocket(url)
print("Connected to", syncNode)

local function submitBlock()
	print("Submitting block with a totally random nonce")
	ws.send(textutils.serializeJSON({
		id = 1,
		type = "submit_block",
		nonce = "amogus",
	}))
end

ws.send(textutils.serializeJSON({
	id = 2,
	type = "login",
	privatekey = privateKey
}))

ws.send(textutils.serializeJSON({
	id = 3,
	type = "subscribe",
	event = "ownValidators",
}))

ws.send(textutils.serializeJSON({
	id = 4,
	type = "subscribe",
	event = "blocks",
}))

while true do
	local data = ws.receive()
	
	data = textutils.unserializeJSON(data)
	
	if data.type == "hello" then
		print("Received hello block")
	elseif data.type == "event" then
		if data.event == "block" then
			print("Received new block", data.block.hash)
		elseif data.event == "validator" then
			submitBlock()
		end
	elseif data.ok and data.isGuest ~= nil and data.address then
		print("Authed as", data.address.address)
		submitBlock()
	end
end

end

while true do local ok, err = pcall(main) if ws and ws.close then pcall(ws.close) end

if not ok then
	printError(err)
	if err:find("Terminated") then
		print("Goodbye")
		break
	end
end	

end