1
- Variant = " 0.0.2 "
1
+ Variant = " 0.0.4 "
2
2
Stakers = Stakers or {}
3
3
Unstaking = Unstaking or {}
4
+ UnstakeDelay = UnstakeDelay or 670
4
5
local bint = require (' .bint' )(256 )
5
6
6
7
--[[
@@ -21,13 +22,12 @@ local utils = {
21
22
-- Stake Action Handler
22
23
Handlers .stake = function (msg )
23
24
local quantity = bint (msg .Tags .Quantity )
24
- local delay = tonumber (msg .Tags .UnstakeDelay )
25
25
local height = tonumber (msg [' Block-Height' ])
26
26
assert (Balances [msg .From ] and bint (Balances [msg .From ]) >= quantity , " Insufficient balance to stake" )
27
27
Balances [msg .From ] = utils .subtract (Balances [msg .From ], msg .Tags .Quantity )
28
28
Stakers [msg .From ] = Stakers [msg .From ] or { amount = " 0" }
29
29
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
31
31
print (" Successfully Staked " .. msg .Tags .Quantity )
32
32
if msg .reply then
33
33
msg .reply ({ Data = " Successfully Staked " .. msg .Tags .Quantity })
@@ -57,12 +57,11 @@ local finalizationHandler = function(msg)
57
57
local currentHeight = tonumber (msg [' Block-Height' ])
58
58
-- Process unstaking
59
59
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
61
61
Balances [address ] = utils .add (Balances [address ] or " 0" , unstakeInfo .amount )
62
62
Unstaking [address ] = nil
63
63
end
64
64
end
65
-
66
65
end
67
66
68
67
-- wrap function to continue handler flow
@@ -91,5 +90,4 @@ Handlers.add("staking.unstake",
91
90
continue (Handlers .utils .hasMatchingTag (" Action" , " Unstake" )), Handlers .unstake )
92
91
-- Finalization handler should be called for every message
93
92
-- 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