Update k.lua and others
This commit is contained in:
@@ -119,4 +119,4 @@ return {
|
|||||||
go = go,
|
go = go,
|
||||||
stop = stop,
|
stop = stop,
|
||||||
await = await
|
await = await
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,6 +101,15 @@ function addresses(cb, limit, offset)
|
|||||||
end, "/addresses?limit="..(limit or 50).."&offset="..(offset or 0))
|
end, "/addresses?limit="..(limit or 50).."&offset="..(offset or 0))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function name(cb, name)
|
||||||
|
asserttype(cb, "callback", "function")
|
||||||
|
asserttype(name, "name", "string")
|
||||||
|
|
||||||
|
api_request(function(success, data)
|
||||||
|
cb(success and data and data.ok, data.name or data)
|
||||||
|
end, "/names/"..name)
|
||||||
|
end
|
||||||
|
|
||||||
function rich(cb, limit, offset)
|
function rich(cb, limit, offset)
|
||||||
asserttype(cb, "callback", "function")
|
asserttype(cb, "callback", "function")
|
||||||
asserttype(limit, "limit", "number", true)
|
asserttype(limit, "limit", "number", true)
|
||||||
@@ -165,7 +174,8 @@ local wsEventNameLookup = {
|
|||||||
names = "name",
|
names = "name",
|
||||||
ownNames = "name",
|
ownNames = "name",
|
||||||
ownWebhooks = "webhook",
|
ownWebhooks = "webhook",
|
||||||
motd = "motd"
|
motd = "motd",
|
||||||
|
keepalive = "keepalive",
|
||||||
}
|
}
|
||||||
|
|
||||||
local wsEvents = {}
|
local wsEvents = {}
|
||||||
@@ -362,6 +372,7 @@ return {
|
|||||||
addressTransactions = addressTransactions,
|
addressTransactions = addressTransactions,
|
||||||
addressNames = addressNames,
|
addressNames = addressNames,
|
||||||
addresses = addresses,
|
addresses = addresses,
|
||||||
|
name = name,
|
||||||
rich = rich,
|
rich = rich,
|
||||||
transactions = transactions,
|
transactions = transactions,
|
||||||
latestTransactions = latestTransactions,
|
latestTransactions = latestTransactions,
|
||||||
@@ -369,5 +380,4 @@ return {
|
|||||||
makeTransaction = makeTransaction,
|
makeTransaction = makeTransaction,
|
||||||
connect = connect,
|
connect = connect,
|
||||||
parseMeta = parseMeta,
|
parseMeta = parseMeta,
|
||||||
sha256 = sha256,
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -18,13 +18,16 @@ end
|
|||||||
|
|
||||||
local function findID(url)
|
local function findID(url)
|
||||||
local found = gfind(url, idPatt)
|
local found = gfind(url, idPatt)
|
||||||
if found then
|
if not found then return nil end
|
||||||
return tonumber(found[#found]:sub(found[#found]:find("%d+")))
|
return tonumber(found[#found]:sub(found[#found]:find("%d+")))
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function newID()
|
local function newID()
|
||||||
return #callbackRegistry + 1
|
for i = 1, math.huge do
|
||||||
|
if not callbackRegistry[i] then
|
||||||
|
return i
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function trimID(url)
|
local function trimID(url)
|
||||||
@@ -36,8 +39,8 @@ end
|
|||||||
function request(callback, url, headers, postData)
|
function request(callback, url, headers, postData)
|
||||||
local id = newID()
|
local id = newID()
|
||||||
local newUrl = url .. "#R" .. id
|
local newUrl = url .. "#R" .. id
|
||||||
http.request(newUrl, postData, headers)
|
|
||||||
callbackRegistry[id] = callback
|
callbackRegistry[id] = callback
|
||||||
|
http.request(newUrl, postData, headers)
|
||||||
end
|
end
|
||||||
|
|
||||||
function init(jua)
|
function init(jua)
|
||||||
@@ -46,7 +49,7 @@ function init(jua)
|
|||||||
local id = findID(url)
|
local id = findID(url)
|
||||||
if id and callbackRegistry[id] then
|
if id and callbackRegistry[id] then
|
||||||
callbackRegistry[id](true, trimID(url), handle)
|
callbackRegistry[id](true, trimID(url), handle)
|
||||||
table.remove(callbackRegistry, id)
|
callbackRegistry[id] = nil
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -54,7 +57,7 @@ function init(jua)
|
|||||||
local id = findID(url)
|
local id = findID(url)
|
||||||
if id and callbackRegistry[id] then
|
if id and callbackRegistry[id] then
|
||||||
callbackRegistry[id](false, trimID(url), handle)
|
callbackRegistry[id](false, trimID(url), handle)
|
||||||
table.remove(callbackRegistry, id)
|
callbackRegistry[id] = nil
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
@@ -62,4 +65,4 @@ end
|
|||||||
return {
|
return {
|
||||||
request = request,
|
request = request,
|
||||||
init = init
|
init = init
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ end
|
|||||||
|
|
||||||
local function findID(url)
|
local function findID(url)
|
||||||
local found = gfind(url, idPatt)
|
local found = gfind(url, idPatt)
|
||||||
local id = tonumber(found[#found]:sub(found[#found]:find("%d+")))
|
if not found then return nil end
|
||||||
return id
|
return tonumber(found[#found]:sub(found[#found]:find("%d+")))
|
||||||
end
|
end
|
||||||
|
|
||||||
local function newID()
|
local function newID()
|
||||||
@@ -71,57 +71,57 @@ function init(jua)
|
|||||||
jua = jua
|
jua = jua
|
||||||
if async then
|
if async then
|
||||||
jua.on("websocket_success", function(event, url, handle)
|
jua.on("websocket_success", function(event, url, handle)
|
||||||
local success, id = pcall(findID,url)
|
local id = findID(url)
|
||||||
if success and id and callbackRegistry[id] and callbackRegistry[id].success then
|
if id and callbackRegistry[id].success then
|
||||||
callbackRegistry[id].success(id, handle)
|
callbackRegistry[id].success(id, handle)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
jua.on("websocket_failure", function(event, url)
|
jua.on("websocket_failure", function(event, url)
|
||||||
local success, id = pcall(findID,url)
|
local id = findID(url)
|
||||||
if success and id and callbackRegistry[id] and callbackRegistry[id].failure then
|
if id and callbackRegistry[id].failure then
|
||||||
callbackRegistry[id].failure(id)
|
callbackRegistry[id].failure(id)
|
||||||
end
|
end
|
||||||
table.remove(callbackRegistry, id)
|
table.remove(callbackRegistry, id)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
jua.on("websocket_message", function(event, url, data)
|
jua.on("websocket_message", function(event, url, data)
|
||||||
local success, id = pcall(findID,url)
|
local id = findID(url)
|
||||||
if success and id and callbackRegistry[id] and callbackRegistry[id].message then
|
if id and callbackRegistry[id].message then
|
||||||
callbackRegistry[id].message(id, data)
|
callbackRegistry[id].message(id, data)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
jua.on("websocket_closed", function(event, url)
|
jua.on("websocket_closed", function(event, url)
|
||||||
local success, id = pcall(findID,url)
|
local id = findID(url)
|
||||||
if success and id and callbackRegistry[id] and callbackRegistry[id].closed then
|
if id and callbackRegistry[id].closed then
|
||||||
callbackRegistry[id].closed(id)
|
callbackRegistry[id].closed(id)
|
||||||
end
|
end
|
||||||
table.remove(callbackRegistry, id)
|
table.remove(callbackRegistry, id)
|
||||||
end)
|
end)
|
||||||
else
|
else
|
||||||
jua.on("socket_connect", function(event, id)
|
jua.on("socket_connect", function(event, id)
|
||||||
if id and callbackRegistry[id] and callbackRegistry[id].success then
|
if id and callbackRegistry[id].success then
|
||||||
callbackRegistry[id].success(id, wsRegistry[id])
|
callbackRegistry[id].success(id, wsRegistry[id])
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
jua.on("socket_error", function(event, id, msg)
|
jua.on("socket_error", function(event, id, msg)
|
||||||
if id and callbackRegistry[id] and callbackRegistry[id].failure then
|
if id and callbackRegistry[id].failure then
|
||||||
callbackRegistry[id].failure(id, msg)
|
callbackRegistry[id].failure(id, msg)
|
||||||
end
|
end
|
||||||
table.remove(callbackRegistry, id)
|
table.remove(callbackRegistry, id)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
jua.on("socket_message", function(event, id)
|
jua.on("socket_message", function(event, id)
|
||||||
if id and callbackRegistry[id] and callbackRegistry[id].message then
|
if id and callbackRegistry[id].message then
|
||||||
local data = wsRegistry[id].read()
|
local data = wsRegistry[id].read()
|
||||||
callbackRegistry[id].message(id, data)
|
callbackRegistry[id].message(id, data)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
jua.on("socket_closed", function(event, id)
|
jua.on("socket_closed", function(event, id)
|
||||||
if id and callbackRegistry[id] and callbackRegistry[id].closed then
|
if id and callbackRegistry[id].closed then
|
||||||
callbackRegistry[id].closed(id)
|
callbackRegistry[id].closed(id)
|
||||||
end
|
end
|
||||||
table.remove(callbackRegistry, id)
|
table.remove(callbackRegistry, id)
|
||||||
|
|||||||
Reference in New Issue
Block a user