2024-04-11 15:51:56 +02:00
|
|
|
|
|
|
|
// secretInboxEpoch provides a function to calculate start and end times of secret inbox epochs.
|
|
|
|
// A secret inbox epoch is the time period during which a secret inbox is active.
|
|
|
|
|
|
|
|
package secretInboxEpoch
|
|
|
|
|
|
|
|
// When a secret inbox is active, the sender should send their messages to the inbox.
|
|
|
|
// Once the epoch has passed, the recipient will check the inbox to a sufficient degree and then stop checking it.
|
|
|
|
|
|
|
|
// Here is an example of how the epoch time works
|
|
|
|
// Example epoch origin time = 100
|
|
|
|
// Example Epoch Duration = 10
|
|
|
|
// Example epochs:
|
|
|
|
// 1st epoch start time: 100
|
|
|
|
// 1st epoch end time: 110
|
|
|
|
// 2nd epoch start time: 111
|
|
|
|
// 2nd epoch end time: 121
|
|
|
|
// 3rd epoch start time: 122
|
|
|
|
// 3rd epoch end time: 132
|
|
|
|
// ...
|
|
|
|
|
|
|
|
import "seekia/internal/helpers"
|
|
|
|
import "seekia/internal/parameters/getParameters"
|
|
|
|
|
|
|
|
import "errors"
|
|
|
|
|
|
|
|
// This is a unix time value from which the secret inbox epochs are calculated.
|
|
|
|
// This value should never change (once the Seekia network goes live)
|
|
|
|
const secretInboxEpochOriginTime int64 = 1670000000
|
|
|
|
|
|
|
|
|
2024-06-11 06:59:06 +02:00
|
|
|
// This function returns the epoch start and end times at the time of the provided messageCreationTime
|
2024-04-11 15:51:56 +02:00
|
|
|
//Outputs:
|
|
|
|
// -bool: Parameters exist
|
|
|
|
// -int64: Current epoch start time
|
|
|
|
// -int64: Current epoch end time
|
|
|
|
// -int64: Next epoch start time
|
|
|
|
// -int64: Next epoch start time
|
|
|
|
// -error
|
2024-06-11 06:59:06 +02:00
|
|
|
func GetSecretInboxEpochStartAndEndTimes(networkType byte, messageCreationTime int64)(bool, int64, int64, int64, int64, error){
|
2024-04-11 15:51:56 +02:00
|
|
|
|
|
|
|
isValid := helpers.VerifyNetworkType(networkType)
|
|
|
|
if (isValid == false){
|
|
|
|
networkTypeString := helpers.ConvertByteToString(networkType)
|
|
|
|
return false, 0, 0, 0, 0, errors.New("GetSecretInboxEpochStartAndEndTimes called with invalid networkType: " + networkTypeString)
|
|
|
|
}
|
|
|
|
|
2024-06-11 06:59:06 +02:00
|
|
|
if (messageCreationTime < secretInboxEpochOriginTime){
|
|
|
|
return false, 0, 0, 0, 0, errors.New("GetSecretInboxEpochStartAndEndTimes called with invalid messageCreationTime.")
|
2024-04-11 15:51:56 +02:00
|
|
|
}
|
|
|
|
|
2024-06-11 06:59:06 +02:00
|
|
|
parametersExist, epochDuration, err := getParameters.GetSecretInboxEpochDuration(networkType, messageCreationTime)
|
2024-04-11 15:51:56 +02:00
|
|
|
if (err != nil) { return false, 0, 0, 0, 0, err }
|
|
|
|
if (parametersExist == false){
|
|
|
|
return false, 0, 0, 0, 0, nil
|
|
|
|
}
|
|
|
|
|
2024-06-11 06:59:06 +02:00
|
|
|
remainder := (messageCreationTime - secretInboxEpochOriginTime) % (epochDuration + 1)
|
2024-04-11 15:51:56 +02:00
|
|
|
|
2024-06-11 06:59:06 +02:00
|
|
|
currentEpochStartTime := messageCreationTime - remainder
|
2024-04-11 15:51:56 +02:00
|
|
|
currentEpochEndTime := currentEpochStartTime + epochDuration
|
|
|
|
|
|
|
|
nextEpochStartTime := currentEpochEndTime + 1
|
|
|
|
nextEpochEndTime := nextEpochStartTime + epochDuration
|
|
|
|
|
|
|
|
return true, currentEpochStartTime, currentEpochEndTime, nextEpochStartTime, nextEpochEndTime, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|