planetmint-go/util/rddl_token.go
Lorenz Herzberger 94830df5fc
184 implement staged claim (#190)
* adjust issuePoPRewards to mint stagedCRDDL
* add GetChallengeRange
* add resolveStagedClaims on ReissueRDDLResult msg
* move claim resolve to distribution result
* add StagedDenom and ClaimDenom to config
* added the prepare4linting.sh script
* renamed PoPEpochs to PopEpochs
* renamed DistributionAddressPoP to DistributionAddressPop
* added config value ReIssuanceEpochs
* detached the re-issuance from the distribution process and schedule them independently
* changed logging messages
* added an explicit util/kv_serialize.go file to have all KV serialization done
* switched to Bigendian serialization of int64 to have the ordered list on the kvstore
* added ComputeReIssuanceValue to enable re-issuances once a day or defined by ReIssuanceEpoch
* integrated a ReIssuanceValue computation test case
* adjusted the challenges test cases to be epoch-dependent
* added ReIssuances per ReIssuanceEpoch
* extended the Reissue message
* checking ReIssuanceProposal in the ante handler
* added precision setter for the UINT to RDDL token converter (and test cases)
* add e2e test case for pop rewards


Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
Co-authored-by: Jürgen Eckel <juergen@riddleandcode.com>
2023-12-05 10:51:06 +01:00

46 lines
1.0 KiB
Go

package util
import "strconv"
var factor = 100000000.0
func RDDLToken2Uint(amount float64) uint64 {
return uint64(amount * factor)
}
func RDDLToken2Float(amount uint64) float64 {
return float64(amount) / factor
}
func RDDLTokenStringToFloat(amount string) (amountFloat float64, err error) {
amountFloat, err = strconv.ParseFloat(amount, 64)
return amountFloat, err
}
func RDDLTokenStringToUint(amount string) (amountUint uint64, err error) {
amountFloat, err := RDDLTokenStringToFloat(amount)
if err == nil {
amountUint = RDDLToken2Uint(amountFloat)
}
return amountUint, err
}
func addPrecision(valueString string) string {
length := len(valueString)
if length > 8 {
return valueString[:length-8] + "." + valueString[length-8:]
}
resultString := "0."
for i := 0; i < 8-length; i++ {
resultString += "0"
}
return resultString + valueString
}
func UintValueToRDDLTokenString(value uint64) (rddlString string) {
uint64String := strconv.FormatUint(value, 10)
rddlString = addPrecision(uint64String)
return
}