2020-07-24 13:54:03 +00:00
|
|
|
package balance
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
|
2020-07-24 13:54:03 +00:00
|
|
|
)
|
|
|
|
|
2022-01-31 09:24:25 +00:00
|
|
|
// Decimals decimal precision of currency transactions
|
|
|
|
// through the Balance contract call, and returns it.
|
|
|
|
func (c *Client) Decimals() (uint32, error) {
|
2021-11-09 20:52:29 +00:00
|
|
|
invokePrm := client.TestInvokePrm{}
|
2022-01-29 13:06:36 +00:00
|
|
|
invokePrm.SetMethod(decimalsMethod)
|
2021-11-09 20:52:29 +00:00
|
|
|
|
|
|
|
prms, err := c.client.TestInvoke(invokePrm)
|
2020-07-24 13:54:03 +00:00
|
|
|
if err != nil {
|
2024-12-04 08:17:13 +00:00
|
|
|
return 0, fmt.Errorf("test invoke (%s): %w", decimalsMethod, err)
|
2020-07-24 13:54:03 +00:00
|
|
|
} else if ln := len(prms); ln != 1 {
|
2022-01-31 09:24:25 +00:00
|
|
|
return 0, fmt.Errorf("unexpected stack item count (%s): %d", decimalsMethod, ln)
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
|
|
|
|
2020-08-27 11:57:13 +00:00
|
|
|
decimals, err := client.IntFromStackItem(prms[0])
|
2020-07-24 13:54:03 +00:00
|
|
|
if err != nil {
|
2024-12-12 12:06:20 +00:00
|
|
|
return 0, fmt.Errorf("get integer stack item from stack item (%s): %w", decimalsMethod, err)
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
2022-01-31 09:24:25 +00:00
|
|
|
return uint32(decimals), nil
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|