-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
108 lines (88 loc) · 2.45 KB
/
Copy pathmain.lua
File metadata and controls
108 lines (88 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
local json = require('json');
local bint = require('.bint')(256)
local utils = require(".utils")
WorldID = 'QIFgbqEmk5MyJy01wuINfcRP_erGNNbhqHRkAQjxKgg'
RouterID = 'wh5vB2IbqmIBUqgodOaTvByNFDPr73gbUq1bVOUtCrw'
BazarID = 'U3TjJAZWJjlWBB4KAXSHKzuky81jtyh0zqH8rUL4Wd0'
Fee = 100
TradeToken = 'MkZP5EYbDuVS_FfALYGEZIR_hBGnjcWYWqyWN9v096k'
WrappedAR = "xU9zFkq3X2ZQ6olwNVvr1vUWIjc3kXTWr7xKQD6dh10"
-- Utils helper functions
Utils = {
add = function(a, b)
return tostring(bint(a) + bint(b))
end,
subtract = function(a, b)
return tostring(bint(a) - bint(b))
end,
toBalanceValue = function(a)
return tostring(bint(a))
end,
toNumber = function(a)
return tonumber(a)
end
}
function Spairs(t, order)
-- collect the keys
local keys = {}
for k in pairs(t) do keys[#keys + 1] = k end
-- if order function given, sort by it by passing the table and keys a, b,
-- otherwise just sort the keys
if order then
table.sort(keys, function(a, b) return order(t, a, b) end)
else
table.sort(keys)
end
-- return the iterator function
local i = 0
return function()
i = i + 1
if keys[i] then
return keys[i], t[keys[i]]
end
end
end
local function some(arr, predicate)
for i = 1, #arr do
if predicate(arr[i]) then
return true
end
end
return false
end
function slice(tbl, start_idx, end_idx)
local new_table = {}
table.move(tbl, start_idx or 1, end_idx or #tbl, 1, new_table)
return new_table
end
local function kind1(msg)
ao.send({
Target = WrappedAR,
Action = 'Transfer',
Recipient = RouterID,
Quantity = Fee,
['X-Prompt'] = 'What is the meaning of life?',
['X-Tokens'] = '10'
})
end
local function kind3(msg)
end
local function kind6(msg)
end
local function event(msg)
if msg.Kind == "1" then kind1(msg) end
if msg.Kind == "3" then kind3(msg) end
if msg.Kind == "6" then kind6(msg) end
end
Handlers.add('FetchEvents', Handlers.utils.hasMatchingTag('Action', 'FetchEvents'), function(msg)
end)
Handlers.add('Event', Handlers.utils.hasMatchingTag('Action', 'Event'), function(msg)
event(msg)
end)
Handlers.add(
"Cron", -- Handler name
Handlers.utils.hasMatchingTag("Action", "Cron"), -- Handler pattern to identify cron message
function () -- Handler task to execute on cron message
-- Do something
end
)