-
Notifications
You must be signed in to change notification settings - Fork 7
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
fix: Improve Stake Time Calculation Accuracy #119
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change time to duration in sub-command struct of this command too. (you can find it in this file on the get commands function)
@@ -117,7 +116,7 @@ func (bc *Blockchain) calcRewardHandler(cmd command.Command, _ command.AppID, _ | |||
|
|||
return cmd.SuccessfulResult("Approximately you earn %v PAC reward, with %v PAC stake 🔒 on your validator in one %s ⏰ with %s total power ⚡ of committee."+ | |||
"\n\n> Note📝: This number is just an estimation. It will vary depending on your stake amount and total network power.", | |||
utils.FormatNumber(reward), utils.FormatNumber(int64(stake)), time, utils.FormatNumber(int64(amount.Amount(bi.TotalPower).ToPAC()))) | |||
utils.FormatNumber(reward), utils.FormatNumber(int64(stake)), duration, utils.FormatNumber(int64(amount.Amount(bi.TotalPower).ToPAC()))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why "utils.FormatNumber(int64(stake))"?
Get stake like:
stake, err := amount.FromString(args[0])
if err != nil {
return cmd.ErrorResult(err)
}
reward := stake*blocks / amount.Amount(bi.TotalPower)
Try to work with amount.Amount
not int64
done |
…Rename Variable for Clarity
|
||
return cmd.SuccessfulResult("Approximately you earn %v PAC reward, with %v PAC stake 🔒 on your validator in one %s ⏰ with %s total power ⚡ of committee."+ | ||
"\n\n> Note📝: This number is just an estimation. It will vary depending on your stake amount and total network power.", | ||
utils.FormatNumber(reward), utils.FormatNumber(int64(stake)), time, utils.FormatNumber(int64(amount.Amount(bi.TotalPower).ToPAC()))) | ||
utils.FormatNumber(int64(reward)), utils.FormatNumber(int64(stake)), duration, utils.FormatNumber(int64(amount.Amount(bi.TotalPower).ToPAC()))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try avoid this:
utils.FormatNumber(int64(reward)), utils.FormatNumber(int64(stake))
use amt.String()
@@ -8,6 +8,7 @@ import ( | |||
"github.com/pagu-project/Pagu/client" | |||
"github.com/pagu-project/Pagu/engine/command" | |||
"github.com/pagu-project/Pagu/utils" | |||
// "github.com/pagu-project/Pagu/utils" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this line.
@@ -114,11 +115,12 @@ func (bc *Blockchain) calcRewardHandler(cmd command.Command, _ command.AppID, _ | |||
|
|||
rewardInt := stake * blocks / int(amount.Amount(bi.TotalPower).ToPAC()) | |||
|
|||
reward := amount.Amount(rewardInt) | |||
// convert from nanoPac to PAC. | |||
totalPowerInPAC := bi.TotalPower / 1_000_000_000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@izikdepth please one time read and check amount.Amount functions.
Avoid using bare operation here.
@akbariandev close this PR |
Description
Related Issue
Types of changes