wao 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/aoconnect.js +2 -2
- package/cjs/index.js +6 -0
- package/{test/lua/aos.wasm → cjs/lua/aos2_0_1.wasm} +0 -0
- package/cjs/utils.js +1 -16
- package/esm/aoconnect.js +2 -2
- package/esm/index.js +2 -1
- package/esm/utils.js +0 -18
- package/package.json +1 -1
- package/test/aoconnect.js +2 -2
- package/test/index.js +2 -1
- package/test/package.json +1 -1
- package/test/utils.js +0 -18
- package/esm/lua/aos-sqlite.wasm +0 -0
- package/esm/lua/aos.wasm +0 -0
- package/esm/lua/aos2.lua +0 -33
- package/esm/lua/atomic-asset.lua +0 -238
- package/esm/lua/atomic-note-library.lua +0 -2274
- package/esm/lua/atomic-note.lua +0 -11
- package/esm/lua/collection-registry.lua +0 -202
- package/esm/lua/collection.lua +0 -173
- package/esm/lua/notebook.lua +0 -173
- package/esm/lua/profile.lua +0 -858
- package/esm/lua/profile000.lua +0 -666
- package/esm/lua/proxy.lua +0 -24
- package/esm/lua/registry.lua +0 -858
- package/esm/lua/registry000.lua +0 -636
- package/test/lua/aos-sqlite.wasm +0 -0
- package/test/lua/aos2.lua +0 -33
- package/test/lua/atomic-asset.lua +0 -238
- package/test/lua/atomic-note-library.lua +0 -2274
- package/test/lua/atomic-note.lua +0 -11
- package/test/lua/collection-registry.lua +0 -202
- package/test/lua/collection.lua +0 -173
- package/test/lua/notebook.lua +0 -173
- package/test/lua/profile.lua +0 -858
- package/test/lua/profile000.lua +0 -666
- package/test/lua/proxy.lua +0 -24
- package/test/lua/registry.lua +0 -858
- package/test/lua/registry000.lua +0 -636
package/cjs/aoconnect.js
CHANGED
|
@@ -115,13 +115,13 @@ var buildTags = function buildTags(act, tags) {
|
|
|
115
115
|
};
|
|
116
116
|
var connect = exports.connect = function connect() {
|
|
117
117
|
var wasms = {
|
|
118
|
-
|
|
118
|
+
"Do_Uc2Sju_ffp6Ev0AnLVdPtot15rvMjP-a9VVaA5fM": {
|
|
119
119
|
file: "aos2_0_1",
|
|
120
120
|
format: "wasm64-unknown-emscripten-draft_2024_02_15"
|
|
121
121
|
}
|
|
122
122
|
};
|
|
123
123
|
var modules = {
|
|
124
|
-
aos_2_0_1: "
|
|
124
|
+
aos_2_0_1: "Do_Uc2Sju_ffp6Ev0AnLVdPtot15rvMjP-a9VVaA5fM"
|
|
125
125
|
};
|
|
126
126
|
var modmap = {};
|
|
127
127
|
var env = {
|
package/cjs/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
@@ -15,6 +16,11 @@ Object.defineProperty(exports, "AR", {
|
|
|
15
16
|
return _ar["default"];
|
|
16
17
|
}
|
|
17
18
|
});
|
|
19
|
+
exports.utils = void 0;
|
|
18
20
|
var _ar = _interopRequireDefault(require("./ar.js"));
|
|
19
21
|
var _ao = _interopRequireDefault(require("./ao.js"));
|
|
22
|
+
var utils = _interopRequireWildcard(require("./utils.js"));
|
|
23
|
+
exports.utils = utils;
|
|
24
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
25
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
|
20
26
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
Binary file
|
package/cjs/utils.js
CHANGED
|
@@ -325,23 +325,8 @@ var srcs = exports.srcs = {
|
|
|
325
325
|
module: "cNlipBptaF9JeFAf4wUmpi43EojNanIBos3EfNrEOWo",
|
|
326
326
|
module_sqlite: "ghSkge2sIUD_F00ym5sEimC63BDBuBrq4b5OcwxOjiw",
|
|
327
327
|
module_aos2: "Do_Uc2Sju_ffp6Ev0AnLVdPtot15rvMjP-a9VVaA5fM",
|
|
328
|
-
notelib_src: "h35YJqJ0ve_2pxO5uV1tKTQ44k9WpTBOzk5lGpYcEWs",
|
|
329
|
-
note_src: "6BrngB9N_ujSka4BmsZ2HuRbbqePQFkNXQ-tATp03ZU",
|
|
330
|
-
notebook_src: "NKISXnq5XseLQd_u-lfO6ThBLuikLoontY47UlONrB4",
|
|
331
|
-
asset_src: "CT5qN5e97Fr0wJ8VVu_TRj6qPNWped52IPsJMJ2pd08",
|
|
332
|
-
collection_src: "cLzVDfhmC0JAADYyFkdLQbtEMtL4VxbeGv98TADbbRk",
|
|
333
|
-
bookreg_src: "4Bm1snpCEHIxYMDdAxiFf6ar81gKQHvElDFeDZbSnJU",
|
|
334
|
-
registry_src: "kBk-wRbK5aIZVqDJEzWhjYb5gnydHafrFG3wgItBvuI",
|
|
335
328
|
scheduler: "_GQ33BkPtZrqxA84vM8Zk-N2aO0toNNu_C-l-rawrBA",
|
|
336
|
-
authority: "fcoN_xJeisVsPXA-trzVAuIiqO3ydLQxM-L4XbrQKzY"
|
|
337
|
-
notelib_mid: "ls7QnjCPXDeAF6w7mA0cNAwv9hY7r-W1T31X1iEJMJU",
|
|
338
|
-
bookreg: "TFWDmf8a3_nw43GCm_CuYlYoylHAjCcFGbgHfDaGcsg",
|
|
339
|
-
thumb: "9v2GrtXpVpPWf9KBuTBdClARjjcDA3NqxFn8Kbn1f2M",
|
|
340
|
-
banner: "UuEwLRmuNmqLTDcKqgcxDEV1CWIR_uZ6rxzmKjODlrg",
|
|
341
|
-
proxy: "0uboI80S6vMxJD9Yn41Wdwnp9uAHEi4XLGQhBrp3qSQ",
|
|
342
|
-
render: "yXXAop3Yxm8QlZRzP46oRxZjCBp88YTpoSTPlTr4TcQ",
|
|
343
|
-
registry: "SNy4m-DrqxWl01YqGM4sxI8qCni-58re8uuJLvZPypY",
|
|
344
|
-
profile: "uEtSHyK9yDBABomez6ts3LI_8ULvO-rANSgDN_9OzEc"
|
|
329
|
+
authority: "fcoN_xJeisVsPXA-trzVAuIiqO3ydLQxM-L4XbrQKzY"
|
|
345
330
|
};
|
|
346
331
|
var buildTags = exports.buildTags = function buildTags(act, tags) {
|
|
347
332
|
var _tags = [];
|
package/esm/aoconnect.js
CHANGED
|
@@ -51,13 +51,13 @@ const buildTags = (act, tags) => {
|
|
|
51
51
|
|
|
52
52
|
export const connect = () => {
|
|
53
53
|
let wasms = {
|
|
54
|
-
|
|
54
|
+
"Do_Uc2Sju_ffp6Ev0AnLVdPtot15rvMjP-a9VVaA5fM": {
|
|
55
55
|
file: "aos2_0_1",
|
|
56
56
|
format: "wasm64-unknown-emscripten-draft_2024_02_15",
|
|
57
57
|
},
|
|
58
58
|
}
|
|
59
59
|
let modules = {
|
|
60
|
-
aos_2_0_1: "
|
|
60
|
+
aos_2_0_1: "Do_Uc2Sju_ffp6Ev0AnLVdPtot15rvMjP-a9VVaA5fM",
|
|
61
61
|
}
|
|
62
62
|
let modmap = {}
|
|
63
63
|
let env = { msgs: {} }
|
package/esm/index.js
CHANGED
package/esm/utils.js
CHANGED
|
@@ -205,26 +205,8 @@ const srcs = {
|
|
|
205
205
|
module: "cNlipBptaF9JeFAf4wUmpi43EojNanIBos3EfNrEOWo",
|
|
206
206
|
module_sqlite: "ghSkge2sIUD_F00ym5sEimC63BDBuBrq4b5OcwxOjiw",
|
|
207
207
|
module_aos2: "Do_Uc2Sju_ffp6Ev0AnLVdPtot15rvMjP-a9VVaA5fM",
|
|
208
|
-
|
|
209
|
-
notelib_src: "h35YJqJ0ve_2pxO5uV1tKTQ44k9WpTBOzk5lGpYcEWs",
|
|
210
|
-
note_src: "6BrngB9N_ujSka4BmsZ2HuRbbqePQFkNXQ-tATp03ZU",
|
|
211
|
-
notebook_src: "NKISXnq5XseLQd_u-lfO6ThBLuikLoontY47UlONrB4",
|
|
212
|
-
asset_src: "CT5qN5e97Fr0wJ8VVu_TRj6qPNWped52IPsJMJ2pd08",
|
|
213
|
-
collection_src: "cLzVDfhmC0JAADYyFkdLQbtEMtL4VxbeGv98TADbbRk",
|
|
214
|
-
bookreg_src: "4Bm1snpCEHIxYMDdAxiFf6ar81gKQHvElDFeDZbSnJU",
|
|
215
|
-
registry_src: "kBk-wRbK5aIZVqDJEzWhjYb5gnydHafrFG3wgItBvuI",
|
|
216
|
-
|
|
217
208
|
scheduler: "_GQ33BkPtZrqxA84vM8Zk-N2aO0toNNu_C-l-rawrBA",
|
|
218
209
|
authority: "fcoN_xJeisVsPXA-trzVAuIiqO3ydLQxM-L4XbrQKzY",
|
|
219
|
-
|
|
220
|
-
notelib_mid: "ls7QnjCPXDeAF6w7mA0cNAwv9hY7r-W1T31X1iEJMJU",
|
|
221
|
-
bookreg: "TFWDmf8a3_nw43GCm_CuYlYoylHAjCcFGbgHfDaGcsg",
|
|
222
|
-
thumb: "9v2GrtXpVpPWf9KBuTBdClARjjcDA3NqxFn8Kbn1f2M",
|
|
223
|
-
banner: "UuEwLRmuNmqLTDcKqgcxDEV1CWIR_uZ6rxzmKjODlrg",
|
|
224
|
-
proxy: "0uboI80S6vMxJD9Yn41Wdwnp9uAHEi4XLGQhBrp3qSQ",
|
|
225
|
-
render: "yXXAop3Yxm8QlZRzP46oRxZjCBp88YTpoSTPlTr4TcQ",
|
|
226
|
-
registry: "SNy4m-DrqxWl01YqGM4sxI8qCni-58re8uuJLvZPypY",
|
|
227
|
-
profile: "uEtSHyK9yDBABomez6ts3LI_8ULvO-rANSgDN_9OzEc",
|
|
228
210
|
}
|
|
229
211
|
|
|
230
212
|
const buildTags = (act, tags) => {
|
package/package.json
CHANGED
package/test/aoconnect.js
CHANGED
|
@@ -51,13 +51,13 @@ const buildTags = (act, tags) => {
|
|
|
51
51
|
|
|
52
52
|
export const connect = () => {
|
|
53
53
|
let wasms = {
|
|
54
|
-
|
|
54
|
+
"Do_Uc2Sju_ffp6Ev0AnLVdPtot15rvMjP-a9VVaA5fM": {
|
|
55
55
|
file: "aos2_0_1",
|
|
56
56
|
format: "wasm64-unknown-emscripten-draft_2024_02_15",
|
|
57
57
|
},
|
|
58
58
|
}
|
|
59
59
|
let modules = {
|
|
60
|
-
aos_2_0_1: "
|
|
60
|
+
aos_2_0_1: "Do_Uc2Sju_ffp6Ev0AnLVdPtot15rvMjP-a9VVaA5fM",
|
|
61
61
|
}
|
|
62
62
|
let modmap = {}
|
|
63
63
|
let env = { msgs: {} }
|
package/test/index.js
CHANGED
package/test/package.json
CHANGED
package/test/utils.js
CHANGED
|
@@ -205,26 +205,8 @@ const srcs = {
|
|
|
205
205
|
module: "cNlipBptaF9JeFAf4wUmpi43EojNanIBos3EfNrEOWo",
|
|
206
206
|
module_sqlite: "ghSkge2sIUD_F00ym5sEimC63BDBuBrq4b5OcwxOjiw",
|
|
207
207
|
module_aos2: "Do_Uc2Sju_ffp6Ev0AnLVdPtot15rvMjP-a9VVaA5fM",
|
|
208
|
-
|
|
209
|
-
notelib_src: "h35YJqJ0ve_2pxO5uV1tKTQ44k9WpTBOzk5lGpYcEWs",
|
|
210
|
-
note_src: "6BrngB9N_ujSka4BmsZ2HuRbbqePQFkNXQ-tATp03ZU",
|
|
211
|
-
notebook_src: "NKISXnq5XseLQd_u-lfO6ThBLuikLoontY47UlONrB4",
|
|
212
|
-
asset_src: "CT5qN5e97Fr0wJ8VVu_TRj6qPNWped52IPsJMJ2pd08",
|
|
213
|
-
collection_src: "cLzVDfhmC0JAADYyFkdLQbtEMtL4VxbeGv98TADbbRk",
|
|
214
|
-
bookreg_src: "4Bm1snpCEHIxYMDdAxiFf6ar81gKQHvElDFeDZbSnJU",
|
|
215
|
-
registry_src: "kBk-wRbK5aIZVqDJEzWhjYb5gnydHafrFG3wgItBvuI",
|
|
216
|
-
|
|
217
208
|
scheduler: "_GQ33BkPtZrqxA84vM8Zk-N2aO0toNNu_C-l-rawrBA",
|
|
218
209
|
authority: "fcoN_xJeisVsPXA-trzVAuIiqO3ydLQxM-L4XbrQKzY",
|
|
219
|
-
|
|
220
|
-
notelib_mid: "ls7QnjCPXDeAF6w7mA0cNAwv9hY7r-W1T31X1iEJMJU",
|
|
221
|
-
bookreg: "TFWDmf8a3_nw43GCm_CuYlYoylHAjCcFGbgHfDaGcsg",
|
|
222
|
-
thumb: "9v2GrtXpVpPWf9KBuTBdClARjjcDA3NqxFn8Kbn1f2M",
|
|
223
|
-
banner: "UuEwLRmuNmqLTDcKqgcxDEV1CWIR_uZ6rxzmKjODlrg",
|
|
224
|
-
proxy: "0uboI80S6vMxJD9Yn41Wdwnp9uAHEi4XLGQhBrp3qSQ",
|
|
225
|
-
render: "yXXAop3Yxm8QlZRzP46oRxZjCBp88YTpoSTPlTr4TcQ",
|
|
226
|
-
registry: "SNy4m-DrqxWl01YqGM4sxI8qCni-58re8uuJLvZPypY",
|
|
227
|
-
profile: "uEtSHyK9yDBABomez6ts3LI_8ULvO-rANSgDN_9OzEc",
|
|
228
210
|
}
|
|
229
211
|
|
|
230
212
|
const buildTags = (act, tags) => {
|
package/esm/lua/aos-sqlite.wasm
DELETED
|
Binary file
|
package/esm/lua/aos.wasm
DELETED
|
Binary file
|
package/esm/lua/aos2.lua
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
local count = 0
|
|
2
|
-
|
|
3
|
-
Handlers.add(
|
|
4
|
-
"Print",
|
|
5
|
-
"Print",
|
|
6
|
-
function (msg)
|
|
7
|
-
print('Hello World!')
|
|
8
|
-
local name = Send({Target = msg.Addr, Action = "Get", Tags = { Origin = msg.From, To = msg.Addr, ID = "1" } }).receive().Data
|
|
9
|
-
local name2 = Send({Target = msg.Addr2, Action = "Get2", Tags = { Origin = msg.From, To2 = msg.Addr2 } }).receive().Data
|
|
10
|
-
local name3 = Send({Target = msg.Addr, Action = "Get", Tags = { Origin = msg.From, To = msg.Addr, ID = "3" } }).receive().Data
|
|
11
|
-
msg.reply({ Data = name3 .. " printed!"})
|
|
12
|
-
local name4 = Send({Target = msg.Addr2, Action = "Get2", Tags = { Origin = msg.From, To2 = msg.Addr2 } }).receive().Data
|
|
13
|
-
msg.reply({ Data = name4 .. " printed!"})
|
|
14
|
-
end
|
|
15
|
-
)
|
|
16
|
-
|
|
17
|
-
Handlers.add(
|
|
18
|
-
"Get",
|
|
19
|
-
"Get",
|
|
20
|
-
function (msg)
|
|
21
|
-
count = count + 1
|
|
22
|
-
msg.reply({ Data = "Bob" .. count, Tags = { Ret = msg.From, Origin = msg.Origin, To = msg.To } })
|
|
23
|
-
end
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
Handlers.add(
|
|
27
|
-
"Get2",
|
|
28
|
-
"Get2",
|
|
29
|
-
function (msg)
|
|
30
|
-
count = count + 1
|
|
31
|
-
msg.reply({ Data = "Alice" .. count, Tags = { Ret = msg.From, Origin = msg.Origin, To = msg.To } })
|
|
32
|
-
end
|
|
33
|
-
)
|
package/esm/lua/atomic-asset.lua
DELETED
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
local bint = require('.bint')(256)
|
|
2
|
-
local json = require('json')
|
|
3
|
-
local base64 = require(".base64")
|
|
4
|
-
local ao = require("ao")
|
|
5
|
-
|
|
6
|
-
if Name ~= '<NAME>' then Name = '<NAME>' end
|
|
7
|
-
if Creator ~= '<CREATOR>' then Creator = '<CREATOR>' end
|
|
8
|
-
if Ticker ~= '<TICKER>' then Ticker = '<TICKER>' end
|
|
9
|
-
if Denomination ~= '<DENOMINATION>' then Denomination = '<DENOMINATION>' end
|
|
10
|
-
if not Balances then Balances = { ['<CREATOR>'] = '<BALANCE>' } end
|
|
11
|
-
|
|
12
|
-
Transferable = true
|
|
13
|
-
|
|
14
|
-
local function checkValidAddress(address)
|
|
15
|
-
if not address or type(address) ~= 'string' then
|
|
16
|
-
return false
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
return string.match(address, "^[%w%-_]+$") ~= nil and #address == 43
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
local function checkValidAmount(data)
|
|
23
|
-
return (math.type(tonumber(data)) == 'integer' or math.type(tonumber(data)) == 'float') and bint(data) > 0
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
local function decodeMessageData(data)
|
|
27
|
-
local status, decodedData = pcall(json.decode, data)
|
|
28
|
-
|
|
29
|
-
if not status or type(decodedData) ~= 'table' then
|
|
30
|
-
return false, nil
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
return true, decodedData
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
-- Read process state
|
|
37
|
-
Handlers.add('Info', Handlers.utils.hasMatchingTag('Action', 'Info'), function(msg)
|
|
38
|
-
ao.send({
|
|
39
|
-
Target = msg.From,
|
|
40
|
-
Action = 'Read-Success',
|
|
41
|
-
Data = json.encode({
|
|
42
|
-
Name = Name,
|
|
43
|
-
Ticker = Ticker,
|
|
44
|
-
Denomination = Denomination,
|
|
45
|
-
Balances = Balances,
|
|
46
|
-
Transferable = Transferable,
|
|
47
|
-
})
|
|
48
|
-
})
|
|
49
|
-
end)
|
|
50
|
-
|
|
51
|
-
-- Transfer balance to recipient (Data - { Recipient, Quantity })
|
|
52
|
-
Handlers.add('Transfer', Handlers.utils.hasMatchingTag('Action', 'Transfer'), function(msg)
|
|
53
|
-
if not Transferable then
|
|
54
|
-
ao.send({ Target = msg.From, Action = 'Validation-Error', Tags = { Status = 'Error', Message = 'Transfers are not allowed' } })
|
|
55
|
-
return
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
local data = {
|
|
59
|
-
Recipient = msg.Tags.Recipient,
|
|
60
|
-
Quantity = msg.Tags.Quantity
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if checkValidAddress(data.Recipient) and checkValidAmount(data.Quantity) then
|
|
64
|
-
-- Transfer is valid, calculate balances
|
|
65
|
-
if not Balances[data.Recipient] then
|
|
66
|
-
Balances[data.Recipient] = '0'
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
Balances[msg.From] = tostring(bint(Balances[msg.From]) - bint(data.Quantity))
|
|
70
|
-
Balances[data.Recipient] = tostring(bint(Balances[data.Recipient]) + bint(data.Quantity))
|
|
71
|
-
|
|
72
|
-
-- If new balance zeroes out then remove it from the table
|
|
73
|
-
if bint(Balances[msg.From]) <= 0 then
|
|
74
|
-
Balances[msg.From] = nil
|
|
75
|
-
end
|
|
76
|
-
if bint(Balances[data.Recipient]) <= 0 then
|
|
77
|
-
Balances[data.Recipient] = nil
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
local debitNoticeTags = {
|
|
81
|
-
Status = 'Success',
|
|
82
|
-
Message = 'Balance transferred, debit notice issued',
|
|
83
|
-
Recipient = msg.Tags.Recipient,
|
|
84
|
-
Quantity = msg.Tags.Quantity,
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
local creditNoticeTags = {
|
|
88
|
-
Status = 'Success',
|
|
89
|
-
Message = 'Balance transferred, credit notice issued',
|
|
90
|
-
Sender = msg.From,
|
|
91
|
-
Quantity = msg.Tags.Quantity,
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
for tagName, tagValue in pairs(msg) do
|
|
95
|
-
if string.sub(tagName, 1, 2) == 'X-' then
|
|
96
|
-
debitNoticeTags[tagName] = tagValue
|
|
97
|
-
creditNoticeTags[tagName] = tagValue
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
-- Send a debit notice to the sender
|
|
102
|
-
ao.send({
|
|
103
|
-
Target = msg.From,
|
|
104
|
-
Action = 'Debit-Notice',
|
|
105
|
-
Tags = debitNoticeTags,
|
|
106
|
-
Data = json.encode({
|
|
107
|
-
Recipient = data.Recipient,
|
|
108
|
-
Quantity = tostring(data.Quantity)
|
|
109
|
-
})
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
-- Send a credit notice to the recipient
|
|
113
|
-
ao.send({
|
|
114
|
-
Target = data.Recipient,
|
|
115
|
-
Action = 'Credit-Notice',
|
|
116
|
-
Tags = creditNoticeTags,
|
|
117
|
-
Data = json.encode({
|
|
118
|
-
Sender = msg.From,
|
|
119
|
-
Quantity = tostring(data.Quantity)
|
|
120
|
-
})
|
|
121
|
-
})
|
|
122
|
-
end
|
|
123
|
-
end)
|
|
124
|
-
|
|
125
|
-
-- Mint new tokens (Data - { Quantity })
|
|
126
|
-
Handlers.add('Mint', Handlers.utils.hasMatchingTag('Action', 'Mint'), function(msg)
|
|
127
|
-
local decodeCheck, data = decodeMessageData(msg.Data)
|
|
128
|
-
|
|
129
|
-
if decodeCheck and data then
|
|
130
|
-
-- Check if quantity is present
|
|
131
|
-
if not data.Quantity then
|
|
132
|
-
ao.send({ Target = msg.From, Action = 'Input-Error', Tags = { Status = 'Error', Message = 'Invalid arguments, required { Quantity }' } })
|
|
133
|
-
return
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
-- Check if quantity is a valid integer greater than zero
|
|
137
|
-
if not checkValidAmount(data.Quantity) then
|
|
138
|
-
ao.send({ Target = msg.From, Action = 'Validation-Error', Tags = { Status = 'Error', Message = 'Quantity must be an integer greater than zero' } })
|
|
139
|
-
return
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
-- Check if owner is sender
|
|
143
|
-
if msg.From ~= Owner then
|
|
144
|
-
ao.send({ Target = msg.From, Action = 'Validation-Error', Tags = { Status = 'Error', Message = 'Only the process owner can mint new tokens' } })
|
|
145
|
-
return
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
-- Mint request is valid, add tokens to the pool
|
|
149
|
-
if not Balances[Owner] then
|
|
150
|
-
Balances[Owner] = '0'
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
Balances[Owner] = tostring(bint(Balances[Owner]) + bint(data.Quantity))
|
|
154
|
-
|
|
155
|
-
ao.send({ Target = msg.From, Action = 'Mint-Success', Tags = { Status = 'Success', Message = 'Tokens minted' } })
|
|
156
|
-
else
|
|
157
|
-
ao.send({
|
|
158
|
-
Target = msg.From,
|
|
159
|
-
Action = 'Input-Error',
|
|
160
|
-
Tags = {
|
|
161
|
-
Status = 'Error',
|
|
162
|
-
Message = string.format('Failed to parse data, received: %s. %s', msg.Data,
|
|
163
|
-
'Data must be an object - { Quantity }')
|
|
164
|
-
}
|
|
165
|
-
})
|
|
166
|
-
end
|
|
167
|
-
end)
|
|
168
|
-
|
|
169
|
-
-- Read balance (Data - { Target })
|
|
170
|
-
Handlers.add('Balance', Handlers.utils.hasMatchingTag('Action', 'Balance'), function(msg)
|
|
171
|
-
local decodeCheck, data = decodeMessageData(msg.Data)
|
|
172
|
-
|
|
173
|
-
if decodeCheck and data then
|
|
174
|
-
-- Check if target is present
|
|
175
|
-
if not data.Target then
|
|
176
|
-
ao.send({ Target = msg.From, Action = 'Input-Error', Tags = { Status = 'Error', Message = 'Invalid arguments, required { Target }' } })
|
|
177
|
-
return
|
|
178
|
-
end
|
|
179
|
-
|
|
180
|
-
-- Check if target is a valid address
|
|
181
|
-
if not checkValidAddress(data.Target) then
|
|
182
|
-
ao.send({ Target = msg.From, Action = 'Validation-Error', Tags = { Status = 'Error', Message = 'Target is not a valid address' } })
|
|
183
|
-
return
|
|
184
|
-
end
|
|
185
|
-
|
|
186
|
-
-- Check if target has a balance
|
|
187
|
-
if not Balances[data.Target] then
|
|
188
|
-
ao.send({ Target = msg.From, Action = 'Read-Error', Tags = { Status = 'Error', Message = 'Target does not have a balance' } })
|
|
189
|
-
return
|
|
190
|
-
end
|
|
191
|
-
|
|
192
|
-
ao.send({
|
|
193
|
-
Target = msg.From,
|
|
194
|
-
Action = 'Read-Success',
|
|
195
|
-
Tags = { Status = 'Success', Message = 'Balance received' },
|
|
196
|
-
Data =
|
|
197
|
-
Balances[data.Target]
|
|
198
|
-
})
|
|
199
|
-
else
|
|
200
|
-
ao.send({
|
|
201
|
-
Target = msg.From,
|
|
202
|
-
Action = 'Input-Error',
|
|
203
|
-
Tags = {
|
|
204
|
-
Status = 'Error',
|
|
205
|
-
Message = string.format('Failed to parse data, received: %s. %s', msg.Data,
|
|
206
|
-
'Data must be an object - { Target }')
|
|
207
|
-
}
|
|
208
|
-
})
|
|
209
|
-
end
|
|
210
|
-
end)
|
|
211
|
-
|
|
212
|
-
-- Read balances
|
|
213
|
-
Handlers.add('Balances', Handlers.utils.hasMatchingTag('Action', 'Balances'),
|
|
214
|
-
function(msg) ao.send({ Target = msg.From, Action = 'Read-Success', Data = json.encode(Balances) }) end)
|
|
215
|
-
|
|
216
|
-
-- Initialize a request to add the uploaded asset to a profile
|
|
217
|
-
Handlers.add('Add-Asset-To-Profile', Handlers.utils.hasMatchingTag('Action', 'Add-Asset-To-Profile'), function(msg)
|
|
218
|
-
if checkValidAddress(msg.Tags.ProfileProcess) then
|
|
219
|
-
-- ao.assign({ Processes = { msg.Tags.ProfileProcess }, Message = ao.id })
|
|
220
|
-
ao.send({
|
|
221
|
-
Target = msg.Tags.ProfileProcess,
|
|
222
|
-
Action = 'Add-Uploaded-Asset',
|
|
223
|
-
Data = json.encode({
|
|
224
|
-
Id = ao.id,
|
|
225
|
-
Quantity = msg.Tags.Quantity or '0'
|
|
226
|
-
})
|
|
227
|
-
})
|
|
228
|
-
else
|
|
229
|
-
ao.send({
|
|
230
|
-
Target = msg.From,
|
|
231
|
-
Action = 'Input-Error',
|
|
232
|
-
Tags = {
|
|
233
|
-
Status = 'Error',
|
|
234
|
-
Message = 'ProfileProcess tag not specified or not a valid Process ID'
|
|
235
|
-
}
|
|
236
|
-
})
|
|
237
|
-
end
|
|
238
|
-
end)
|