diff --git a/pool/pool.go b/pool/pool.go index 6a2e628..6c2d036 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -14,6 +14,7 @@ import ( "time" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" + "github.com/nspcc-dev/neofs-sdk-go/accounting" "github.com/nspcc-dev/neofs-sdk-go/client" apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" "github.com/nspcc-dev/neofs-sdk-go/container" @@ -122,6 +123,7 @@ func (pb *Builder) Build(ctx context.Context, options *BuilderOptions) (Pool, er type Pool interface { Object Container + Accounting Connection() (client.Client, *session.Token, error) OwnerID() *owner.ID WaitForContainerPresence(context.Context, *cid.ID, *ContainerPollingParams) error @@ -149,6 +151,10 @@ type Container interface { AnnounceContainerUsedSpace(ctx context.Context, announce []container.UsedSpaceAnnouncement, opts ...CallOption) error } +type Accounting interface { + Balance(ctx context.Context, owner *owner.ID, opts ...CallOption) (*accounting.Decimal, error) +} + type clientPack struct { client client.Client healthy bool @@ -891,6 +897,26 @@ func (p *pool) AnnounceContainerUsedSpace(ctx context.Context, announce []contai return err } +func (p *pool) Balance(ctx context.Context, o *owner.ID, opts ...CallOption) (*accounting.Decimal, error) { + cfg := cfgFromOpts(opts...) + cp, options, err := p.conn(ctx, cfg) + if err != nil { + return nil, err + } + + res, err := cp.client.GetBalance(ctx, o, options...) + if err == nil { + // reflect status failures in err + err = apistatus.ErrFromStatus(res.Status()) + } + + if err != nil { + return nil, err + } + + return res.Amount(), nil +} + func (p *pool) WaitForContainerPresence(ctx context.Context, cid *cid.ID, pollParams *ContainerPollingParams) error { conn, _, err := p.Connection() if err != nil {