seekia/internal/network/myIdentityBalance/myIdentityBalance.go

65 lines
2.7 KiB
Go

// myIdentityBalance provides functions to store a user's identity balance, and to update the balance through the account credit servers
package myIdentityBalance
// Only Mate/Host identities use identity balances. Moderator identities use Identity Scores.
// This package is useful because a user's identity balance will be retained, even if the database if deleted
// We also query directly from the account credit servers, instead of relying on trusted statuses from other hosts
// See trustedFundedStatus.go, verifiedFundedStatus.go, and fundedStatus.go to see how peer identity balances are retrieved and stored
// Each identity needs to be funded with a minimum amount of gold to activate it
// The account credits servers keep track of each identity's Activated status
// Before it is activated, each transaction has to send at least a parameters-specified minimum amount of gold to activate it
// Once an identity is activated, any amount of funds can be sent to it to extend its expiration time
//TODO: Complete this package
// We need to retrieve this information from the account funds interface servers
import "seekia/internal/helpers"
import "seekia/internal/myIdentity"
import "time"
import "errors"
// Start time and end time describe the current uninterrupted period of the balance being sufficient
// The start time is recorded locally whenever we successfully fund the balance
//Outputs:
// -bool: My identity found
// -bool: Identity is activated
// -If this bool is true, the identity was funded enough to be activated at one point in the past
// -Balance can still be insufficient, even if this bool is true
// -bool: Balance is sufficient
// -int64: Balance is sufficient start time (Unix)
// -int64: Balance is sufficient end time (Expiration time) (Unix)
// -error
func GetMyIdentityBalanceStatus(myIdentityHash [16]byte, networkType byte)(bool, bool, bool, int64, int64, error){
isValid := helpers.VerifyNetworkType(networkType)
if (isValid == false){
networkTypeString := helpers.ConvertByteToString(networkType)
return false, false, false, 0, 0, errors.New("GetMyIdentityBalanceStatus called with invalid networkType: " + networkTypeString)
}
isMine, identityType, err := myIdentity.CheckIfIdentityHashIsMine(myIdentityHash)
if (err != nil) { return false, false, false, 0, 0, err }
if (isMine == false){
return false, false, false, 0, 0, nil
}
if (identityType == "Moderator"){
return false, false, false, 0, 0, errors.New("GetMyIdentityBalanceStatus called with Moderator identity")
}
//TODO: Build function
fakeStartTime := time.Now().Unix() - 31556926
fakeExpirationTime := time.Now().Unix() + 10000000
return true, true, true, fakeStartTime, fakeExpirationTime, nil
}