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.
@@ -1,11 +0,0 @@
1
- if Name ~= '<NAME>' then Name = '<NAME>' end
2
- if Description ~= '<DESCRIPTION>' then Description = '<DESCRIPTION>' end
3
- if Thumbnail ~= '<THUMBNAIL>' then Thumbnail = '<THUMBNAIL>' end
4
- if Creator ~= '<CREATOR>' then Creator = '<CREATOR>' end
5
- if Ticker ~= '<TICKER>' then Ticker = '<TICKER>' end
6
- if Denomination ~= '<DENOMINATION>' then Denomination = '<DENOMINATION>' end
7
- if not Balances then Balances = { ['<CREATOR>'] = '<BALANCE>' } end
8
- if DateCreated ~= '<DATECREATED>' then DateCreated = '<DATECREATED>' end
9
- if not Collections then Collections = {} end
10
-
11
- ao.addAssignable("LIBRARY", { Id = '<LIBRARY>' })
@@ -1,202 +0,0 @@
1
- local json = require('json')
2
-
3
- -- Collections { Id, Name, Description, Creator, DateCreated, Banner, Thumbnail }[]
4
- if not Collections then Collections = {} end
5
-
6
- -- CollectionsByUser: { Creator: { CollectionIds } }
7
- if not CollectionsByUser then CollectionsByUser = {} end
8
-
9
- -- Add collection to registry
10
- Handlers.add('Add-Collection', Handlers.utils.hasMatchingTag('Action', 'Add-Collection'), function(msg)
11
- local data = {
12
- Id = msg.Tags.CollectionId,
13
- Name = msg.Tags.Name,
14
- Description = msg.Tags.Description,
15
- Creator = msg.Tags.Creator,
16
- DateCreated = msg.Tags.DateCreated,
17
- Banner = msg.Tags.Banner,
18
- Thumbnail = msg.Tags.Thumbnail
19
- }
20
-
21
- local requiredFields = {
22
- { key = 'Id', name = 'CollectionId' },
23
- { key = 'Name', name = 'Name' },
24
- { key = 'Creator', name = 'Creator' }
25
- }
26
-
27
- for _, field in ipairs(requiredFields) do
28
- if not data[field.key] or data[field.key] == '' then
29
- ao.send({
30
- Target = msg.From,
31
- Action = 'Action-Response',
32
- Tags = {
33
- Status = 'Error',
34
- Message = 'Invalid or missing ' .. field.name
35
- }
36
- })
37
- return
38
- end
39
- end
40
-
41
- for _, collection in ipairs(Collections) do
42
- if collection.Id == data.Id then
43
- ao.send({
44
- Target = msg.From,
45
- Action = 'Action-Response',
46
- Tags = {
47
- Status = 'Error',
48
- Message = 'Collection with this ID already exists'
49
- }
50
- })
51
- return
52
- end
53
- end
54
-
55
- table.insert(Collections, {
56
- Id = data.Id,
57
- Name = data.Name,
58
- Description = data.Description,
59
- Creator = data.Creator,
60
- DateCreated = data.DateCreated,
61
- Banner = data.Banner,
62
- Thumbnail = data.Thumbnail
63
- })
64
-
65
- if not CollectionsByUser[data.Creator] then
66
- CollectionsByUser[data.Creator] = {}
67
- end
68
- table.insert(CollectionsByUser[data.Creator], data.Id)
69
-
70
- ao.send({
71
- Target = msg.From,
72
- Action = 'Action-Response',
73
- Tags = {
74
- Status = 'Success',
75
- Message = 'Collection added successfully'
76
- }
77
- })
78
- end)
79
-
80
- -- Get collections by user
81
- Handlers.add('Get-Collections', Handlers.utils.hasMatchingTag('Action', 'Get-Collections'), function(msg)
82
- ao.send({
83
- Target = msg.From,
84
- Action = 'Action-Response',
85
- Tags = {
86
- Status = 'Success',
87
- Message = 'Collections fetched successfully'
88
- },
89
- Data = json.encode({ Collections = Collections })
90
- })
91
- end)
92
-
93
- -- Get collections by user
94
- Handlers.add('Get-Collections-By-User', Handlers.utils.hasMatchingTag('Action', 'Get-Collections-By-User'), function(msg)
95
- local creator = msg.Tags.Creator
96
-
97
- if not creator or creator == '' then
98
- ao.send({
99
- Target = msg.From,
100
- Action = 'Action-Response',
101
- Tags = {
102
- Status = 'Error',
103
- Message = 'Invalid or missing Creator'
104
- }
105
- })
106
- return
107
- end
108
-
109
- local collectionIds = CollectionsByUser[creator] or {}
110
- local userCollections = {}
111
-
112
- for _, collectionId in ipairs(collectionIds) do
113
- for _, collection in ipairs(Collections) do
114
- if collection.Id == collectionId then
115
- table.insert(userCollections, collection)
116
- break
117
- end
118
- end
119
- end
120
-
121
- ao.send({
122
- Target = msg.From,
123
- Action = 'Action-Response',
124
- Tags = {
125
- Status = 'Success',
126
- Message = 'Collections fetched successfully'
127
- },
128
- Data = json.encode({
129
- Creator = creator,
130
- Collections = userCollections
131
- })
132
- })
133
- end)
134
-
135
- -- Remove collection by ID
136
- Handlers.add('Remove-Collection', Handlers.utils.hasMatchingTag('Action', 'Remove-Collection'), function(msg)
137
- if msg.From ~= Owner and msg.From ~= ao.id then
138
- ao.send({
139
- Target = msg.From,
140
- Action = 'Authorization-Error',
141
- Tags = {
142
- Status = 'Error',
143
- Message = 'Unauthorized to access this handler'
144
- }
145
- })
146
- return
147
- end
148
-
149
- local collectionId = msg.Tags.CollectionId
150
-
151
- if not collectionId or collectionId == '' then
152
- ao.send({
153
- Target = msg.From,
154
- Action = 'Action-Response',
155
- Tags = {
156
- Status = 'Error',
157
- Message = 'Invalid or missing CollectionId'
158
- }
159
- })
160
- return
161
- end
162
-
163
- local collectionIndex = nil
164
- local collectionOwner = nil
165
-
166
- for index, collection in ipairs(Collections) do
167
- if collection.Id == collectionId then
168
- collectionIndex = index
169
- collectionOwner = collection.Creator
170
- break
171
- end
172
- end
173
-
174
- if not collectionIndex then
175
- ao.send({
176
- Target = msg.From,
177
- Action = 'Action-Response',
178
- Tags = {
179
- Status = 'Error',
180
- Message = 'Collection not found'
181
- }
182
- })
183
- return
184
- end
185
-
186
- table.remove(Collections, collectionIndex)
187
- for i, id in ipairs(CollectionsByUser[collectionOwner]) do
188
- if id == collectionId then
189
- table.remove(CollectionsByUser[collectionOwner], i)
190
- break
191
- end
192
- end
193
-
194
- ao.send({
195
- Target = msg.From,
196
- Action = 'Action-Response',
197
- Tags = {
198
- Status = 'Success',
199
- Message = 'Collection removed successfully'
200
- }
201
- })
202
- end)
@@ -1,173 +0,0 @@
1
- local json = require('json')
2
-
3
- if Name ~= '<NAME>' then Name = '<NAME>' end
4
- if Description ~= '<DESCRIPTION>' then Description = '<DESCRIPTION>' end
5
- if Creator ~= '<CREATOR>' then Creator = '<CREATOR>' end
6
- if Banner ~= '<BANNER>' then Banner = '<BANNER>' end
7
- if Thumbnail ~= '<THUMBNAIL>' then Thumbnail = '<THUMBNAIL>' end
8
-
9
- if DateCreated ~= '<DATECREATED>' then DateCreated = '<DATECREATED>' end
10
- if LastUpdate ~= '<LASTUPDATE>' then LastUpdate = '<LASTUPDATE>' end
11
-
12
- -- Assets: Id[]
13
- if not Assets then Assets = {} end
14
-
15
- local function decodeMessageData(data)
16
- local status, decodedData = pcall(json.decode, data)
17
-
18
- if not status or type(decodedData) ~= 'table' then
19
- return false, nil
20
- end
21
-
22
- return true, decodedData
23
- end
24
-
25
- local function assetExists(assetId)
26
- for _, id in ipairs(Assets) do
27
- if id == assetId then
28
- return true
29
- end
30
- end
31
- return false
32
- end
33
-
34
- local function checkValidAddress(address)
35
- if not address or type(address) ~= 'string' then
36
- return false
37
- end
38
-
39
- return string.match(address, "^[%w%-_]+$") ~= nil and #address == 43
40
- end
41
-
42
- Handlers.add('Info', Handlers.utils.hasMatchingTag('Action', 'Info'), function(msg)
43
- ao.send({
44
- Target = msg.From,
45
- Data = json.encode({
46
- Name = Name,
47
- Description = Description,
48
- Creator = Creator,
49
- Banner = Banner,
50
- Thumbnail = Thumbnail,
51
- DateCreated = DateCreated,
52
- Assets = Assets
53
- })
54
- })
55
- end)
56
-
57
- -- Add or remove assets
58
- Handlers.add('Update-Assets', Handlers.utils.hasMatchingTag('Action', 'Update-Assets'), function(msg)
59
- if msg.From ~= Owner and msg.From ~= ao.id and msg.From ~= Creator then
60
- ao.send({
61
- Target = msg.From,
62
- Action = 'Authorization-Error',
63
- Tags = {
64
- Status = 'Error',
65
- Message = 'Unauthorized to access this handler'
66
- }
67
- })
68
- return
69
- end
70
-
71
- local decodeCheck, data = decodeMessageData(msg.Data)
72
-
73
- if decodeCheck and data then
74
- if not data.AssetIds or type(data.AssetIds) ~= 'table' or #data.AssetIds == 0 then
75
- ao.send({
76
- Target = msg.From,
77
- Action = 'Action-Response',
78
- Tags = {
79
- Status = 'Error',
80
- Message = 'Invalid or empty AssetIds list'
81
- }
82
- })
83
- return
84
- end
85
-
86
- if not data.UpdateType or (data.UpdateType ~= 'Add' and data.UpdateType ~= 'Remove') then
87
- ao.send({
88
- Target = msg.From,
89
- Action = 'Action-Response',
90
- Tags = {
91
- Status = 'Error',
92
- Message = 'UpdateType argument required (Add | Remove)'
93
- }
94
- })
95
- return
96
- end
97
-
98
- if data.UpdateType == 'Add' then
99
- for _, assetId in ipairs(data.AssetIds) do
100
- if not assetExists(assetId) then
101
- table.insert(Assets, assetId)
102
- ao.send({
103
- Target = assetId,
104
- Action = 'Add-To-Collection-Success',
105
- Tags = {}
106
- })
107
- end
108
- end
109
- end
110
-
111
- if data.UpdateType == 'Remove' then
112
- for _, assetId in ipairs(data.AssetIds) do
113
- for i, id in ipairs(Assets) do
114
- if id == assetId then
115
- table.remove(Assets, i)
116
- ao.send({
117
- Target = assetId,
118
- Action = 'Remove-From-Collection-Success',
119
- Tags = {}
120
- })
121
- break
122
- end
123
- end
124
- end
125
- end
126
-
127
- LastUpdate = msg.Timestamp
128
-
129
- ao.send({
130
- Target = msg.From,
131
- Action = 'Action-Response',
132
- Tags = {
133
- Status = 'Success',
134
- Message = 'Assets updated successfully'
135
- }
136
- })
137
- else
138
- ao.send({
139
- Target = msg.From,
140
- Action = 'Input-Error',
141
- Tags = {
142
- Status = 'Error',
143
- Message = string.format('Failed to parse data, received: %s. %s',
144
- msg.Data,
145
- 'Data must be an object - { AssetIds: [], UpdateType }')
146
- }
147
- })
148
- end
149
- end)
150
-
151
- -- Initialize a request to add the uploaded asset to a profile
152
- Handlers.add('Add-Collection-To-Profile', Handlers.utils.hasMatchingTag('Action', 'Add-Collection-To-Profile'), function(msg)
153
- if checkValidAddress(msg.Tags.ProfileProcess) then
154
- -- ao.assign({Processes = {msg.Tags.ProfileProcess}, Message = ao.id})
155
- ao.send({
156
- Target = msg.Tags.ProfileProcess,
157
- Action = 'Add-Collection',
158
- Data = json.encode({
159
- Id = ao.id,
160
- Name = Name
161
- })
162
- })
163
- else
164
- ao.send({
165
- Target = msg.From,
166
- Action = 'Input-Error',
167
- Tags = {
168
- Status = 'Error',
169
- Message = 'ProfileProcess tag not specified or not a valid Process ID'
170
- }
171
- })
172
- end
173
- end)
@@ -1,173 +0,0 @@
1
- local json = require('json')
2
-
3
- if Name ~= '<NAME>' then Name = '<NAME>' end
4
- if Description ~= '<DESCRIPTION>' then Description = '<DESCRIPTION>' end
5
- if Creator ~= '<CREATOR>' then Creator = '<CREATOR>' end
6
- if Banner ~= '<BANNER>' then Banner = '<BANNER>' end
7
- if Thumbnail ~= '<THUMBNAIL>' then Thumbnail = '<THUMBNAIL>' end
8
-
9
- if DateCreated ~= '<DATECREATED>' then DateCreated = '<DATECREATED>' end
10
- if LastUpdate ~= '<LASTUPDATE>' then LastUpdate = '<LASTUPDATE>' end
11
-
12
- -- Assets: Id[]
13
- if not Assets then Assets = {} end
14
-
15
- local function decodeMessageData(data)
16
- local status, decodedData = pcall(json.decode, data)
17
-
18
- if not status or type(decodedData) ~= 'table' then
19
- return false, nil
20
- end
21
-
22
- return true, decodedData
23
- end
24
-
25
- local function assetExists(assetId)
26
- for _, id in ipairs(Assets) do
27
- if id == assetId then
28
- return true
29
- end
30
- end
31
- return false
32
- end
33
-
34
- local function checkValidAddress(address)
35
- if not address or type(address) ~= 'string' then
36
- return false
37
- end
38
-
39
- return string.match(address, "^[%w%-_]+$") ~= nil and #address == 43
40
- end
41
-
42
- Handlers.add('Info', Handlers.utils.hasMatchingTag('Action', 'Info'), function(msg)
43
- ao.send({
44
- Target = msg.From,
45
- Data = json.encode({
46
- Name = Name,
47
- Description = Description,
48
- Creator = Creator,
49
- Banner = Banner,
50
- Thumbnail = Thumbnail,
51
- DateCreated = DateCreated,
52
- Assets = Assets
53
- })
54
- })
55
- end)
56
-
57
- -- Add or remove assets
58
- Handlers.add('Update-Assets', Handlers.utils.hasMatchingTag('Action', 'Update-Assets'), function(msg)
59
- if msg.From ~= Owner and msg.From ~= ao.id and msg.From ~= Creator then
60
- ao.send({
61
- Target = msg.From,
62
- Action = 'Authorization-Error',
63
- Tags = {
64
- Status = 'Error',
65
- Message = 'Unauthorized to access this handler'
66
- }
67
- })
68
- return
69
- end
70
-
71
- local decodeCheck, data = decodeMessageData(msg.Data)
72
-
73
- if decodeCheck and data then
74
- if not data.AssetIds or type(data.AssetIds) ~= 'table' or #data.AssetIds == 0 then
75
- ao.send({
76
- Target = msg.From,
77
- Action = 'Action-Response',
78
- Tags = {
79
- Status = 'Error',
80
- Message = 'Invalid or empty AssetIds list'
81
- }
82
- })
83
- return
84
- end
85
-
86
- if not data.UpdateType or (data.UpdateType ~= 'Add' and data.UpdateType ~= 'Remove') then
87
- ao.send({
88
- Target = msg.From,
89
- Action = 'Action-Response',
90
- Tags = {
91
- Status = 'Error',
92
- Message = 'UpdateType argument required (Add | Remove)'
93
- }
94
- })
95
- return
96
- end
97
-
98
- if data.UpdateType == 'Add' then
99
- for _, assetId in ipairs(data.AssetIds) do
100
- if not assetExists(assetId) then
101
- table.insert(Assets, assetId)
102
- ao.send({
103
- Target = assetId,
104
- Action = 'Add-To-Collection-Success',
105
- Tags = {}
106
- })
107
- end
108
- end
109
- end
110
-
111
- if data.UpdateType == 'Remove' then
112
- for _, assetId in ipairs(data.AssetIds) do
113
- for i, id in ipairs(Assets) do
114
- if id == assetId then
115
- table.remove(Assets, i)
116
- ao.send({
117
- Target = assetId,
118
- Action = 'Remove-From-Collection-Success',
119
- Tags = {}
120
- })
121
- break
122
- end
123
- end
124
- end
125
- end
126
-
127
- LastUpdate = msg.Timestamp
128
-
129
- ao.send({
130
- Target = msg.From,
131
- Action = 'Action-Response',
132
- Tags = {
133
- Status = 'Success',
134
- Message = 'Assets updated successfully'
135
- }
136
- })
137
- else
138
- ao.send({
139
- Target = msg.From,
140
- Action = 'Input-Error',
141
- Tags = {
142
- Status = 'Error',
143
- Message = string.format('Failed to parse data, received: %s. %s',
144
- msg.Data,
145
- 'Data must be an object - { AssetIds: [], UpdateType }')
146
- }
147
- })
148
- end
149
- end)
150
-
151
- -- Initialize a request to add the uploaded asset to a profile
152
- Handlers.add('Add-Collection-To-Profile', Handlers.utils.hasMatchingTag('Action', 'Add-Collection-To-Profile'), function(msg)
153
- if checkValidAddress(msg.Tags.ProfileProcess) then
154
- -- ao.assign({Processes = {msg.Tags.ProfileProcess}, Message = ao.id})
155
- ao.send({
156
- Target = msg.Tags.ProfileProcess,
157
- Action = 'Add-Collection',
158
- Data = json.encode({
159
- Id = ao.id,
160
- Name = Name
161
- })
162
- })
163
- else
164
- ao.send({
165
- Target = msg.From,
166
- Action = 'Input-Error',
167
- Tags = {
168
- Status = 'Error',
169
- Message = 'ProfileProcess tag not specified or not a valid Process ID'
170
- }
171
- })
172
- end
173
- end)