Skip to content

Commit

Permalink
fix(handlers): fix handlers for distributions
Browse files Browse the repository at this point in the history
  • Loading branch information
dtfiedler committed Jun 7, 2024
1 parent 6b67f4f commit f807280
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions contract/src/epochs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ function epochs.getObservationsForEpoch(epochNumber)
return epochs.getEpoch(epochNumber).observations or {}
end

function epochs.getDistributionsForEpoch(epochNumber)
return epochs.getEpoch(epochNumber).distributions or {}
end

function epochs.getPrescribedNamesForEpoch(epochNumber)
return epochs.getEpoch(epochNumber).prescribedNames or {}
end
Expand Down
4 changes: 2 additions & 2 deletions contract/src/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ end)
Handlers.add(ActionMap.Distributions, utils.hasMatchingTag("Action", ActionMap.Distributions), function(msg)
-- check if the epoch number is provided, if not get the epoch number from the timestamp
local checkAssertions = function()
assert(msg.Tags.EpochIndex or msg.Timestamp, "Epoch index or timestamp is required")
assert(msg.Tags.EpochIndex or msg.Timestamp or msg.Tags.Timestamp, "Epoch index or timestamp is required")
end

local inputStatus, inputResult = pcall(checkAssertions)
Expand All @@ -881,7 +881,7 @@ Handlers.add(ActionMap.Distributions, utils.hasMatchingTag("Action", ActionMap.D
return
end

local epochIndex = tonumber(msg.Tags.EpochIndex) or epochs.getEpochIndexFromTimestamp(tonumber(msg.Timestamp))
local epochIndex = tonumber(msg.Tags.EpochIndex) or epochs.getEpochIndexFromTimestamp(tonumber(msg.Timestamp or msg.Tags.Timestamp))
local distributions = epochs.getDistributionsForEpoch(epochIndex)
ao.send({ Target = msg.From, Data = json.encode(distributions) })
end)
Expand Down

0 comments on commit f807280

Please sign in to comment.