mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-06 02:52:19 +00:00
24 lines
512 B
Go
24 lines
512 B
Go
|
package utils
|
||
|
|
||
|
import "time"
|
||
|
|
||
|
// compute current slot.
|
||
|
func GetCurrentSlot(genesisTime uint64, secondsPerSlot uint64) uint64 {
|
||
|
now := uint64(time.Now().Unix())
|
||
|
if now < genesisTime {
|
||
|
return 0
|
||
|
}
|
||
|
|
||
|
return (now - genesisTime) / secondsPerSlot
|
||
|
}
|
||
|
|
||
|
// compute current epoch.
|
||
|
func GetCurrentEpoch(genesisTime uint64, secondsPerSlot uint64, slotsPerEpoch uint64) uint64 {
|
||
|
now := uint64(time.Now().Unix())
|
||
|
if now < genesisTime {
|
||
|
return 0
|
||
|
}
|
||
|
|
||
|
return GetCurrentSlot(genesisTime, secondsPerSlot) / slotsPerEpoch
|
||
|
}
|