[#261] pkg/client: Use self address as default in ListContainers/GetBalance

This will allow us to overwrite key for every request.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2021-03-10 15:07:06 +03:00 committed by Leonard Lyubich
parent 18e9122e43
commit 74769323be
2 changed files with 26 additions and 22 deletions

View file

@ -12,15 +12,7 @@ import (
)
func (c Client) GetSelfBalance(ctx context.Context, opts ...CallOption) (*accounting.Decimal, error) {
w, err := owner.NEO3WalletFromPublicKey(&c.key.PublicKey)
if err != nil {
return nil, err
}
ownerID := new(owner.ID)
ownerID.SetNeo3Wallet(w)
return c.GetBalance(ctx, ownerID, opts...)
return c.GetBalance(ctx, nil, opts...)
}
func (c Client) GetBalance(ctx context.Context, owner *owner.ID, opts ...CallOption) (*accounting.Decimal, error) {
@ -33,7 +25,7 @@ func (c Client) GetBalance(ctx context.Context, owner *owner.ID, opts ...CallOpt
}
}
func (c Client) getBalanceV2(ctx context.Context, owner *owner.ID, opts ...CallOption) (*accounting.Decimal, error) {
func (c Client) getBalanceV2(ctx context.Context, ownerID *owner.ID, opts ...CallOption) (*accounting.Decimal, error) {
// apply all available options
callOptions := c.defaultCallOptions()
@ -41,8 +33,18 @@ func (c Client) getBalanceV2(ctx context.Context, owner *owner.ID, opts ...CallO
opts[i].apply(&callOptions)
}
if ownerID == nil {
w, err := owner.NEO3WalletFromPublicKey(&c.key.PublicKey)
if err != nil {
return nil, err
}
ownerID = new(owner.ID)
ownerID.SetNeo3Wallet(w)
}
reqBody := new(v2accounting.BalanceRequestBody)
reqBody.SetOwnerID(owner.ToV2())
reqBody.SetOwnerID(ownerID.ToV2())
req := new(v2accounting.BalanceRequest)
req.SetBody(reqBody)

View file

@ -94,15 +94,7 @@ func (c Client) ListContainers(ctx context.Context, owner *owner.ID, opts ...Cal
}
func (c Client) ListSelfContainers(ctx context.Context, opts ...CallOption) ([]*container.ID, error) {
w, err := owner.NEO3WalletFromPublicKey(&c.key.PublicKey)
if err != nil {
return nil, err
}
ownerID := new(owner.ID)
ownerID.SetNeo3Wallet(w)
return c.ListContainers(ctx, ownerID, opts...)
return c.ListContainers(ctx, nil, opts...)
}
func (c Client) DeleteContainer(ctx context.Context, id *container.ID, opts ...CallOption) error {
@ -282,7 +274,7 @@ func (c Client) getContainerV2(ctx context.Context, id *container.ID, opts ...Ca
}
}
func (c Client) listContainerV2(ctx context.Context, owner *owner.ID, opts ...CallOption) ([]*container.ID, error) {
func (c Client) listContainerV2(ctx context.Context, ownerID *owner.ID, opts ...CallOption) ([]*container.ID, error) {
// apply all available options
callOptions := c.defaultCallOptions()
@ -290,8 +282,18 @@ func (c Client) listContainerV2(ctx context.Context, owner *owner.ID, opts ...Ca
opts[i].apply(&callOptions)
}
if ownerID == nil {
w, err := owner.NEO3WalletFromPublicKey(&c.key.PublicKey)
if err != nil {
return nil, err
}
ownerID = new(owner.ID)
ownerID.SetNeo3Wallet(w)
}
reqBody := new(v2container.ListRequestBody)
reqBody.SetOwnerID(owner.ToV2())
reqBody.SetOwnerID(ownerID.ToV2())
req := new(v2container.ListRequest)
req.SetBody(reqBody)