Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions patches/2025-11-06-primary-names-hb-sync-fix.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
--[[
Updates the hyperbeam patch message for primary names to use PrimaryNameInfo for the owners mapping
to allow for sdk compatible lookups on hyperbeam.

Reviewers: Dylan, Ariel, Atticus
]]
--

_G.package.loaded[".src.hb"].createPrimaryNamesPatch = function()
local primaryNames = require(".src.primary_names")
---@type {names: table<string, string>, owners: table<string, PrimaryNameInfo>, requests: table<string, table<string, string>>}
local affectedPrimaryNamesAddresses = {
names = {},
---@type table<string, PrimaryNameInfo>
owners = {},
requests = {},
}

-- if no changes, return early. This will allow downstream code to not send the patch state for this key ('primary-names')
if
next(_G.HyperbeamSync.primaryNames.names) == nil
and next(_G.HyperbeamSync.primaryNames.owners) == nil
and next(_G.HyperbeamSync.primaryNames.requests) == nil
then
return nil
end

-- build the affected primary names addresses table for the patch message
for name, _ in pairs(_G.HyperbeamSync.primaryNames.names) do
-- we need to send an empty string to remove the name
affectedPrimaryNamesAddresses.names[name] = PrimaryNames.names[name] or ""
end
for owner, _ in pairs(_G.HyperbeamSync.primaryNames.owners) do
-- we need to send an empty table to remove the owner primary name data
affectedPrimaryNamesAddresses.owners[owner] = primaryNames.getPrimaryNameDataWithOwnerFromAddress(owner) or {}
end
for address, _ in pairs(_G.HyperbeamSync.primaryNames.requests) do
-- we need to send an empty table to remove the request
affectedPrimaryNamesAddresses.requests[address] = PrimaryNames.requests[address] or {}
end

-- Setting the property to {} will nuke the entire table from patch device state
-- We do this because we want to remove the entire table from patch device state if it's empty
if next(PrimaryNames.names) == nil then
affectedPrimaryNamesAddresses.names = {}
-- setting the property to nil will remove it from the patch message entirely to avoid sending an empty table and nuking patch device state
-- We do this to AVOID sending an empty table and nuking patch device state if our lua state is not empty.
elseif next(affectedPrimaryNamesAddresses.names) == nil then
affectedPrimaryNamesAddresses.names = nil
end

if next(PrimaryNames.owners) == nil then
affectedPrimaryNamesAddresses.owners = {}
elseif next(affectedPrimaryNamesAddresses.owners) == nil then
affectedPrimaryNamesAddresses.owners = nil
end

if next(PrimaryNames.requests) == nil then
affectedPrimaryNamesAddresses.requests = {}
elseif next(affectedPrimaryNamesAddresses.requests) == nil then
affectedPrimaryNamesAddresses.requests = nil
end

-- if we're not sending any data, return nil which will allow downstream code to not send the patch message
-- We do this to AVOID sending an empty table and nuking patch device state if our lua state is not empty.
if next(affectedPrimaryNamesAddresses) == nil then
return nil
end

return affectedPrimaryNamesAddresses
end
6 changes: 4 additions & 2 deletions src/hb.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
-- hb.lua needs to be in its own file and not in balances.lua to avoid circular dependencies
local hb = {}
local primaryNames = require(".src.primary_names")

---@return table<string, string>|nil affectedBalancesAddresses table of addresses and their balance values as strings
function hb.createBalancesPatch()
Expand Down Expand Up @@ -31,9 +32,10 @@ end

---@return PrimaryNames|nil affectedPrimaryNamesAddresses
function hb.createPrimaryNamesPatch()
---@type PrimaryNames
---@type {names: table<string, string>, owners: table<string, PrimaryNameInfo>, requests: table<string, table<string, string>>}
local affectedPrimaryNamesAddresses = {
names = {},
---@type table<string, PrimaryNameInfo>
owners = {},
requests = {},
}
Expand All @@ -54,7 +56,7 @@ function hb.createPrimaryNamesPatch()
end
for owner, _ in pairs(_G.HyperbeamSync.primaryNames.owners) do
-- we need to send an empty table to remove the owner primary name data
affectedPrimaryNamesAddresses.owners[owner] = PrimaryNames.owners[owner] or {}
affectedPrimaryNamesAddresses.owners[owner] = primaryNames.getPrimaryNameDataWithOwnerFromAddress(owner) or {}
end
for address, _ in pairs(_G.HyperbeamSync.primaryNames.requests) do
-- we need to send an empty table to remove the request
Expand Down
1 change: 0 additions & 1 deletion src/primary_names.lua
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ function primaryNames.getPrimaryNameDataWithOwnerFromAddress(address)
return nil
end
return {

owner = address,
name = nameData.name,
startTimestamp = nameData.startTimestamp,
Expand Down
Loading