forked from TrueCloudLab/frostfs-node
[#873] morph/client: Add function that calculates notary deposit
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
d55456f3ac
commit
d2096b392c
1 changed files with 30 additions and 0 deletions
|
@ -715,3 +715,33 @@ const alreadyOnChainErrorMessage = "already on chain"
|
|||
func alreadyOnChainError(err error) bool {
|
||||
return strings.Contains(err.Error(), alreadyOnChainErrorMessage)
|
||||
}
|
||||
|
||||
// CalculateNotaryDepositAmount calculates notary deposit amount
|
||||
// using the rule:
|
||||
// IF notaryBalance < gasBalance * gasMul {
|
||||
// DEPOSIT gasBalance / gasDiv
|
||||
// } ELSE {
|
||||
// DEPOSIT 1
|
||||
// }
|
||||
// gasMul and gasDiv must be positive.
|
||||
func CalculateNotaryDepositAmount(c *Client, gasMul, gasDiv int64) (fixedn.Fixed8, error) {
|
||||
notaryBalance, err := c.GetNotaryDeposit()
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("could not get notary balance: %w", err)
|
||||
}
|
||||
|
||||
gasBalance, err := c.GasBalance()
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("could not get GAS balance: %w", err)
|
||||
}
|
||||
|
||||
var depositAmount int64
|
||||
|
||||
if gasBalance*gasMul > notaryBalance {
|
||||
depositAmount = gasBalance / gasDiv
|
||||
} else {
|
||||
depositAmount = 1
|
||||
}
|
||||
|
||||
return fixedn.Fixed8(depositAmount), nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue