@@ -49,82 +49,98 @@ main.init = function()
49
49
error (registerRes )
50
50
end
51
51
52
- ao .send ({
52
+ print (" Message reference: " .. msg .Nonce )
53
+ local startTime = os.time ()
54
+ local stateMsg = ao .send ({
53
55
Target = antId ,
54
56
Action = " State" ,
55
- })
57
+ }).receive (Handlers .utils .hasMatchingTag (" Action" , ActionMap .StateNotice ), function (msg )
58
+ return msg
59
+ end )
60
+ print (
61
+ " Time taken: "
62
+ .. os.time () - startTime
63
+ .. " "
64
+ .. " Message reference: "
65
+ .. msg .Nonce
66
+ .. " :"
67
+ .. stateMsg .Nonce
68
+ )
69
+
56
70
ao .send ({
57
71
Target = msg .From ,
58
72
Action = " Register-Notice" ,
59
73
})
60
- end )
61
- )
62
74
63
- Handlers .add (
64
- camel (ActionMap .StateNotice ),
65
- Handlers .utils .hasMatchingTag (" Action" , ActionMap .StateNotice ),
66
- ANT_DB_ADMIN :createSafeTransaction (function (msg )
67
- print (" Action: " .. ActionMap .StateNotice )
68
- local stateStatus , stateRes = pcall (utils .parseAntState , msg .Data )
69
- if not stateStatus then
70
- ao .send ({
71
- Target = msg .From ,
72
- Action = " State-Notice-Failure" ,
73
- [" Message-Id" ] = msg .Id ,
74
- Data = tostring (stateRes ),
75
- })
76
- error (stateRes )
77
- end
78
-
79
- -- Check if already registered and send notice of registration if not registered
80
- local isRegisteredStatus , isRegisteredRes = pcall (ANT_DB_ADMIN .isRegistered , ANT_DB_ADMIN , msg .From )
81
- if not isRegisteredStatus then
82
- ao .send ({
83
- Target = msg .From ,
84
- Action = " State-Notice-Failure" ,
85
- [" Message-Id" ] = msg .Id ,
86
- Data = isRegisteredRes ,
87
- })
88
- error (isRegisteredRes )
89
- end
90
- -- Register the ANT and send a notice if it is not already registered
91
- if isRegisteredRes == false then
92
- local registrationStatus , registrationRes =
93
- pcall (ANT_DB_ADMIN .register , ANT_DB_ADMIN , msg .From , tonumber (msg .Timestamp ))
94
- if not registrationStatus then
95
- ao .send ({
96
- Target = msg .From ,
97
- Action = " Register-Notice-Failure" ,
98
- [" Message-Id" ] = msg .Id ,
99
- Data = registrationRes ,
100
- })
101
- error (registrationRes )
102
- end
103
- end
104
-
105
- local aclUpdateStatus , aclUpdateRes = pcall (ANT_DB_ADMIN .updateACL , ANT_DB_ADMIN , msg .From , stateRes )
106
-
107
- if not aclUpdateStatus then
108
- ao .send ({
109
- Target = msg .From ,
110
- Action = " State-Notice-Failure" ,
111
- [" Message-Id" ] = msg .Id ,
112
- Data = aclUpdateRes ,
113
- })
114
- error (aclUpdateRes )
115
- end
116
-
117
- -- notify the ant that it has been registered in this action
118
- if isRegisteredRes == false then
119
- ao .send ({
120
- Target = msg .From ,
121
- Action = " Register-Notice" ,
122
- [" Message-Id" ] = msg .Id ,
123
- })
124
- end
75
+ return " I have returned"
125
76
end )
126
77
)
127
78
79
+ -- Handlers.add(
80
+ -- camel(ActionMap.StateNotice),
81
+ -- Handlers.utils.hasMatchingTag("Action", ActionMap.StateNotice),
82
+ -- ANT_DB_ADMIN:createSafeTransaction(function(msg)
83
+ -- print("Action: " .. ActionMap.StateNotice)
84
+ -- local stateStatus, stateRes = pcall(utils.parseAntState, msg.Data)
85
+ -- if not stateStatus then
86
+ -- ao.send({
87
+ -- Target = msg.From,
88
+ -- Action = "State-Notice-Failure",
89
+ -- ["Message-Id"] = msg.Id,
90
+ -- Data = tostring(stateRes),
91
+ -- })
92
+ -- error(stateRes)
93
+ -- end
94
+
95
+ -- -- Check if already registered and send notice of registration if not registered
96
+ -- local isRegisteredStatus, isRegisteredRes = pcall(ANT_DB_ADMIN.isRegistered, ANT_DB_ADMIN, msg.From)
97
+ -- if not isRegisteredStatus then
98
+ -- ao.send({
99
+ -- Target = msg.From,
100
+ -- Action = "State-Notice-Failure",
101
+ -- ["Message-Id"] = msg.Id,
102
+ -- Data = isRegisteredRes,
103
+ -- })
104
+ -- error(isRegisteredRes)
105
+ -- end
106
+ -- -- Register the ANT and send a notice if it is not already registered
107
+ -- if isRegisteredRes == false then
108
+ -- local registrationStatus, registrationRes =
109
+ -- pcall(ANT_DB_ADMIN.register, ANT_DB_ADMIN, msg.From, tonumber(msg.Timestamp))
110
+ -- if not registrationStatus then
111
+ -- ao.send({
112
+ -- Target = msg.From,
113
+ -- Action = "Register-Notice-Failure",
114
+ -- ["Message-Id"] = msg.Id,
115
+ -- Data = registrationRes,
116
+ -- })
117
+ -- error(registrationRes)
118
+ -- end
119
+ -- end
120
+
121
+ -- local aclUpdateStatus, aclUpdateRes = pcall(ANT_DB_ADMIN.updateACL, ANT_DB_ADMIN, msg.From, stateRes)
122
+
123
+ -- if not aclUpdateStatus then
124
+ -- ao.send({
125
+ -- Target = msg.From,
126
+ -- Action = "State-Notice-Failure",
127
+ -- ["Message-Id"] = msg.Id,
128
+ -- Data = aclUpdateRes,
129
+ -- })
130
+ -- error(aclUpdateRes)
131
+ -- end
132
+
133
+ -- -- notify the ant that it has been registered in this action
134
+ -- if isRegisteredRes == false then
135
+ -- ao.send({
136
+ -- Target = msg.From,
137
+ -- Action = "Register-Notice",
138
+ -- ["Message-Id"] = msg.Id,
139
+ -- })
140
+ -- end
141
+ -- end)
142
+ -- )
143
+
128
144
Handlers .add (
129
145
camel (ActionMap .AccessControlList ),
130
146
Handlers .utils .hasMatchingTag (" Action" , ActionMap .AccessControlList ),
0 commit comments