From a50e55663048c46434b76b6341515d81396fe52b Mon Sep 17 00:00:00 2001 From: dtfiedler Date: Mon, 24 Jun 2024 10:38:46 -0600 Subject: [PATCH 1/4] fix(tags): use ans-116 format for all tags --- src/arns.lua | 6 +++--- src/main.lua | 47 ++++++++++++++++++++++++----------------------- test/arns.test.js | 18 +++++++++--------- 3 files changed, 36 insertions(+), 35 deletions(-) diff --git a/src/arns.lua b/src/arns.lua index 729e35f..1d318ea 100644 --- a/src/arns.lua +++ b/src/arns.lua @@ -307,7 +307,7 @@ end function arns.getTokenCost(intendedAction) local tokenCost = 0 - if intendedAction.intent == "BuyRecord" then + if intendedAction.intent == "Buy-Record" then local purchaseType = intendedAction.purchaseType local years = intendedAction.years local name = intendedAction.name @@ -316,7 +316,7 @@ function arns.getTokenCost(intendedAction) assert(type(name) == "string", "Name is required and must be a string.") local baseFee = demand.getFees()[#name] tokenCost = arns.calculateRegistrationFee(purchaseType, baseFee, years, demand.getDemandFactor()) - elseif intendedAction.intent == "ExtendLease" then + elseif intendedAction.intent == "Extend-Lease" then local name = intendedAction.name local years = intendedAction.years assert(type(name) == "string", "Name is required and must be a string.") @@ -331,7 +331,7 @@ function arns.getTokenCost(intendedAction) local years = intendedAction.years local baseFee = demand.getFees()[#intendedAction.name] tokenCost = arns.calculateExtensionFee(baseFee, years, demand.getDemandFactor()) - elseif intendedAction.intent == "IncreaseUndernameLimit" then + elseif intendedAction.intent == "Increase-Undername-Limit" then local name = intendedAction.name local qty = intendedAction.quantity local currentTimestamp = intendedAction.currentTimestamp diff --git a/src/main.lua b/src/main.lua index e9e5570..1659bdb 100644 --- a/src/main.lua +++ b/src/main.lua @@ -33,39 +33,40 @@ local ActionMap = { Transfer = "Transfer", Balance = "Balance", Balances = "Balances", - DemandFactor = "DemandFactor", + DemandFactor = "Demand-Factor", -- EPOCH READ APIS Epochs = "Epochs", Epoch = "Epoch", - PrescribedObservers = "EpochPrescribedObservers", - PrescribedNames = "EpochPrescribedNames", - Observations = "EpochObservations", - Distributions = "EpochDistributions", + PrescribedObservers = "Epoch-Prescribed-Observers", + PrescribedNames = "Epoch-Prescribed-Names", + Observations = "Epoch-Observations", + Distributions = "Epoch-Distributions", + -- hypenated for all of these -- NAME REGISTRY READ APIS Record = "Record", Records = "Records", - ReservedNames = "ReservedNames", - ReservedName = "ReservedName", - TokenCost = "TokenCost", + ReservedNames = "Reserved-Names", + ReservedName = "Reserved-Name", + TokenCost = "Token-Cost", -- GATEWAY REGISTRY READ APIS Gateway = "Gateway", Gateways = "Gateways", -- writes - CreateVault = "CreateVault", - VaultedTransfer = "VaultedTransfer", - ExtendVault = "ExtendVault", - IncreaseVault = "IncreaseVault", - BuyRecord = "BuyRecord", - ExtendLease = "ExtendLease", - IncreaseUndernameLimit = "IncreaseUndernameLimit", - JoinNetwork = "JoinNetwork", - LeaveNetwork = "LeaveNetwork", - IncreaseOperatorStake = "IncreaseOperatorStake", - DecreaseOperatorStake = "DecreaseOperatorStake", - UpdateGatewaySettings = "UpdateGatewaySettings", - SaveObservations = "SaveObservations", - DelegateStake = "DelegateStake", - DecreaseDelegateStake = "DecreaseDelegateStake", + CreateVault = "Create-Vault", + VaultedTransfer = "Vaulted-Transfer", + ExtendVault = "Extend-Vault", + IncreaseVault = "Increase-Vault", + BuyRecord = "Buy-Record", + ExtendLease = "Extend-Lease", + IncreaseUndernameLimit = "Increase-Undername-Limit", + JoinNetwork = "Join-Network", + LeaveNetwork = "Leave-Network", + IncreaseOperatorStake = "Increase-Operator-Stake", + DecreaseOperatorStake = "Decrease-Operator-Stake", + UpdateGatewaySettings = "Update-Gateway-Settings", + SaveObservations = "Save-Observations", + DelegateStake = "Delegate-Stake", + DecreaseDelegateStake = "Decrease-Delegate-Stake", } -- Write handlers diff --git a/test/arns.test.js b/test/arns.test.js index 4b0ad78..0d28935 100644 --- a/test/arns.test.js +++ b/test/arns.test.js @@ -24,7 +24,7 @@ describe('ArNS', async () => { it('should increase the undernames', async () => { const buyUndernameResult = await handle({ Tags: [ - { name: 'Action', value: 'BuyRecord' }, + { name: 'Action', value: 'Buy-Record' }, { name: 'Name', value: 'test-name' }, { name: 'PurchaseType', value: 'lease' }, { name: 'Years', value: '1' }, @@ -34,7 +34,7 @@ describe('ArNS', async () => { const increaseUndernameResult = await handle( { Tags: [ - { name: 'Action', value: 'IncreaseUndernameLimit' }, + { name: 'Action', value: 'Increase-Undername-Limit' }, { name: 'Name', value: 'test-name' }, { name: 'Quantity', value: '1' }, ], @@ -58,8 +58,8 @@ describe('ArNS', async () => { it('should get the costs buy record correctly', async () => { const result = await handle({ Tags: [ - { name: 'Action', value: 'TokenCost' }, - { name: 'Intent', value: 'BuyRecord' }, + { name: 'Action', value: 'Token-Cost' }, + { name: 'Intent', value: 'Buy-Record' }, { name: 'Name', value: 'test-name' }, { name: 'PurchaseType', value: 'lease' }, { name: 'Years', value: '1' }, @@ -73,7 +73,7 @@ describe('ArNS', async () => { it('should get the costs increase undername correctly', async () => { const buyUndernameResult = await handle({ Tags: [ - { name: 'Action', value: 'BuyRecord' }, + { name: 'Action', value: 'Buy-Record' }, { name: 'Name', value: 'test-name' }, { name: 'PurchaseType', value: 'lease' }, { name: 'Years', value: '1' }, @@ -83,8 +83,8 @@ describe('ArNS', async () => { const result = await handle( { Tags: [ - { name: 'Action', value: 'TokenCost' }, - { name: 'Intent', value: 'IncreaseUndernameLimit' }, + { name: 'Action', value: 'Token-Cost' }, + { name: 'Intent', value: 'Increase-Undername-Limit' }, { name: 'Name', value: 'test-name' }, { name: 'Quantity', value: '1' }, ], @@ -99,7 +99,7 @@ describe('ArNS', async () => { it('should get the cost of increasing a lease correctly', async () => { const buyUndernameResult = await handle({ Tags: [ - { name: 'Action', value: 'BuyRecord' }, + { name: 'Action', value: 'Buy-Record' }, { name: 'Name', value: 'test-name' }, { name: 'PurchaseType', value: 'lease' }, { name: 'Years', value: '1' }, @@ -119,7 +119,7 @@ describe('ArNS', async () => { const extendResult = await handle( { Tags: [ - { name: 'Action', value: 'ExtendLease' }, + { name: 'Action', value: 'Extend-Lease' }, { name: 'Name', value: 'test-name' }, { name: 'Years', value: '1' }, ], From 7444defe831767dcbbcabb900d3c5a83f7fce16a Mon Sep 17 00:00:00 2001 From: dtfiedler Date: Mon, 24 Jun 2024 11:29:30 -0600 Subject: [PATCH 2/4] fix(tags): follow ans-116 for all tags --- src/constants.lua | 2 +- src/main.lua | 67 ++++++++++++++++++++++++++++------------------- test/arns.test.js | 16 +++++------ 3 files changed, 49 insertions(+), 36 deletions(-) diff --git a/src/constants.lua b/src/constants.lua index 2ebbb40..123a26f 100644 --- a/src/constants.lua +++ b/src/constants.lua @@ -88,7 +88,7 @@ constants.genesisFees = { [48] = 400000000, [49] = 400000000, [50] = 400000000, - [51] = 400000000, + [51] = 400 * 000000, } return constants diff --git a/src/main.lua b/src/main.lua index 1659bdb..ba79132 100644 --- a/src/main.lua +++ b/src/main.lua @@ -136,7 +136,7 @@ end) Handlers.add(ActionMap.CreateVault, utils.hasMatchingTag("Action", ActionMap.CreateVault), function(msg) local function checkAssertions() assert( - tonumber(msg.Tags.LockLength) > 0 and utils.isInteger(tonumber(msg.Tags.LockLength)), + tonumber(msg.Tags["Lock-Length"]) > 0 and utils.isInteger(tonumber(msg.Tags.LockLength)), "Invalid lock length. Must be integer greater than 0" ) assert( @@ -156,7 +156,8 @@ Handlers.add(ActionMap.CreateVault, utils.hasMatchingTag("Action", ActionMap.Cre return end - local result, err = balances.createVault(msg.From, msg.Tags.Quantity, msg.Tags.LockLength, msg.Timestamp, msg.Id) + local result, err = + balances.createVault(msg.From, msg.Tags.Quantity, tonumber(msg.Tags["Lock-Length"]), msg.Timestamp, msg.Id) if err then ao.send({ Target = msg.From, @@ -176,7 +177,7 @@ Handlers.add(ActionMap.VaultedTransfer, utils.hasMatchingTag("Action", ActionMap local function checkAssertions() assert(utils.isValidArweaveAddress(msg.Tags.Recipient), "Invalid recipient") assert( - tonumber(msg.Tags.LockLength) > 0 and utils.isInteger(tonumber(msg.Tags.LockLength)), + tonumber(msg.Tags["Lock-Length"]) > 0 and utils.isInteger(tonumber(msg.Tags["Lock-Length"])), "Invalid lock length. Must be integer greater than 0" ) assert( @@ -199,8 +200,8 @@ Handlers.add(ActionMap.VaultedTransfer, utils.hasMatchingTag("Action", ActionMap local result, err = balances.vaultedTransfer( msg.From, msg.Tags.Recipient, - msg.Tags.Quantity, - msg.Tags.LockLength, + tonumber(msg.Tags.Quantity), + tonumber(msg.Tags.LockLength), msg.Timestamp, msg.Id ) @@ -262,7 +263,7 @@ end) Handlers.add(ActionMap.IncreaseVault, utils.hasMatchingTag("Action", ActionMap.IncreaseVault), function(msg) local function checkAssertions() - assert(utils.isValidArweaveAddress(msg.Tags.VaultId), "Invalid vault id") + assert(utils.isValidArweaveAddress(msg.Tags["Vault-Id"]), "Invalid vault id") assert( tonumber(msg.Tags.Quantity) > 0 and utils.isInteger(tonumber(msg.Tags.Quantity)), "Invalid quantity. Must be integer greater than 0" @@ -280,7 +281,7 @@ Handlers.add(ActionMap.IncreaseVault, utils.hasMatchingTag("Action", ActionMap.I return end - local result, err = balances.increaseVault(msg.From, msg.Tags.Quantity, msg.Tags.VaultId, msg.Timestamp) + local result, err = balances.increaseVault(msg.From, msg.Tags.Quantity, msg.Tags["Vault-Id"], msg.Timestamp) if err then ao.send({ Target = msg.From, @@ -299,7 +300,8 @@ end) Handlers.add(ActionMap.BuyRecord, utils.hasMatchingTag("Action", ActionMap.BuyRecord), function(msg) local checkAssertions = function() assert(type(msg.Tags.Name) == "string", "Invalid name") - assert(type(msg.Tags.PurchaseType) == "string", "Invalid purchase type") + assert(type(msg.Tags["Purchase-Type"]) == "string", "Invalid purchase type") + assert(utils.isValidArweaveAddress(msg.Tags["Process-Id"]), "Invalid process id") assert( tonumber(msg.Tags.Years) > 0 and tonumber(msg.Tags.Years) < 5 and utils.isInteger(tonumber(msg.Tags.Years)), "Invalid years. Must be integer between 1 and 5" @@ -320,11 +322,11 @@ Handlers.add(ActionMap.BuyRecord, utils.hasMatchingTag("Action", ActionMap.BuyRe local status, result = pcall( arns.buyRecord, msg.Tags.Name, - msg.Tags.PurchaseType, + msg.Tags["Purchase-Type"], tonumber(msg.Tags.Years), msg.From, msg.Timestamp, - msg.Tags.ProcessId + msg.Tags["Process-Id"] ) if not status then ao.send({ @@ -463,7 +465,7 @@ Handlers.add(ActionMap.TokenCost, utils.hasMatchingTag("Action", ActionMap.Token name = msg.Tags.Name, years = tonumber(msg.Tags.Years) or 1, quantity = tonumber(msg.Tags.Quantity), - purchaseType = msg.Tags.PurchaseType or "lease", + purchaseType = msg.Tags["Purchase-Type"] or "lease", currentTimestamp = tonumber(msg.Timestamp), }) if not status then @@ -488,18 +490,18 @@ Handlers.add(ActionMap.JoinNetwork, utils.hasMatchingTag("Action", ActionMap.Joi fqdn = msg.Tags.FQDN, port = tonumber(msg.Tags.Port) or 443, protocol = msg.Tags.Protocol or "https", - allowDelegatedStaking = msg.Tags.AllowDelegatedStaking == "true", - minDelegatedStake = tonumber(msg.Tags.MinDelegatedStake), - delegateRewardShareRatio = tonumber(msg.Tags.DelegateRewardShareRatio) or 0, + allowDelegatedStaking = msg.Tags["Allow-Delegated-Staking"] == "true", + minDelegatedStake = tonumber(msg.Tags["Min-Delegated-Stake"]), + delegateRewardShareRatio = tonumber(msg.Tags["Delegate-Reward-Share-Ratio"]) or 0, properties = msg.Tags.Properties or "FH1aVetOoulPGqgYukj0VE0wIhDy90WiQoV3U2PeY44", - autoStake = msg.Tags.AutoStake == "true", + autoStake = msg.Tags["Auto-Stake"] == "true", } - local observerAddress = msg.Tags.ObserverAddress or msg.Tags.From + local observerAddress = msg.Tags["Observer-Address"] or msg.Tags.From local status, result = pcall( gar.joinNetwork, msg.From, - tonumber(msg.Tags.OperatorStake), + tonumber(msg.Tags["Operator-Stake"]), updatedSettings, observerAddress, msg.Timestamp @@ -542,6 +544,10 @@ Handlers.add( function(msg) local checkAssertions = function() assert(tonumber(msg.Tags.Quantity) > 0, "Invalid quantity") + assert( + utils.isInteger(tonumber(msg.Tags.Quantity) and tonumber(msg.Tags.Quantity) > 0), + "Invalid quantity. Must be integer greater than 0" + ) end local inputStatus, inputResult = pcall(checkAssertions) @@ -577,7 +583,10 @@ Handlers.add( utils.hasMatchingTag("Action", ActionMap.DecreaseOperatorStake), function(msg) local checkAssertions = function() - assert(tonumber(msg.Tags.Quantity) > 0, "Invalid quantity") + assert( + utils.isInteger(tonumber(msg.Tags.Quantity) and tonumber(msg.Tags.Quantity) > 0), + "Invalid quantity. Must be integer greater than 0" + ) end local inputStatus, inputResult = pcall(checkAssertions) @@ -630,7 +639,11 @@ Handlers.add(ActionMap.DelegateStake, utils.hasMatchingTag("Action", ActionMap.D if not status then ao.send({ Target = msg.From, - Tags = { Error = "GAR-Invalid-Delegate-Stake-Increase", Action = ActionMap.DelegateStake, Message = result }, + Tags = { + Error = "GAR-Invalid-Delegate-Stake-Increase", + Action = ActionMap.DelegateStake, + Message = result, + }, Data = tostring(json.encode(result)), }) else @@ -707,15 +720,15 @@ Handlers.add( fqdn = msg.Tags.FQDN or gateway.settings.fqdn, port = tonumber(msg.Tags.Port) or gateway.settings.port, protocol = msg.Tags.Protocol or gateway.settings.protocol, - allowDelegatedStaking = not msg.Tags.AllowDelegatedStaking and gateway.settings.allowDelegatedStaking - or msg.Tags.AllowDelegatedStaking == "true", - minDelegatedStake = tonumber(msg.Tags.MinDelegatedStake) or gateway.settings.minDelegatedStake, - delegateRewardShareRatio = tonumber(msg.Tags.DelegateRewardShareRatio) + allowDelegatedStaking = not msg.Tags["Allow-Delegated-Staking"] and gateway.settings.allowDelegatedStaking + or msg.Tags["Allow-Delegated-Staking"] == "true", + minDelegatedStake = tonumber(msg.Tags["Min-Delegated-Stake"]) or gateway.settings.minDelegatedStake, + delegateRewardShareRatio = tonumber(msg.Tags["Delegate-Reward-Share-Ratio"]) or gateway.settings.delegateRewardShareRatio, properties = msg.Tags.Properties or gateway.settings.properties, - autoStake = msg.Tags.AutoStake == "true" or gateway.settings.autoStake, + autoStake = msg.Tags["Auto-Stkae"] == "true" or gateway.settings.autoStake, } - local observerAddress = msg.Tags.ObserverAddress or gateway.observerAddress + local observerAddress = msg.Tags["Observer-Address"] or gateway.observerAddress local status, result = pcall(gar.updateGatewaySettings, msg.From, updatedSettings, observerAddress, msg.Timestamp, msg.Id) if not status then @@ -735,8 +748,8 @@ Handlers.add( ) Handlers.add(ActionMap.SaveObservations, utils.hasMatchingTag("Action", ActionMap.SaveObservations), function(msg) - local reportTxId = msg.Tags.ReportTxId - local failedGateways = utils.splitString(msg.Tags.FailedGateways, ",") + local reportTxId = msg.Tags["Report-Tx-Id"] + local failedGateways = utils.splitString(msg.Tags["Failed-Gateways"], ",") local checkAssertions = function() assert(utils.isValidArweaveAddress(reportTxId), "Invalid report tx id") for _, gateway in ipairs(failedGateways) do diff --git a/test/arns.test.js b/test/arns.test.js index 0d28935..cb185fe 100644 --- a/test/arns.test.js +++ b/test/arns.test.js @@ -26,9 +26,9 @@ describe('ArNS', async () => { Tags: [ { name: 'Action', value: 'Buy-Record' }, { name: 'Name', value: 'test-name' }, - { name: 'PurchaseType', value: 'lease' }, + { name: 'Purchase-Type', value: 'lease' }, { name: 'Years', value: '1' }, - { name: 'ProcessId', value: ''.padEnd(43, 'a') }, + { name: 'Process-Id', value: ''.padEnd(43, 'a') }, ], }); const increaseUndernameResult = await handle( @@ -61,9 +61,9 @@ describe('ArNS', async () => { { name: 'Action', value: 'Token-Cost' }, { name: 'Intent', value: 'Buy-Record' }, { name: 'Name', value: 'test-name' }, - { name: 'PurchaseType', value: 'lease' }, + { name: 'Purchase-Type', value: 'lease' }, { name: 'Years', value: '1' }, - { name: 'ProcessId', value: ''.padEnd(43, 'a') }, + { name: 'Process-Id', value: ''.padEnd(43, 'a') }, ], }); const tokenCost = JSON.parse(result.Messages[0].Data); @@ -75,9 +75,9 @@ describe('ArNS', async () => { Tags: [ { name: 'Action', value: 'Buy-Record' }, { name: 'Name', value: 'test-name' }, - { name: 'PurchaseType', value: 'lease' }, + { name: 'Purchase-Type', value: 'lease' }, { name: 'Years', value: '1' }, - { name: 'ProcessId', value: ''.padEnd(43, 'a') }, + { name: 'Process-Id', value: ''.padEnd(43, 'a') }, ], }); const result = await handle( @@ -101,9 +101,9 @@ describe('ArNS', async () => { Tags: [ { name: 'Action', value: 'Buy-Record' }, { name: 'Name', value: 'test-name' }, - { name: 'PurchaseType', value: 'lease' }, + { name: 'Purchase-Type', value: 'lease' }, { name: 'Years', value: '1' }, - { name: 'ProcessId', value: ''.padEnd(43, 'a') }, + { name: 'Process-Id', value: ''.padEnd(43, 'a') }, ], }); const recordResultBefore = await handle( From 770d60970f9879846f9140c2c709d5187ebfa56d Mon Sep 17 00:00:00 2001 From: dtfiedler Date: Mon, 24 Jun 2024 11:32:36 -0600 Subject: [PATCH 3/4] fix: revert constants file --- src/constants.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/constants.lua b/src/constants.lua index 123a26f..2ebbb40 100644 --- a/src/constants.lua +++ b/src/constants.lua @@ -88,7 +88,7 @@ constants.genesisFees = { [48] = 400000000, [49] = 400000000, [50] = 400000000, - [51] = 400 * 000000, + [51] = 400000000, } return constants From 767bfa7b97872aac141902ba498515f8638af831 Mon Sep 17 00:00:00 2001 From: dtfiedler Date: Mon, 24 Jun 2024 11:37:39 -0600 Subject: [PATCH 4/4] fix(tags): update epoch tags --- src/main.lua | 76 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 23 deletions(-) diff --git a/src/main.lua b/src/main.lua index f67a87b..b4ddf89 100644 --- a/src/main.lua +++ b/src/main.lua @@ -41,7 +41,6 @@ local ActionMap = { PrescribedNames = "Epoch-Prescribed-Names", Observations = "Epoch-Observations", Distributions = "Epoch-Distributions", - -- hypenated for all of these -- NAME REGISTRY READ APIS Record = "Record", Records = "Records", @@ -136,7 +135,7 @@ end) Handlers.add(ActionMap.CreateVault, utils.hasMatchingTag("Action", ActionMap.CreateVault), function(msg) local function checkAssertions() assert( - tonumber(msg.Tags["Lock-Length"]) > 0 and utils.isInteger(tonumber(msg.Tags.LockLength)), + tonumber(msg.Tags["Lock-Length"]) > 0 and utils.isInteger(tonumber(msg.Tags["Lock-Length"])), "Invalid lock length. Must be integer greater than 0" ) assert( @@ -201,7 +200,7 @@ Handlers.add(ActionMap.VaultedTransfer, utils.hasMatchingTag("Action", ActionMap msg.From, msg.Tags.Recipient, tonumber(msg.Tags.Quantity), - tonumber(msg.Tags.LockLength), + tonumber(msg.Tags["Lock-Length"]), msg.Timestamp, msg.Id ) @@ -622,7 +621,10 @@ Handlers.add( Handlers.add(ActionMap.DelegateStake, utils.hasMatchingTag("Action", ActionMap.DelegateStake), function(msg) local checkAssertions = function() assert(utils.isValidArweaveAddress(msg.Tags.Target), "Invalid target address") - assert(tonumber(msg.Tags.Quantity) > 0, "Invalid quantity") + assert( + tonumber(msg.Tags.Quantity) > 0 and utils.isInteger(tonumber(msg.Tags.Quantity)), + "Invalid quantity. Must be integer greater than 0" + ) end local inputStatus, inputResult = pcall(checkAssertions) @@ -630,7 +632,7 @@ Handlers.add(ActionMap.DelegateStake, utils.hasMatchingTag("Action", ActionMap.D if not inputStatus then ao.send({ Target = msg.From, - Tags = { Action = "Invalid-Delegate-Stake-Notice", Error = "Bad-Input", }, + Tags = { Action = "Invalid-Delegate-Stake-Notice", Error = "Bad-Input" }, Data = tostring(inputResult), }) return @@ -659,7 +661,10 @@ Handlers.add( function(msg) local checkAssertions = function() assert(utils.isValidArweaveAddress(msg.Tags.Target), "Invalid target address") - assert(tonumber(msg.Tags.Quantity) > 0, "Invalid quantity") + assert( + tonumber(msg.Tags.Quantity) > 0 and utils.isInteger(tonumber(msg.Tags.Quantity)), + "Invalid quantity. Must be integer greater than 0" + ) end local inputStatus, inputResult = pcall(checkAssertions) @@ -667,7 +672,7 @@ Handlers.add( if not inputStatus then ao.send({ Target = msg.From, - Tags = { Action = "Invalid-Decrease-Delegate-Stake-Notice", Error = "Bad-Input", }, + Tags = { Action = "Invalid-Decrease-Delegate-Stake-Notice", Error = "Bad-Input" }, Data = tostring(inputResult), }) return @@ -770,7 +775,12 @@ Handlers.add(ActionMap.SaveObservations, utils.hasMatchingTag("Action", ActionMa if status then ao.send({ Target = msg.From, Action = "Save-Observations-Notice", Data = json.encode(result) }) else - ao.send({ Target = msg.From, Action = "Invalid-Save-Observations-Notice", Error = "Invalid-Saved-Observations", Data = json.encode(result) }) + ao.send({ + Target = msg.From, + Action = "Invalid-Save-Observations-Notice", + Error = "Invalid-Saved-Observations", + Data = json.encode(result), + }) end end) @@ -814,7 +824,12 @@ Handlers.add("tick", utils.hasMatchingTag("Action", "Tick"), function(msg) NameRegistry = previousState.NameRegistry Epochs = previousState.Epochs DemandFactor = previousState.DemandFactor - ao.send({ Target = msg.From, Action = "Invalid-Tick-Notice", Error = "Invalid-Tick", Data = json.encode(result) }) + ao.send({ + Target = msg.From, + Action = "Invalid-Tick-Notice", + Error = "Invalid-Tick", + Data = json.encode(result), + }) end end end) @@ -884,7 +899,7 @@ Handlers.add(ActionMap.Balance, Handlers.utils.hasMatchingTag("Action", ActionMa Data = balance, Balance = balance, Ticker = Ticker, - Address = msg.Tags.Target or msg.Tags.Address or msg.From + Address = msg.Tags.Target or msg.Tags.Address or msg.From, }) end) @@ -894,7 +909,12 @@ Handlers.add(ActionMap.DemandFactor, utils.hasMatchingTag("Action", ActionMap.De if status then ao.send({ Target = msg.From, Action = "Demand-Factor-Notice", Data = tostring(result) }) else - ao.send({ Target = msg.From, Action = "Invalid-Demand-Factor-Notice", Error = "Invalid-Demand-Factor", Data = json.encode(result) }) + ao.send({ + Target = msg.From, + Action = "Invalid-Demand-Factor-Notice", + Error = "Invalid-Demand-Factor", + Data = json.encode(result), + }) end end) @@ -945,7 +965,7 @@ end) Handlers.add(ActionMap.Epoch, utils.hasMatchingTag("Action", ActionMap.Epoch), 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.Tags.Timestamp or msg.Timestamp, "Epoch index or timestamp is required") + assert(msg.Tags["Epoch-Index"] or msg.Tags.Timestamp or msg.Timestamp, "Epoch index or timestamp is required") end local inputStatus, inputResult = pcall(checkAssertions) @@ -959,7 +979,7 @@ Handlers.add(ActionMap.Epoch, utils.hasMatchingTag("Action", ActionMap.Epoch), f return end - local epochIndex = tonumber(msg.Tags.EpochIndex) + local epochIndex = tonumber(msg.Tags["Epoch-Index"]) or epochs.getEpochIndexForTimestamp(tonumber(msg.Tags.Timestamp or msg.Timestamp)) local epoch = epochs.getEpoch(epochIndex) ao.send({ Target = msg.From, Action = "Epoch-Notice", Data = json.encode(epoch) }) @@ -973,7 +993,7 @@ end) Handlers.add(ActionMap.PrescribedObservers, utils.hasMatchingTag("Action", ActionMap.PrescribedObservers), 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 or msg.Tags.Timestamp, "Epoch index or timestamp is required") + assert(msg.Tags["Epoch-Index"] or msg.Timestamp or msg.Tags.Timestamp, "Epoch index or timestamp is required") end local inputStatus, inputResult = pcall(checkAssertions) @@ -987,7 +1007,7 @@ Handlers.add(ActionMap.PrescribedObservers, utils.hasMatchingTag("Action", Actio return end - local epochIndex = tonumber(msg.Tags.EpochIndex) or epochs.getEpochIndexFromTimestamp(tonumber(msg.Timestamp)) + local epochIndex = tonumber(msg.Tags["Epoch-Index"]) or epochs.getEpochIndexFromTimestamp(tonumber(msg.Timestamp)) local prescribedObservers = epochs.getPrescribedObserversForEpoch(epochIndex) ao.send({ Target = msg.From, Action = "Prescribed-Observers-Notice", Data = json.encode(prescribedObservers) }) end) @@ -995,7 +1015,7 @@ end) Handlers.add(ActionMap.Observations, utils.hasMatchingTag("Action", ActionMap.Observations), 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 or msg.Tags.Timestamp, "Epoch index or timestamp is required") + assert(msg.Tags["Epoch-Index"] or msg.Timestamp or msg.Tags.Timestamp, "Epoch index or timestamp is required") end local inputStatus, inputResult = pcall(checkAssertions) @@ -1009,16 +1029,21 @@ Handlers.add(ActionMap.Observations, utils.hasMatchingTag("Action", ActionMap.Ob return end - local epochIndex = tonumber(msg.Tags.EpochIndex) + local epochIndex = tonumber(msg.Tags["Epoch-Index"]) or epochs.getEpochIndexFromTimestamp(tonumber(msg.Timestamp or msg.Tags.Timestamp)) local observations = epochs.getObservationsForEpoch(epochIndex) - ao.send({ Target = msg.From, Action = "Observations-Notice", EpochIndex = tostring(epochIndex), Data = json.encode(observations) }) + ao.send({ + Target = msg.From, + Action = "Observations-Notice", + EpochIndex = tostring(epochIndex), + Data = json.encode(observations), + }) end) Handlers.add(ActionMap.PrescribedNames, utils.hasMatchingTag("Action", ActionMap.PrescribedNames), 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.Tags.Timestamp or msg.Timestamp, "Epoch index or timestamp is required") + assert(msg.Tags["Epoch-Index"] or msg.Tags.Timestamp or msg.Timestamp, "Epoch index or timestamp is required") end local inputStatus, inputResult = pcall(checkAssertions) @@ -1032,7 +1057,7 @@ Handlers.add(ActionMap.PrescribedNames, utils.hasMatchingTag("Action", ActionMap return end - local epochIndex = tonumber(msg.Tags.EpochIndex) + local epochIndex = tonumber(msg.Tags["Epoch-Index"]) or epochs.getEpochIndexForTimestamp(tonumber(msg.Timestamp or msg.Tags.Timestamp)) local prescribedNames = epochs.getPrescribedNamesForEpoch(epochIndex) ao.send({ Target = msg.From, Action = "Prescribed-Names-Notice", Data = json.encode(prescribedNames) }) @@ -1041,7 +1066,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 or msg.Tags.Timestamp, "Epoch index or timestamp is required") + assert(msg.Tags["Epoch-Index"] or msg.Timestamp or msg.Tags.Timestamp, "Epoch index or timestamp is required") end local inputStatus, inputResult = pcall(checkAssertions) @@ -1055,7 +1080,7 @@ Handlers.add(ActionMap.Distributions, utils.hasMatchingTag("Action", ActionMap.D return end - local epochIndex = tonumber(msg.Tags.EpochIndex) + local epochIndex = tonumber(msg.Tags["Epoch-Index"]) or epochs.getEpochIndexFromTimestamp(tonumber(msg.Timestamp or msg.Tags.Timestamp)) local distributions = epochs.getDistributionsForEpoch(epochIndex) ao.send({ Target = msg.From, Action = "Distributions-Notice", Data = json.encode(distributions) }) @@ -1068,7 +1093,12 @@ end) Handlers.add(ActionMap.ReservedName, utils.hasMatchingTag("Action", ActionMap.ReservedName), function(msg) local reservedName = arns.getReservedName(msg.Tags.Name) - ao.send({ Target = msg.From, Action = "Reserved-Name-Notice", ReservedName = msg.Tags.Name, Data = json.encode(reservedName) }) + ao.send({ + Target = msg.From, + Action = "Reserved-Name-Notice", + ReservedName = msg.Tags.Name, + Data = json.encode(reservedName), + }) end) -- END READ HANDLERS