summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2022-12-29 22:26:29 +0000
committerubq323 <ubq323@ubq323.website>2022-12-29 22:26:29 +0000
commit63cbdfdecff90ca86f19e74e7fff52d51eec18ce (patch)
treeb4da6e9f87ade93e90eb2ea7285b46167f796628
parent9b05d8b9ee386e22d717ed501c78349e28b197d0 (diff)
shop
-rw-r--r--shop.lua27
1 files changed, 25 insertions, 2 deletions
diff --git a/shop.lua b/shop.lua
index 42efa9d..7bd3c81 100644
--- a/shop.lua
+++ b/shop.lua
@@ -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