2020-07-24 13:54:03 +00:00
|
|
|
package balance
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
|
|
|
|
2020-07-24 13:54:03 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
|
|
|
)
|
|
|
|
|
|
|
|
// DecimalsArgs groups the arguments
|
|
|
|
// of decimals test invoke call.
|
|
|
|
type DecimalsArgs struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
// DecimalsValues groups the stack parameters
|
|
|
|
// returned by decimals test invoke.
|
|
|
|
type DecimalsValues struct {
|
|
|
|
decimals int64 // decimals value
|
|
|
|
}
|
|
|
|
|
|
|
|
// Decimals returns the decimals value.
|
|
|
|
func (d *DecimalsValues) Decimals() int64 {
|
|
|
|
return d.decimals
|
|
|
|
}
|
|
|
|
|
|
|
|
// Decimals performs the test invoke of decimals
|
|
|
|
// method of NeoFS Balance contract.
|
|
|
|
func (c *Client) Decimals(args DecimalsArgs) (*DecimalsValues, error) {
|
|
|
|
prms, err := c.client.TestInvoke(
|
|
|
|
c.decimalsMethod,
|
|
|
|
)
|
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not perform test invocation (%s): %w", c.decimalsMethod, err)
|
2020-07-24 13:54:03 +00:00
|
|
|
} else if ln := len(prms); ln != 1 {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("unexpected stack item count (%s): %d", c.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 {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not get integer stack item from stack item (%s): %w", c.decimalsMethod, err)
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &DecimalsValues{
|
|
|
|
decimals: decimals,
|
|
|
|
}, nil
|
|
|
|
}
|