Skip to content

Commit f47f8bd

Browse files
committed
Merge branch 'main' of https://github.com/permaweb/aos into twilson63/chore-bump-2.0.1
2 parents 414cc89 + af92119 commit f47f8bd

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

blueprints/staking.lua

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
Variant = "0.0.2"
1+
Variant = "0.0.4"
22
Stakers = Stakers or {}
33
Unstaking = Unstaking or {}
4+
UnstakeDelay = UnstakeDelay or 670
45
local bint = require('.bint')(256)
56

67
--[[
@@ -21,13 +22,12 @@ local utils = {
2122
-- Stake Action Handler
2223
Handlers.stake = function(msg)
2324
local quantity = bint(msg.Tags.Quantity)
24-
local delay = tonumber(msg.Tags.UnstakeDelay)
2525
local height = tonumber(msg['Block-Height'])
2626
assert(Balances[msg.From] and bint(Balances[msg.From]) >= quantity, "Insufficient balance to stake")
2727
Balances[msg.From] = utils.subtract(Balances[msg.From], msg.Tags.Quantity)
2828
Stakers[msg.From] = Stakers[msg.From] or { amount = "0" }
2929
Stakers[msg.From].amount = utils.add(Stakers[msg.From].amount, msg.Tags.Quantity)
30-
Stakers[msg.From].unstake_at = height + delay
30+
Stakers[msg.From].unstake_at = height + UnstakeDelay
3131
print("Successfully Staked " .. msg.Tags.Quantity)
3232
if msg.reply then
3333
msg.reply({ Data = "Successfully Staked " .. msg.Tags.Quantity})
@@ -57,12 +57,11 @@ local finalizationHandler = function(msg)
5757
local currentHeight = tonumber(msg['Block-Height'])
5858
-- Process unstaking
5959
for address, unstakeInfo in pairs(Unstaking) do
60-
if currentHeight >= unstakeInfo.release_at then
60+
if unstakeInfo.release_at == nil or currentHeight >= unstakeInfo.release_at then
6161
Balances[address] = utils.add(Balances[address] or "0", unstakeInfo.amount)
6262
Unstaking[address] = nil
6363
end
6464
end
65-
6665
end
6766

6867
-- wrap function to continue handler flow
@@ -91,5 +90,4 @@ Handlers.add("staking.unstake",
9190
continue(Handlers.utils.hasMatchingTag("Action", "Unstake")), Handlers.unstake)
9291
-- Finalization handler should be called for every message
9392
-- changed to continue to let messages pass-through
94-
Handlers.add("staking.finalize", function (msg) return "continue" end, finalizationHandler)
95-
93+
Handlers.prepend("staking.finalize", function (msg) return "continue" end, finalizationHandler)

0 commit comments

Comments
 (0)