diff options
author | ubq323 <ubq323@ubq323.website> | 2022-12-29 22:26:29 +0000 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2022-12-29 22:26:29 +0000 |
commit | 63cbdfdecff90ca86f19e74e7fff52d51eec18ce (patch) | |
tree | b4da6e9f87ade93e90eb2ea7285b46167f796628 | |
parent | 9b05d8b9ee386e22d717ed501c78349e28b197d0 (diff) |
shop
-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 |