Update kstwallet.lua

This commit is contained in:
Ale32bit 2016-03-13 14:12:25 +01:00
parent e3ac5e1bfc
commit e0eab0cb3b

View file

@ -1,21 +1,21 @@
--[[----------------------------------------------- --[[-----------------------------------------------
| KristWallet by cossacksson | | KristWallet by 3d6 |
--------------------------------------------------- ---------------------------------------------------
| This is the reference wallet for Krist. | | This is the reference wallet for Krist. |
| It is the basic definition of a functional | | It is the basic definition of a functional |
| Krist program, although it is not as old as the | | Krist program, although it is not as old as the |
| network (we used to just use raw API calls). | | network (we used to just use raw API calls). |
--------------------------------------------------- ---------------------------------------------------
| Every last bit of this program (except, of | /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\
| course, SHA256 itself) was made entirely by | / \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/
| cossacksson and is "free software" and whatnot. | ---------------------------------------------------
| Do whatever you want with it, but if you make | | Do whatever you want with this, but if you make |
| it interact with a currency or network other | | it interact with a currency or network other |
| than Krist, please give me credit. Thanks <3 | | than Krist, please give me credit. Thanks <3 |
--------------------------------------------------- ---------------------------------------------------
| This wallet will NEVER save passwords anywhere. |]]local --[[pretty sneaky, huh?]] | This wallet will NEVER save passwords anywhere. |]]local
-----------------------------------------------]]-- -----------------------------------------------]]--
version = 11 version = 14
local latest = 0 local latest = 0
local balance = 0 local balance = 0
local balance2 = 0 local balance2 = 0
@ -45,9 +45,33 @@ local maxspace = ""
local ar = 0 local ar = 0
local amt = 0 local amt = 0
local availability = 0 local availability = 0
local function split(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t={} ; i=1
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
t[i] = str
i = i + 1
end
return t
end
local function readURL(url)
local resp = http.get(url)
if not resp then
log("Could not reach "..url)
error("Error connecting to server")
panic()
end
local content = resp.readAll()
resp.close()
return content
end
local function boot() local function boot()
checkdir() for i=1,2 do checkdir() end
checkdir()
print("Starting KristWallet v"..tostring(version)) print("Starting KristWallet v"..tostring(version))
log("Started KristWallet v"..tostring(version)) log("Started KristWallet v"..tostring(version))
update() update()
@ -71,13 +95,13 @@ local function boot()
end end
end end
function update() function update()
latest = tonumber(http.get(readconfig("versionserver")).readAll()) latest = tonumber(readURL(readconfig("versionserver")))
if latest > version then if latest > version then
print("An update is available!") print("An update is available!")
log("Discovered update") log("Discovered update")
if readconfig("autoupdate") then if readconfig("autoupdate") then
local me = fs.open(fs.getName(shell.getRunningProgram()),"w") local me = fs.open(fs.getName(shell.getRunningProgram()),"w")
local nextversion = http.get(readconfig("updateserver")).readAll() local nextversion = readURL(readconfig("updateserver"))
print("Installed update. Run this program again to start v"..latest..".") print("Installed update. Run this program again to start v"..latest..".")
me.write(nextversion) me.write(nextversion)
me.close() me.close()
@ -348,33 +372,21 @@ end
function checkdir() function checkdir()
if fs.isDir("kst") then if fs.isDir("kst") then
math.randomseed(os.time()) math.randomseed(os.time())
checkfile("log_wallet",[[-----KRISTWALLET LOG FILE----- checkfile("log_wallet","-----KRISTWALLET LOG FILE-----")
--If this file becomes excessively large, you checkfile("enabled","true") --Disabling this just makes KristWallet refuse to start.
--should save a copy to a disk and stow it away.
--You should not destroy logs - they may help any
--detectives recover stolen krist, or at least find
--the perpetrator! Happy Kristmas! -cossacksson.
---------------------------------------------------]])
checkfile("enabled","true") --Disabling this just makes KristWallet refuse to start. No danger of Krist loss.
checkfile("sweepv1","true") checkfile("sweepv1","true")
checkfile("appendhashes","true") --Disabling this makes it possible to use KristWallet with extremely old addresses. I doubt anyone but me ever will. checkfile("appendhashes","true") --Disabling this makes it possible to use KristWallet with extremely old addresses.
checkfile("autoupdate","true") checkfile("autoupdate","true")
checkfile("whitelisted","false") checkfile("whitelisted","false")
checkfile("rebootonexit","false") checkfile("rebootonexit","false")
checkfile("locksettings","false") checkfile("autologin","false")
checkfile("usev1address","false") checkfile("keyAL",sha256(""))
checkfile("autologin","false") --Don't use autologin. Admittedly, it was a very stupid and dangerous idea. If you want a wallet exclusive to your address, use whitelist instead. checkfile("keyLV",sha256(math.random(1000000)..os.time())) --This is where the local vault's krist is stored. DO NOT DESTROY!
checkfile("keyAL",sha256("")) --This is meaningless gibberish
checkfile("keyLV",sha256(math.random(10)..os.time())) --This is where the local vault's krist is stored. DO NOT DESTROY EVER.
checkfile("versionserver","https://raw.githubusercontent.com/BTCTaras/kristwallet/master/staticapi/version") checkfile("versionserver","https://raw.githubusercontent.com/BTCTaras/kristwallet/master/staticapi/version")
checkfile("updateserver","https://raw.githubusercontent.com/BTCTaras/kristwallet/master/kristwallet") checkfile("updateserver","https://raw.githubusercontent.com/BTCTaras/kristwallet/master/kristwallet")
checkfile("syncnode","http://ceriat.net/krist/") --A trusted A-class node to push transactions to. checkfile("syncnode","http://krist.ceriat.net/")
checkfile("whitelist",[[kg5dc1lzo0 checkfile("whitelist","")
a5dfb396d3]]) checkfile("blacklist","")
checkfile("blacklist",[[ke3kjplzsz #Blank string (prevent accidents)
kojddz0uzw #RV main
8c11bb0d2d #Ransom virus
]])
else else
fs.makeDir("kst") fs.makeDir("kst")
end end
@ -419,6 +431,7 @@ function openwallet()
password = readconfig("keyAL") password = readconfig("keyAL")
else else
password = read("*") password = read("*")
if password == "" then term.setCursorPos(16,6) password = read("*") end
if readconfig("appendhashes") then password = sha256("KRISTWALLET"..password) end if readconfig("appendhashes") then password = sha256("KRISTWALLET"..password) end
end end
term.clear() term.clear()
@ -430,12 +443,10 @@ function openwallet()
log("Derived address: "..addressv1) log("Derived address: "..addressv1)
address = makev2address(masterkey) address = makev2address(masterkey)
log("Derived address: "..address) log("Derived address: "..address)
balance = tonumber(http.get(readconfig("syncnode").."?getbalance="..addressv1).readAll()) balance = tonumber(readURL(readconfig("syncnode").."?getbalance="..addressv1))
if balance > 0 and readconfig("sweepv1") then local transaction = http.get(readconfig("syncnode").."?pushtx&q="..address.."&pkey="..masterkey.."&amt="..balance).readAll() log("Swept hex address") end if balance > 0 and readconfig("sweepv1") then local transaction = readURL(readconfig("syncnode").."?pushtx&q="..address.."&pkey="..masterkey.."&amt="..balance); log("Swept hex address") end
balance = tonumber(http.get(readconfig("syncnode").."?getbalance="..address).readAll()) balance = tonumber(readURL(readconfig("syncnode").."?getbalance="..address))
if balance >= 100000 then log("Woah! There's a small fortune here!") elseif balance > 0 then log("There is some krist here!") end if balance >= 100000 then log("Woah! There's a small fortune here!") elseif balance > 0 then log("There is some krist here!") end
if balance == 420 then log("This is such a blazing balance") end
if balance == 42 then log("Hey, Chuck") end
if readconfig("whitelisted") then if readconfig("whitelisted") then
local whitelist = readconfig("whitelist") local whitelist = readconfig("whitelist")
if string.find(whitelist, address) == nil then if string.find(whitelist, address) == nil then
@ -458,7 +469,6 @@ function openwallet()
os.sleep(3) os.sleep(3)
end end
end end
if readconfig("usev1address") then address = addressv1 end
addresslv = makev2address(readconfig("keyLV")) addresslv = makev2address(readconfig("keyLV"))
log("Loaded local vault") log("Loaded local vault")
end end
@ -603,8 +613,33 @@ local function postgraphic(px,py,id)
term.write(".kst") term.write(".kst")
elseif id == 8 then elseif id == 8 then
--Name sent --Name sent
term.setCursorPos(px+1,py+3)
term.setBackgroundColor(16384)
term.setTextColor(4)
term.write(".kst")
term.setTextColor(16384)
term.setBackgroundColor(1)
term.setCursorPos(px+2,py)
term.write("/\\")
term.setCursorPos(px+2,py+1)
term.write("||")
elseif id == 9 then elseif id == 9 then
--Name received --Name received
term.setCursorPos(px+1,py+3)
term.setBackgroundColor(16384)
term.setTextColor(4)
term.write(".kst")
term.setTextColor(8192)
term.setBackgroundColor(1)
term.setCursorPos(px+1,py)
term.write("||")
term.setCursorPos(px+1,py+1)
term.write("\\/")
term.setTextColor(16384)
term.setCursorPos(px+3,py)
term.write("/\\")
term.setCursorPos(px+3,py+1)
term.write("||")
end end
end end
function wallet() function wallet()
@ -614,7 +649,7 @@ function wallet()
if gui == 1 and xPos >= 3 and xPos <= 14 then if gui == 1 and xPos >= 3 and xPos <= 14 then
if yPos == 5 then if yPos == 5 then
page = 1 page = 1
balance = tonumber(http.get(readconfig("syncnode").."?getbalance="..address).readAll()) balance = tonumber(readURL(readconfig("syncnode").."?getbalance="..address))
end end
if yPos == 7 then if yPos == 7 then
page = 2 page = 2
@ -623,7 +658,7 @@ function wallet()
end end
if yPos == 9 then if yPos == 9 then
page = 3 page = 3
balance = tonumber(http.get(readconfig("syncnode").."?getbalance="..address).readAll()) balance = tonumber(readURL(readconfig("syncnode").."?getbalance="..address))
end end
if yPos == 11 then if yPos == 11 then
page = 8 page = 8
@ -642,10 +677,18 @@ function wallet()
page = 0 page = 0
end end
end end
local lexm = http.get(readconfig("syncnode").."?listnames="..address)
local lem = false
local lexmm
if lexm.readAll then
lem = true
lexmm = lexm.readAll()
end
if page == 1 then if page == 1 then
balance = tonumber(http.get(readconfig("syncnode").."?getbalance="..address).readAll()) balance = tonumber(readURL(readconfig("syncnode").."?getbalance="..address))
if (yPos-7)%5 == 0 and yPos >= 7 and xPos >= 26 and xPos <= 35 then if (yPos-7)%5 == 0 and yPos >= 7 and xPos >= 26 and xPos <= 35 then
subject = string.sub(http.get(readconfig("syncnode").."?listtx="..address.."&overview").readAll(),13+(31*((yPos-7)/5)),22+(31*((yPos-7)/5))) subject = string.sub(readURL(readconfig("syncnode").."?listtx="..address.."&overview"),13+(31*((yPos-7)/5)),22+(31*((yPos-7)/5)))
if string.len(subject) == 10 and subject ~= "N/A(Mined)" and subject ~= "N/A(Names)" then if string.len(subject) == 10 and subject ~= "N/A(Mined)" and subject ~= "N/A(Names)" then
page = 2 page = 2
end end
@ -685,8 +728,8 @@ function wallet()
log("Read recipient for transfer") log("Read recipient for transfer")
local amount = read() local amount = read()
log("Read amount for transfer") log("Read amount for transfer")
local transaction = http.get(readconfig("syncnode").."?pushtx2&q="..recipient.."&pkey="..masterkey.."&amt="..amount).readAll() local transaction = readURL(readconfig("syncnode").."?pushtx2&q="..recipient.."&pkey="..masterkey.."&amt="..amount)
balance = tonumber(http.get(readconfig("syncnode").."?getbalance="..address).readAll()) balance = tonumber(readURL(readconfig("syncnode").."?getbalance="..address))
log("Attempting to send "..amount.." KST to "..recipient) log("Attempting to send "..amount.." KST to "..recipient)
term.setCursorPos(19,8) term.setCursorPos(19,8)
if transaction == "Success" then if transaction == "Success" then
@ -721,9 +764,6 @@ function wallet()
if yPos == 4 and xPos >= 19 and xPos <= 31 then if yPos == 4 and xPos >= 19 and xPos <= 31 then
page = 10 page = 10
end end
if yPos == 5 and xPos >= 19 and xPos <= 31 then
--page = 11
end
if yPos == 3 and xPos >= 35 and xPos <= 48 then if yPos == 3 and xPos >= 35 and xPos <= 48 then
page = 6 page = 6
end end
@ -757,27 +797,32 @@ function wallet()
end end
end end
elseif page == 15 then elseif page == 15 then
if yPos == 1 and xPos >= 46 then
page = 16 local function isEdit(xpo)
elseif yPos >= 3 and xPos >= 39 and xPos <= 42 then return xpo >= 39 and xpo <= 42
page = 17 end
local listofnames = http.get(readconfig("syncnode").."?listnames="..address).readAll() local function isSend(xpo)
local nameclicked = yPos - 3 return xpo >= 44 and xpo <= 47
if nameclicked > 0 then repeat end
listofnames = listofnames:sub(1+listofnames:find(";"))
nameclicked = nameclicked - 1 if xPos and yPos then
until nameclicked == 0 end local listofnames = split(lexmm, ";")
subject = listofnames:sub(0,listofnames:find(";")-1) if yPos == 1 and xPos >= 46 then
elseif yPos >= 3 and xPos >= 44 and xPos <= 47 then page = 16
page = 18 elseif lem and yPos >= 3 and isEdit(xPos) then
local listofnames = http.get(readconfig("syncnode").."?listnames="..address).readAll() if listofnames[yPos - 3] then
local nameclicked = yPos - 3 page = 17
if nameclicked > 0 then repeat local nameclicked = yPos - 3
listofnames = listofnames:sub(1+listofnames:find(";")) subject = listofnames[nameclicked]
nameclicked = nameclicked - 1 end
until nameclicked == 0 end elseif lem and yPos >= 3 and isSend(xPos) then
subject = listofnames:sub(0,listofnames:find(";")-1) if listofnames[yPos - 3] then
end page = 18
local nameclicked = yPos - 3
subject = listofnames[nameclicked]
end
end
end
elseif page == 8 then elseif page == 8 then
if yPos == 3 and xPos >= 19 and xPos <= 30 then if yPos == 3 and xPos >= 19 and xPos <= 30 then
page = 9 page = 9
@ -785,6 +830,9 @@ function wallet()
if yPos == 3 and xPos >= 35 and xPos <= 47 then if yPos == 3 and xPos >= 35 and xPos <= 47 then
page = 16 page = 16
end end
if yPos == 4 and xPos >= 35 and xPos <= 47 then
--page = 18
end
if yPos == 4 and xPos >= 19 and xPos <= 29 then if yPos == 4 and xPos >= 19 and xPos <= 29 then
page = 13 page = 13
end end
@ -795,14 +843,13 @@ function wallet()
term.setCursorPos(30,5) term.setCursorPos(30,5)
maxspace = read():lower() maxspace = read():lower()
term.setCursorPos(19,7) term.setCursorPos(19,7)
pagespace = http.get(readconfig("syncnode").."?name_transfer&pkey="..masterkey.."&name="..subject.."&q="..maxspace).readAll() pagespace = readURL(readconfig("syncnode").."?name_transfer&pkey="..masterkey.."&name="..subject.."&q="..maxspace)
if pagespace == "Success" then if pagespace == "Success" then
end end
term.write("Transfer request broadcasted") term.write("Name transferred")
log("Tried sending a name to "..maxspace) log("Tried sending a name to "..maxspace)
os.sleep(3) os.sleep(3)
page = 15 page = 15
--im drunk on water right now
end end
elseif page == 16 then elseif page == 16 then
if yPos == 4 and xPos >= 25 then if yPos == 4 and xPos >= 25 then
@ -816,7 +863,7 @@ function wallet()
if name == "a" or name == "name" or name == "id" or name == "owner" or name == "registered" or name == "updated" or name == "expires" or name == "unpaid" then if name == "a" or name == "name" or name == "id" or name == "owner" or name == "registered" or name == "updated" or name == "expires" or name == "unpaid" then
availability = 0 availability = 0
else else
availability = tonumber(http.get(readconfig("syncnode").."?name_check="..name).readAll()) availability = tonumber(readURL(readconfig("syncnode").."?name_check="..name))
log("Checked "..name..".kst for availability ("..availability..")") log("Checked "..name..".kst for availability ("..availability..")")
term.setCursorPos(19,7) term.setCursorPos(19,7)
if availability then if availability then
@ -832,7 +879,7 @@ function wallet()
end end
elseif yPos == 7 and xPos >= 30 and xPos <= 39 and availability == 1 and balance >= 500 then elseif yPos == 7 and xPos >= 30 and xPos <= 39 and availability == 1 and balance >= 500 then
availability = 2 availability = 2
local k = http.get(readconfig("syncnode").."?name_new&pkey="..masterkey.."&name="..name).readAll() local k = readURL(readconfig("syncnode").."?name_new&pkey="..masterkey.."&name="..name)
end end
elseif page == 17 then elseif page == 17 then
if yPos == 5 and xPos >= 25 then if yPos == 5 and xPos >= 25 then
@ -842,10 +889,10 @@ function wallet()
zone = read():gsub("http://","") zone = read():gsub("http://","")
term.setCursorPos(25,5) term.setCursorPos(25,5)
term.write("Please wait... ") term.write("Please wait... ")
local sevenminutesleftuntilmaystartsfuckihavetoreleasethisnow = http.get(readconfig("syncnode").."?name_update&pkey="..masterkey.."&name="..subject.."&ar="..zone).readAll() local sevenminutesleftuntilmaystartsfuckihavetoreleasethisnow = readURL(readconfig("syncnode").."?name_update&pkey="..masterkey.."&name="..subject.."&ar="..zone)
elseif yPos == 7 and xPos >= 30 and xPos <= 39 and availability == 1 and balance >= 500 then elseif yPos == 7 and xPos >= 30 and xPos <= 39 and availability == 1 and balance >= 500 then
availability = 2 availability = 2
local k = http.get(readconfig("syncnode").."?name_new&pkey="..masterkey.."&name="..name).readAll() local k = readURL(readconfig("syncnode").."?name_new&pkey="..masterkey.."&name="..name)
end end
elseif page == 9 then elseif page == 9 then
if yPos == 4 and xPos >= 30 then if yPos == 4 and xPos >= 30 then
@ -858,7 +905,7 @@ function wallet()
if string.len(doublekey) > 0 then if string.len(doublekey) > 0 then
doublekey = sha256(masterkey.."-"..sha256(doublekey)) doublekey = sha256(masterkey.."-"..sha256(doublekey))
addressdv = makev2address(doublekey) addressdv = makev2address(doublekey)
balance2 = tonumber(http.get(readconfig("syncnode").."?getbalance="..addressdv).readAll()) balance2 = tonumber(readURL(readconfig("syncnode").."?getbalance="..addressdv))
log("Derived double vault "..addressdv) log("Derived double vault "..addressdv)
else else
addressdv = "" addressdv = ""
@ -881,9 +928,9 @@ function wallet()
if yPos == 6 and xPos >= 25 and xPos <= 33 then if yPos == 6 and xPos >= 25 and xPos <= 33 then
if tonumber(amt) > 0 and string.len(doublekey) > 0 then if tonumber(amt) > 0 and string.len(doublekey) > 0 then
if tonumber(amt) <= balance then if tonumber(amt) <= balance then
local transaction = http.get(readconfig("syncnode").."?pushtx2&q="..addressdv.."&pkey="..masterkey.."&amt="..tonumber(amt)).readAll() local transaction = readURL(readconfig("syncnode").."?pushtx2&q="..addressdv.."&pkey="..masterkey.."&amt="..tonumber(amt))
balance = tonumber(http.get(readconfig("syncnode").."?getbalance="..address).readAll()) balance = tonumber(readURL(readconfig("syncnode").."?getbalance="..address))
balance2 = tonumber(http.get(readconfig("syncnode").."?getbalance="..addressdv).readAll()) balance2 = tonumber(readURL(readconfig("syncnode").."?getbalance="..addressdv))
log("Put "..amt.." KST in a double vault") log("Put "..amt.." KST in a double vault")
end end
end end
@ -891,9 +938,9 @@ function wallet()
if yPos == 6 and xPos >= 35 and xPos <= 44 then if yPos == 6 and xPos >= 35 and xPos <= 44 then
if tonumber(amt) > 0 and string.len(doublekey) > 0 then if tonumber(amt) > 0 and string.len(doublekey) > 0 then
if tonumber(amt) <= balance2 then if tonumber(amt) <= balance2 then
local transaction = http.get(readconfig("syncnode").."?pushtx2&q="..address.."&pkey="..doublekey.."&amt="..tonumber(amt)).readAll() local transaction = readURL(readconfig("syncnode").."?pushtx2&q="..address.."&pkey="..doublekey.."&amt="..tonumber(amt))
balance = tonumber(http.get(readconfig("syncnode").."?getbalance="..address).readAll()) balance = tonumber(readURL(readconfig("syncnode").."?getbalance="..address))
balance2 = tonumber(http.get(readconfig("syncnode").."?getbalance="..addressdv).readAll()) balance2 = tonumber(readURL(readconfig("syncnode").."?getbalance="..addressdv))
log("Took "..amt.." KST from a double vault") log("Took "..amt.." KST from a double vault")
end end
end end
@ -916,8 +963,8 @@ function wallet()
if yPos == 6 and xPos >= 25 and xPos <= 33 then if yPos == 6 and xPos >= 25 and xPos <= 33 then
if tonumber(amt) > 0 then if tonumber(amt) > 0 then
if tonumber(amt) <= balance then if tonumber(amt) <= balance then
local transaction = http.get(readconfig("syncnode").."?pushtx2&q="..addresslv.."&pkey="..masterkey.."&amt="..tonumber(amt)).readAll() local transaction = readURL(readconfig("syncnode").."?pushtx2&q="..addresslv.."&pkey="..masterkey.."&amt="..tonumber(amt))
balance = tonumber(http.get(readconfig("syncnode").."?getbalance="..address).readAll()) balance = tonumber(readURL(readconfig("syncnode").."?getbalance="..address))
log("Put "..amt.." KST in a local vault") log("Put "..amt.." KST in a local vault")
end end
end end
@ -925,8 +972,8 @@ function wallet()
if yPos == 6 and xPos >= 35 and xPos <= 44 then if yPos == 6 and xPos >= 35 and xPos <= 44 then
if tonumber(amt) > 0 then if tonumber(amt) > 0 then
if tonumber(amt) <= balance3 then if tonumber(amt) <= balance3 then
local transaction = http.get(readconfig("syncnode").."?pushtx2&q="..address.."&pkey="..readconfig("keyLV").."&amt="..tonumber(amt)).readAll() local transaction = readURL(readconfig("syncnode").."?pushtx2&q="..address.."&pkey="..readconfig("keyLV").."&amt="..tonumber(amt))
balance = tonumber(http.get(readconfig("syncnode").."?getbalance="..address).readAll()) balance = tonumber(readURL(readconfig("syncnode").."?getbalance="..address))
log("Took "..amt.." KST from a local vault") log("Took "..amt.." KST from a local vault")
end end
end end
@ -963,7 +1010,7 @@ function hud()
term.setTextColor(2048) term.setTextColor(2048)
term.write("release "..version.."") term.write("release "..version.."")
term.setCursorPos(2,19) term.setCursorPos(2,19)
term.write("by cossacksson") term.write(" by 3d6")
term.setTextColor(32768) term.setTextColor(32768)
term.setCursorPos(3,5) term.setCursorPos(3,5)
drawTab(" Overview ") drawTab(" Overview ")
@ -1011,18 +1058,20 @@ function hud()
term.setTextColor(32768) term.setTextColor(32768)
term.setCursorPos(19,5) term.setCursorPos(19,5)
local recenttransactions = "" local recenttransactions = ""
--if tostring(balance) ~= 'nil' then recenttransactions = http.get(readconfig("syncnode").."?listtx="..address.."&overview").readAll() end if tostring(balance) ~= 'nil' then recenttransactions = readURL(readconfig("syncnode").."?listtx="..address.."&overview") end
local txtype = 0 local txtype = 0
local graphics = 0 local graphics = 0
if string.len(recenttransactions) > 25 then if string.len(recenttransactions) > 25 then
repeat repeat
if string.sub(recenttransactions,13+(31*graphics),22+(31*graphics)) == "N/A(Mined)" then txtype = 1 if string.sub(recenttransactions,13+(31*graphics),22+(31*graphics)) == "N/A(Mined)" then txtype = 1
elseif string.sub(recenttransactions,13+(31*graphics),22+(31*graphics)) == "N/A(Names)" and tonumber(string.sub(recenttransactions,23+(31*graphics),31+(31*graphics))) == 0 then txtype = 7 elseif string.sub(recenttransactions,13+(31*graphics),22+(31*graphics)) == "N/A(Names)" and tonumber(string.sub(recenttransactions,23+(31*graphics),31+(31*graphics))) == 0 then txtype = 7
elseif tonumber(string.sub(recenttransactions,23+(31*graphics),31+(31*graphics))) == 0 then txtype = 9
elseif string.sub(recenttransactions,13+(31*graphics),22+(31*graphics)) == "N/A(Names)" then txtype = 6 elseif string.sub(recenttransactions,13+(31*graphics),22+(31*graphics)) == "N/A(Names)" then txtype = 6
elseif string.sub(recenttransactions,13+(31*graphics),22+(31*graphics)) == address then txtype = 4 elseif string.sub(recenttransactions,13+(31*graphics),22+(31*graphics)) == address then txtype = 4
elseif string.sub(recenttransactions,13+(31*graphics),22+(31*graphics)) == addressv1 then txtype = 5 elseif string.sub(recenttransactions,13+(31*graphics),22+(31*graphics)) == addressv1 then txtype = 5
elseif tonumber(string.sub(recenttransactions,23+(31*graphics),31+(31*graphics))) < 0 then txtype = 2 elseif tonumber(string.sub(recenttransactions,23+(31*graphics),31+(31*graphics))) < 0 then txtype = 2
elseif tonumber(string.sub(recenttransactions,23+(31*graphics),31+(31*graphics))) > 0 then txtype = 3 elseif tonumber(string.sub(recenttransactions,23+(31*graphics),31+(31*graphics))) > 0 then txtype = 3
else txtype = 8
end end
postgraphic(19,5+(5*graphics),txtype) postgraphic(19,5+(5*graphics),txtype)
term.setCursorPos(26,5+(5*graphics)) term.setCursorPos(26,5+(5*graphics))
@ -1035,6 +1084,8 @@ function hud()
elseif txtype == 5 then term.write("Imported") elseif txtype == 5 then term.write("Imported")
elseif txtype == 6 then term.write("Name registered") elseif txtype == 6 then term.write("Name registered")
elseif txtype == 7 then term.write("Name operation") elseif txtype == 7 then term.write("Name operation")
elseif txtype == 8 then term.write("Unknown")
elseif txtype == 9 then term.write("Name transfer")
end end
term.setCursorPos(26,6+(5*graphics)) term.setCursorPos(26,6+(5*graphics))
if txtype == 4 then if txtype == 4 then
@ -1051,7 +1102,7 @@ function hud()
term.setCursorPos(26,7+(5*graphics)) term.setCursorPos(26,7+(5*graphics))
term.setTextColor(32768) term.setTextColor(32768)
if txtype ~= 6 then term.setTextColor(512) end if txtype ~= 6 then term.setTextColor(512) end
if txtype > 1 and txtype < 6 then term.write(string.sub(recenttransactions,13+(31*graphics),22+(31*graphics))) end if txtype == 9 or (txtype > 1 and txtype < 6) then term.write(string.sub(recenttransactions,13+(31*graphics),22+(31*graphics))) end
--if txtype == 6 then term.write(".kst") end --if txtype == 6 then term.write(".kst") end
term.setCursorPos(26,8+(5*graphics)) term.setCursorPos(26,8+(5*graphics))
term.setTextColor(128) term.setTextColor(128)
@ -1059,23 +1110,6 @@ function hud()
graphics = graphics + 1 graphics = graphics + 1
until graphics >= math.floor(string.len(recenttransactions)/32) until graphics >= math.floor(string.len(recenttransactions)/32)
end end
term.setTextColor(colors.gray)
term.setCursorPos(19,5)
term.write("The Krist database is getting")
term.setCursorPos(19,6)
term.write("extremely huge. Some features")
term.setCursorPos(19,7)
term.write("have been temporarily disabled")
term.setCursorPos(19,8)
term.write("until queries can be made more")
term.setCursorPos(19,9)
term.write("efficient.")
term.setCursorPos(19,11)
term.write("This includes the recent")
term.setCursorPos(19,12)
term.write("transaction list that would")
term.setCursorPos(19,13)
term.write("normally be found here.")
term.setTextColor(32768) term.setTextColor(32768)
term.setCursorPos(19,3) term.setCursorPos(19,3)
term.write("Your balance: ") term.write("Your balance: ")
@ -1083,18 +1117,21 @@ function hud()
if tostring(balance) == 'nil' then balance = 0 end if tostring(balance) == 'nil' then balance = 0 end
term.write(tostring(balance).." KST ") term.write(tostring(balance).." KST ")
term.setTextColor(512) term.setTextColor(512)
local names = tonumber(http.get(readconfig("syncnode").."?getnames="..address).readAll()) local names = tonumber(readURL(readconfig("syncnode").."?getnames="..address))
if names > 0 then term.write("["..tostring(names).."]") end if names > 0 then term.write("["..tostring(names).."]") end
if address == "khm4f12scx" or address == "klhyy8e845" or address == "kcyd5vejdw" then if address == "ke3kjplzsz" or address == "767fc628a4" or address == "e3b0c44298" then
term.setCursorPos(1,1) term.setCursorPos(1,1)
term.setBackgroundColor(16384) term.setBackgroundColor(16384)
term.setTextColor(16) term.setTextColor(16)
term.clearLine() term.clearLine()
term.write("The crash on trying to edit a name is now fixed btw") term.write("You are currently using a blank string password.")
end end
elseif page == 2 then elseif page == 2 then
subbal = http.get(readconfig("syncnode").."?getbalance="..subject).readAll() term.setCursorPos(18,1)
subtxs = http.get(readconfig("syncnode").."?listtx="..subject).readAll() term.write("Please wait...")
os.sleep(0)
subbal = readURL(readconfig("syncnode").."?getbalance="..subject)
subtxs = readURL(readconfig("syncnode").."?listtx="..subject)
log("Loaded transactions for address "..subject) log("Loaded transactions for address "..subject)
log("Page index is "..scroll) log("Page index is "..scroll)
term.setCursorPos(18,1) term.setCursorPos(18,1)
@ -1215,7 +1252,7 @@ function hud()
term.setCursorPos(19,9) term.setCursorPos(19,9)
--term.write("KST distrib. Largest transfers") --term.write("KST distrib. Largest transfers")
elseif page == 5 then elseif page == 5 then
local blocks = http.get(readconfig("syncnode").."?blocks").readAll() local blocks = readURL(readconfig("syncnode").."?blocks")
local tx = 0 local tx = 0
ar = 0 ar = 0
local height = string.sub(blocks,1,8) local height = string.sub(blocks,1,8)
@ -1273,7 +1310,7 @@ function hud()
term.setCursorPos(18,1) term.setCursorPos(18,1)
term.write("ADDRESS (click to edit)") term.write("ADDRESS (click to edit)")
elseif page == 7 then elseif page == 7 then
local blocks = http.get(readconfig("syncnode").."?richapi").readAll() local blocks = readURL(readconfig("syncnode").."?richapi")
local tx = 0 local tx = 0
ar = 0 ar = 0
local height = string.sub(blocks,1,8) local height = string.sub(blocks,1,8)
@ -1316,7 +1353,7 @@ function hud()
term.setCursorPos(19,3) term.setCursorPos(19,3)
term.write("Double vault Register name") term.write("Double vault Register name")
term.setCursorPos(19,4) term.setCursorPos(19,4)
term.write("Local vault ") term.write("Local vault")
term.setCursorPos(19,5) term.setCursorPos(19,5)
--term.write("Disk vault v1 SHA vault") --term.write("Disk vault v1 SHA vault")
term.setCursorPos(19,6) term.setCursorPos(19,6)
@ -1385,7 +1422,7 @@ function hud()
end end
term.setTextColor(32768) term.setTextColor(32768)
elseif page == 10 then elseif page == 10 then
local blocks = http.get(readconfig("syncnode").."?blocks&low").readAll() local blocks = readURL(readconfig("syncnode").."?blocks&low")
local tx = 0 local tx = 0
ar = 0 ar = 0
local blktime = {} local blktime = {}
@ -1419,7 +1456,7 @@ function hud()
term.write(string.sub(blkhash[ar],1,12)) term.write(string.sub(blkhash[ar],1,12))
until ar == math.min(tx,18) until ar == math.min(tx,18)
elseif page == 11 then elseif page == 11 then
local blocks = http.get(readconfig("syncnode").."?blocks&low&lownonce").readAll() local blocks = readURL(readconfig("syncnode").."?blocks&low&lownonce")
local tx = 0 local tx = 0
ar = 0 ar = 0
local blktime = {} local blktime = {}
@ -1450,7 +1487,7 @@ function hud()
term.write(tonumber(blkhash[ar])) term.write(tonumber(blkhash[ar]))
until ar == math.min(tx,18) until ar == math.min(tx,18)
elseif page == 12 then elseif page == 12 then
local blocks = http.get(readconfig("syncnode").."?blocks&low&highnonce").readAll() local blocks = readURL(readconfig("syncnode").."?blocks&low&highnonce")
local tx = 0 local tx = 0
ar = 0 ar = 0
local blktime = {} local blktime = {}
@ -1481,7 +1518,7 @@ function hud()
term.write(tonumber(blkhash[ar])) term.write(tonumber(blkhash[ar]))
until ar == math.min(tx,18) until ar == math.min(tx,18)
elseif page == 13 then elseif page == 13 then
balance3 = tonumber(http.get(readconfig("syncnode").."?getbalance="..addresslv).readAll()) balance3 = tonumber(readURL(readconfig("syncnode").."?getbalance="..addresslv))
term.setCursorPos(25,2) term.setCursorPos(25,2)
term.write("Local vault manager") term.write("Local vault manager")
term.setCursorPos(19,8) term.setCursorPos(19,8)
@ -1497,15 +1534,15 @@ function hud()
term.setCursorPos(19,13) term.setCursorPos(19,13)
term.write("they were initially created on.") term.write("they were initially created on.")
term.setCursorPos(19,14) term.setCursorPos(19,14)
term.write("This has use cases, but is a") term.write("If you do this, please ensure")
term.setCursorPos(19,15) term.setCursorPos(19,15)
term.write("dangerous way of storing Krist") term.write("that this computer is never")
term.setCursorPos(19,16) term.setCursorPos(19,16)
term.write("and you should probably only do") term.write("stolen or broken, as your money")
term.setCursorPos(19,17) term.setCursorPos(19,17)
term.write("it this way if you know what") term.write("may be lost if you don't have a")
term.setCursorPos(19,18) term.setCursorPos(19,18)
term.write("you're doing.") term.write("backup.")
term.setCursorPos(19,4) term.setCursorPos(19,4)
term.write("KST put here: "..balance3) term.write("KST put here: "..balance3)
term.setCursorPos(19,5) term.setCursorPos(19,5)
@ -1554,26 +1591,29 @@ function hud()
term.write(" Name Actions ") term.write(" Name Actions ")
term.setBackgroundColor(1) term.setBackgroundColor(1)
term.setCursorPos(18,3) term.setCursorPos(18,3)
local namelist = http.get(readconfig("syncnode").."?listnames="..address).readAll() local namelist = readURL(readconfig("syncnode").."?listnames="..address)
if string.len(namelist) == 0 then local splitname = split(namelist, ";")
if #splitname == 0 then
term.setTextColor(256) term.setTextColor(256)
term.write("No names to display!") term.write("No names to display!")
else else
local namecount = 0 local namecount = 1
repeat repeat
local thisname = namelist:sub(0,namelist:find(";")-1) local thisname = splitname[namecount]
--namelist:sub(0,namelist:find(";")-1)
term.setTextColor(32768) term.setTextColor(32768)
term.setCursorPos(18,3+namecount) term.setCursorPos(18,3+namecount)
term.write(string.sub(thisname..".kst",0,20)) term.write(splitname[namecount]..".kst")
term.setCursorPos(39,3+namecount) term.setCursorPos(39,3+namecount)
term.setTextColor(512) term.setTextColor(512)
if thisname == "a" or thisname == "name" or thisname == "owner" or thisname == "updated" or thisname == "registered" or thisname == "expires" or thisname == "id" or thisname == "unpaid" then term.setTextColor(256) end if thisname == "a" or thisname == "name" or thisname == "owner" or thisname == "updated" or thisname == "registered" or thisname == "expires" or thisname == "id" or thisname == "unpaid" then term.setTextColor(256) end
term.write("Edit Send ") term.write("Edit Send ")
term.setTextColor(256) term.setTextColor(256)
term.write("Go") term.write("Go")
namelist = namelist:sub(1+namelist:find(";"))
namecount = namecount + 1 namecount = namecount + 1
until string.len(namelist) == 0 until namecount == #splitname+1
end end
--term.write("a.kst Edit Send Go") --term.write("a.kst Edit Send Go")
term.setBackgroundColor(1) term.setBackgroundColor(1)
@ -1668,7 +1708,7 @@ function hud()
term.setTextColor(colors.black) term.setTextColor(colors.black)
term.setCursorPos(19,5) term.setCursorPos(19,5)
term.write("Zone: ") term.write("Zone: ")
zone = http.get(readconfig("syncnode").."?a="..subject).readAll() zone = readURL(readconfig("syncnode").."?a="..subject)
if zone == "" then if zone == "" then
term.setTextColor(colors.lightGray) term.setTextColor(colors.lightGray)
term.write("(click to set)") term.write("(click to set)")
@ -1703,3 +1743,19 @@ function hud()
end end
end end
boot() boot()
wallet = nil
checkfile = nil
posx = nil
update = nil
log = nil
checkdir = nil
readconfig = nil
file = nil
drawTab = nil
makev2address = nil
logfile = nil
posy = nil
openwallet = nil
settle = nil
drawBtn = nil
hud = nil