Advertisement
Guest User

test

a guest
Feb 21st, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.27 KB | None | 0 0
  1. gactive = false
  2. local w = require("w") -- allows interaction with krist websocket api (for realtime data)
  3. local r = require("r") -- makes http requests easier
  4. local k = require("k") -- the krist api itself
  5. local jua = require("jua") -- makes events easier
  6. os.loadAPI("json.lua") -- to parse data returned by the krist api
  7. local await = jua.await
  8. r.init(jua)
  9. w.init(jua)
  10. k.init(jua, json, w, r)
  11.  
  12.  
  13.  
  14. local function openWebsocket()
  15.   local success, ws = await(k.connect, k.toKristWalletFormat(6798332999))
  16.   assert(success, "Failed to get websocket URL")
  17.  
  18.   -- print("Connected to websocket.")
  19.  
  20.   -- here we subscribe to the 'transactions' event
  21.   local success = await(ws.subscribe, "transactions", function(data)
  22.     -- this function is called every time a transaction is made
  23.     local transaction = data.transaction
  24.     gactive = true
  25.     --print("Transaction made:")
  26.     --print("From: " .. transaction.from)
  27.     --print("To: " .. transaction.to)
  28.     --print("Value: " .. transaction.value .. " KST")
  29.     -- Transactions have other properties, including "metadata", "id" and "time".
  30.     -- Metadata can be parsed using k.parseMeta
  31.   end)
  32.   assert(success, "Failed to subscribe to event")
  33. end
  34.  
  35.  
  36. jua.go(function()
  37.   openWebsocket()
  38.  setInterval(main,0.001)
  39.  
  40. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement