Skip to content

Instantly share code, notes, and snippets.

@Ale32bit
Last active September 18, 2023 14:30
Show Gist options
  • Save Ale32bit/2978fd3962506a8a943fbcf115084b6b to your computer and use it in GitHub Desktop.
Save Ale32bit/2978fd3962506a8a943fbcf115084b6b to your computer and use it in GitHub Desktop.
Tenebra Staking Node for CC: Tweaked
--[[
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 <private key> [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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment