[#266] pkg/client: Export Client interface instead of structure

Make it easier to test API clients and mock specific methods.
Also add comments on exported methods.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2021-03-12 18:02:26 +03:00 committed by Leonard Lyubich
parent e39a1fd949
commit ae2fb263f1
7 changed files with 134 additions and 52 deletions

View file

@ -11,11 +11,19 @@ import (
"github.com/pkg/errors"
)
func (c Client) GetSelfBalance(ctx context.Context, opts ...CallOption) (*accounting.Decimal, error) {
// Accounting contains methods related to balance querying.
type Accounting interface {
// GetSelfBalance returns balance of the account deduced from client's key.
GetSelfBalance(context.Context, ...CallOption) (*accounting.Decimal, error)
// GetBalance returns balance of provided account.
GetBalance(context.Context, *owner.ID, ...CallOption) (*accounting.Decimal, error)
}
func (c clientImpl) GetSelfBalance(ctx context.Context, opts ...CallOption) (*accounting.Decimal, error) {
return c.GetBalance(ctx, nil, opts...)
}
func (c Client) GetBalance(ctx context.Context, owner *owner.ID, opts ...CallOption) (*accounting.Decimal, error) {
func (c clientImpl) GetBalance(ctx context.Context, owner *owner.ID, opts ...CallOption) (*accounting.Decimal, error) {
// check remote node version
switch c.remoteNode.Version.Major() {
case 2:
@ -25,7 +33,7 @@ func (c Client) GetBalance(ctx context.Context, owner *owner.ID, opts ...CallOpt
}
}
func (c Client) getBalanceV2(ctx context.Context, ownerID *owner.ID, opts ...CallOption) (*accounting.Decimal, error) {
func (c clientImpl) getBalanceV2(ctx context.Context, ownerID *owner.ID, opts ...CallOption) (*accounting.Decimal, error) {
// apply all available options
callOptions := c.defaultCallOptions()