-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lua-node): adapt blockchain fastforward
- Loading branch information
1 parent
6831e87
commit 3078b14
Showing
6 changed files
with
66 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,31 @@ | ||
local clock = os.clock | ||
local time = os.time | ||
|
||
function sleep(number_of_seconds) | ||
local function sleep(number_of_seconds) | ||
local t0 = clock() | ||
while clock() - t0 <= number_of_seconds do end | ||
end | ||
|
||
return {sleep = sleep} | ||
local function prettify_clock(status) | ||
local c = status.clock | ||
local b = status.last_block | ||
local s | ||
if c.last_resume == 0 then | ||
time_left = c.allowance | ||
s = string.format("clock paused, %d seconds left", time_left) | ||
else | ||
local current = tonumber(b) | ||
time_left = c.allowance - (current - c.last_resume) | ||
if time_left >= 0 then | ||
s = string.format("clock running, %d seconds left", time_left) | ||
else | ||
s = string.format("clock running, %d seconds overdue", -time_left) | ||
end | ||
end | ||
return s | ||
end | ||
|
||
return { | ||
sleep = sleep, | ||
prettify_clock = prettify_clock | ||
} |