Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: functions to convert unix epoch to fil epoch #252

Merged
merged 5 commits into from
Nov 24, 2020
Merged
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
26 changes: 26 additions & 0 deletions storage/migrations/21_height_functions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package migrations

import (
"github.com/go-pg/migrations/v8"
)

// Schema version 21 adds helper functions to convert from unix epoch to fil epoch

func init() {
up := batch(`
CREATE OR REPLACE FUNCTION public.unix_to_height(unix_epoch bigint) RETURNS bigint AS $$
SELECT ((unix_epoch - 1598306400) / 30)::bigint;
$$ LANGUAGE SQL;
CREATE OR REPLACE FUNCTION public.height_to_unix(fil_epoch bigint) RETURNS bigint AS $$
SELECT ((fil_epoch * 30) + 1598306400)::bigint;
$$ LANGUAGE SQL;
`)

down := batch(`
DROP FUNCTION IF EXISTS public.unix_to_height;
DROP FUNCTION IF EXISTS public.height_to_unix;
`)

migrations.MustRegisterTx(up, down)
}