Skip to content

Commit

Permalink
Merge pull request #11 from AxLabs/develop
Browse files Browse the repository at this point in the history
v0.0.7
  • Loading branch information
mialbu authored Nov 7, 2022
2 parents 3f85653 + a51e772 commit 0da0e5c
Show file tree
Hide file tree
Showing 7 changed files with 849 additions and 75 deletions.
14 changes: 3 additions & 11 deletions accounting/accounting.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"github.com/AxLabs/neofs-api-shared-lib/client"
"github.com/AxLabs/neofs-api-shared-lib/response"
"github.com/google/uuid"
v2accounting "github.com/nspcc-dev/neofs-api-go/v2/accounting"
neofsclient "github.com/nspcc-dev/neofs-sdk-go/client"
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
Expand All @@ -17,18 +16,14 @@ import (
Balance
*/

func GetBalance(clientID *uuid.UUID, id *user.ID) *response.PointerResponse {
func GetBalance(neofsClient *client.NeoFSClient, id *user.ID) *response.PointerResponse {
ctx := context.Background()

var prmBalanceGet neofsclient.PrmBalanceGet
//id, err := main.UserIDFromPublicKey(publicKey)
prmBalanceGet.SetAccount(*id)

neofsClient, err := client.GetClient(clientID)
if err != nil {
return response.ClientError()
}
resBalanceGet, err := neofsClient.LockAndGet().BalanceGet(ctx, prmBalanceGet)
client := neofsClient.LockAndGet()
resBalanceGet, err := client.BalanceGet(ctx, prmBalanceGet)
neofsClient.Unlock()
if err != nil {
return response.Error(err)
Expand All @@ -40,9 +35,6 @@ func GetBalance(clientID *uuid.UUID, id *user.ID) *response.PointerResponse {
}

amount := resBalanceGet.Amount()
if amount == nil {
return response.Error(err)
}

var v2 v2accounting.Decimal
amount.WriteToV2(&v2)
Expand Down
1 change: 0 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package client

import "C"
import (
"crypto/ecdsa"
"fmt"
Expand Down
35 changes: 24 additions & 11 deletions container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package container
import "C"
import (
"context"
"encoding/json"
"github.com/AxLabs/neofs-api-shared-lib/client"
"github.com/AxLabs/neofs-api-shared-lib/response"
v2container "github.com/nspcc-dev/neofs-api-go/v2/container"
Expand Down Expand Up @@ -32,7 +33,8 @@ func PutContainer(neofsClient *client.NeoFSClient, cnr *container.Container) *re
var prmContainerPut neofsclient.PrmContainerPut
prmContainerPut.SetContainer(*cnr)

resContainerPut, err := neofsClient.LockAndGet().ContainerPut(ctx, prmContainerPut)
client := neofsClient.LockAndGet()
resContainerPut, err := client.ContainerPut(ctx, prmContainerPut)
neofsClient.Unlock()
if err != nil {
return response.StringError(err)
Expand All @@ -42,7 +44,7 @@ func PutContainer(neofsClient *client.NeoFSClient, cnr *container.Container) *re
return response.StringStatusResponse()
}

containerID := *resContainerPut.ID()
containerID := resContainerPut.ID()
return response.NewString(reflect.TypeOf(containerID), containerID.String())
}

Expand Down Expand Up @@ -122,13 +124,13 @@ func deleteContainer(neofsClient *client.NeoFSClient, containerID *cid.ID, sessi
}

func ListContainer(neofsClient *client.NeoFSClient, userID *user.ID) *response.PointerResponse {
client := neofsClient.LockAndGet()
ctx := context.Background()

var prmContainerList neofsclient.PrmContainerList
prmContainerList.SetAccount(*userID)
//prmContainerList.WithXHeaders()

client := neofsClient.LockAndGet()
resContainerList, err := client.ContainerList(ctx, prmContainerList)
neofsClient.Unlock()
if err != nil {
Expand All @@ -139,17 +141,28 @@ func ListContainer(neofsClient *client.NeoFSClient, userID *user.ID) *response.P
return response.StatusResponse()
}

containerIDs := resContainerList.Containers()
ids := parseContainerIDs(containerIDs)
return response.New(reflect.TypeOf(containerIDs), ids)
bytes, err := buildContainerListResponse(resContainerList)
if err != nil {
return response.Error(err)
}
return response.New(reflect.TypeOf(ListResponse{}), bytes)
}

func parseContainerIDs(containerIDList []cid.ID) []byte {
bytes := make([]byte, 0)
for _, id := range containerIDList {
bytes = append(bytes[:], []byte(id.EncodeToString())...)
func buildContainerListResponse(resContainerList *neofsclient.ResContainerList) ([]byte, error) {
ids := make([]string, len(resContainerList.Containers()))
for i, ctr := range resContainerList.Containers() {
ids[i] = ctr.EncodeToString()
}
listResponse := ListResponse{Containers: ids}
bytes, err := json.Marshal(listResponse)
if err != nil {
return nil, err
}
return bytes
return bytes, nil
}

type ListResponse struct {
Containers []string `json:"containers"`
}

////export SetExtendedACL
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ go 1.16

require (
github.com/google/uuid v1.3.0
github.com/nspcc-dev/neo-go v0.99.1
github.com/nspcc-dev/neofs-api-go/v2 v2.13.1
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.6
google.golang.org/protobuf v1.28.1 // indirect
github.com/nspcc-dev/neo-go v0.99.4
github.com/nspcc-dev/neofs-api-go/v2 v2.14.0
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.7
google.golang.org/genproto v0.0.0-20221027153422-115e99e71e1c // indirect
)
Loading

0 comments on commit 0da0e5c

Please sign in to comment.