From 32da7f8000caeeb73d1482db57abce5a3c03fe25 Mon Sep 17 00:00:00 2001 From: atticusofsparta Date: Wed, 29 Jan 2025 10:20:18 -0600 Subject: [PATCH 1/3] fix(reply): add msg.reply to all apis --- src/common/main.lua | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/common/main.lua b/src/common/main.lua index 01e8a3e..22dd42b 100644 --- a/src/common/main.lua +++ b/src/common/main.lua @@ -90,6 +90,7 @@ function ant.init() local recipient = msg.Tags.Recipient if msg.From ~= Owner then utils.Send(msg, { + Target = msg.From, Action = "Transfer-Error", ["Message-Id"] = msg.Id, Error = "Insufficient Balance!", @@ -108,6 +109,7 @@ function ant.init() local balRes = balances.balance(addressToCheck, msg.Tags["Allow-Unsafe-Addresses"]) utils.Send(msg, { + Target = msg.From, Action = "Balance-Notice", Balance = tostring(balRes), Ticker = Ticker, @@ -123,13 +125,14 @@ function ant.init() bals[k] = tostring(v) end - utils.Send(msg, { Data = json.encode(bals) }) + utils.Send(msg, { Target = msg.From, Data = json.encode(bals) }) end) createActionHandler(TokenSpecActionMap.TotalSupply, function(msg) assert(msg.From ~= ao.id, "Cannot call Total-Supply from the same process!") utils.Send(msg, { + Target = msg.From, Action = "Total-Supply", Data = tostring(TotalSupply), Ticker = Ticker, @@ -149,6 +152,7 @@ function ant.init() Handlers = utils.getHandlerNames(Handlers), } utils.Send(msg, { + Target = msg.From, Action = "Info-Notice", Tags = info, Data = json.encode(info), @@ -225,8 +229,8 @@ function ant.init() return initialize.initializeANTState(msg.Data) end) - createActionHandler(ActionMap.State, function(msg) - notices.notifyState(msg, msg.From) + createActionHandler(ActionMap.State, function() + return utils.getState() end) -- IO Network Contract Handlers @@ -248,7 +252,7 @@ function ant.init() Name = name, }) - ao.send({ + utils.Send(msg, { Target = msg.From, Action = "Release-Name-Notice", Initiator = msg.From, @@ -275,7 +279,7 @@ function ant.init() ["Process-Id"] = antProcessIdToReassign, }) - ao.send({ + utils.Send(msg, { Target = msg.From, Action = "Reassign-Name-Notice", Initiator = msg.From, From 162b3edfa08342c67ab99b403c646c359bc60333 Mon Sep 17 00:00:00 2001 From: atticusofsparta Date: Wed, 29 Jan 2025 10:24:17 -0600 Subject: [PATCH 2/3] fix(version): update version and changelog --- CHANGELOG.md | 6 ++++++ version.mjs | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a389297..e7e90dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Fixed +- Added msg.reply to all APIs + +## [13] - [zh4at_Y_GKJMD3SOkZ5Yx7mG2JRRLc89huEOspPtHq4] - (2025-1-29) + +### Fixed + - Removed print with ID in Handler wrapper since ID can be null on dry runs. ## [12] - [mwCMAjglwV_96oEMEIi5epg_QXElOMzEcLkCUeQyGGo] - (2025-1-28) diff --git a/version.mjs b/version.mjs index 4ce3e81..d8b7f22 100644 --- a/version.mjs +++ b/version.mjs @@ -1,3 +1,3 @@ // TODO: make this an auto generated file -export default '12'; +export default '13'; From a7e4c5395489bf966e210cf57870eeda253b057a Mon Sep 17 00:00:00 2001 From: atticusofsparta Date: Wed, 29 Jan 2025 12:13:58 -0600 Subject: [PATCH 3/3] fix(reply): dont use utils.Send in boot because it will crash memory --- src/common/main.lua | 31 +++++++++++++------------------ test/evolve.test.mjs | 1 + 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/common/main.lua b/src/common/main.lua index 22dd42b..60df60a 100644 --- a/src/common/main.lua +++ b/src/common/main.lua @@ -333,6 +333,7 @@ function ant.init() AOS provides a _boot handler that is designed to load Lua code on boot. This handler OVERRIDES this and replaces it with our ANT state initialization handler. + NOTE: if we use utils.Send here memory blows up for some reason ]] Handlers.once("_boot", function(msg) return msg.Tags.Type == "Process" and Owner == msg.From @@ -343,28 +344,22 @@ function ant.init() initialize.initializeANTState(msg.Data) end, utils.errorHandler) if not status then - utils.Send( - msg, - notices.addForwardedTags(msg, { - Target = Owner, - Error = res or "", - Data = res or "", - Action = "Invalid-Boot-Notice", - ["Message-Id"] = msg.Id, - }) - ) + ao.send(notices.addForwardedTags(msg, { + Target = Owner, + Error = res or "", + Data = res or "", + Action = "Invalid-Boot-Notice", + ["Message-Id"] = msg.Id, + })) end end if Owner then - utils.Send( - msg, - notices.credit({ - From = msg.From, - Sender = Owner, - Recipient = Owner, - }) - ) + ao.send(notices.credit({ + From = msg.From, + Sender = Owner, + Recipient = Owner, + })) end if AntRegistryId then diff --git a/test/evolve.test.mjs b/test/evolve.test.mjs index fc79ac5..6563024 100644 --- a/test/evolve.test.mjs +++ b/test/evolve.test.mjs @@ -44,6 +44,7 @@ describe('aos Evolve', async () => { }, evolveResult.Memory, ); + assert(evalResult.Output.data); assert(evalResult.Output.data.includes('info')); });