diff options
-rw-r--r-- | shop.lua | 27 |
1 files changed, 25 insertions, 2 deletions
@@ -1,4 +1,8 @@ key=assert(settings.get"krist.pkey","please set private key") + +-- d@ac.kst +our_name = {"d","ac"} + sres =textutils.unserializeJSON( http.post("https://krist.dev/ws/start","privatekey="..key).readAll()) assert(sres.ok,"not ok") @@ -14,6 +18,26 @@ end sendws{type="me"} +function parsemeta(m) + local out = {} + for s in string.gmatch(m..";","(.-);") do + local k,v = s:match"^(.-)=(.-)$" + if k=nil then + out.recipient = s + else + out[k]=v + end + end + return out +end + +function proctrans(tr) + if tr.to ~= our_addr then return end + if tr.type ~= "transfer" then return end + if not (tr.sent_metaname == our_name[1] and tr.sent_name == our_name[2]) then return end + return parsemeta(tr.metadata) +end + while true do msgtxt = assert(ws.receive(),"ws error") msg = textutils.unserializeJSON(msgtxt) @@ -25,8 +49,7 @@ while true do m.write(our_addr) end if msg.type == "event" and msg.event == "transaction" then - print("trans") - + print(proctrans(msg.transaction)) end end |