Skip to content

Commit

Permalink
(Minor) Get client for accounting.go in lib.go and fix other minor is…
Browse files Browse the repository at this point in the history
…sues
  • Loading branch information
mialbu committed Nov 7, 2022
1 parent 0b19799 commit a51e772
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 30 deletions.
11 changes: 3 additions & 8 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 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
5 changes: 3 additions & 2 deletions container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,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 Down Expand Up @@ -123,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 Down
12 changes: 6 additions & 6 deletions lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,36 +31,36 @@ func CreateClient(privateKey *C.char, neofsEndpoint *C.char) C.pointerResponse {

//export GetBalance
func GetBalance(clientID *C.char, publicKey *C.char) C.pointerResponse {
id, err := uuidToGo(clientID)
c, err := GetClient(clientID)
if err != nil {
return responseToC(response.Error(err))
}
key, err := UserIDFromPublicKey(publicKey)
if err != nil {
return responseToC(response.Error(err))
}
return responseToC(accounting.GetBalance(id, key))
return responseToC(accounting.GetBalance(c, key))
}

// endregion accounting
// region netmap

//export GetEndpoint
func GetEndpoint(clientID *C.char) C.pointerResponse {
id, err := uuidToGo(clientID)
c, err := GetClient(clientID)
if err != nil {
return responseToC(response.Error(err))
}
return responseToC(netmap.GetEndpoint(id))
return responseToC(netmap.GetEndpoint(c))
}

//export GetNetworkInfo
func GetNetworkInfo(clientID *C.char) C.pointerResponse {
id, err := uuidToGo(clientID)
c, err := GetClient(clientID)
if err != nil {
return responseToC(response.Error(err))
}
return responseToC(netmap.GetNetworkInfo(id))
return responseToC(netmap.GetNetworkInfo(c))
}

// endregion netmap
Expand Down
19 changes: 6 additions & 13 deletions netmap/netmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"github.com/AxLabs/neofs-api-shared-lib/client"
"github.com/AxLabs/neofs-api-shared-lib/response"
"github.com/google/uuid"
v2netmap "github.com/nspcc-dev/neofs-api-go/v2/netmap"
v2refs "github.com/nspcc-dev/neofs-api-go/v2/refs"
neofsclient "github.com/nspcc-dev/neofs-sdk-go/client"
Expand All @@ -20,15 +19,12 @@ EndpointInfo
NetMapSnapshot (only exists >v1.0.0-rc.6)
*/

func GetEndpoint(clientID *uuid.UUID) *response.PointerResponse {
func GetEndpoint(neofsClient *client.NeoFSClient) *response.PointerResponse {
ctx := context.Background()
var prmEndpointInfo neofsclient.PrmEndpointInfo

neofsClient, err := client.GetClient(clientID)
if err != nil {
return response.Error(err)
}
resEndpointInfo, err := neofsClient.LockAndGet().EndpointInfo(ctx, prmEndpointInfo)
client := neofsClient.LockAndGet()
resEndpointInfo, err := client.EndpointInfo(ctx, prmEndpointInfo)
neofsClient.Unlock()
if err != nil {
return response.Error(err)
Expand Down Expand Up @@ -76,16 +72,13 @@ type EndpointResponse struct {
LatestVersion string `json:"version.Version"`
}

func GetNetworkInfo(clientID *uuid.UUID) *response.PointerResponse {
func GetNetworkInfo(neofsClient *client.NeoFSClient) *response.PointerResponse {
ctx := context.Background()
var prmNetworkInfo neofsclient.PrmNetworkInfo
//prmNetworkInfo.WithXHeaders()

neofsClient, err := client.GetClient(clientID)
if err != nil {
return response.Error(err)
}
resNetworkInfo, err := neofsClient.LockAndGet().NetworkInfo(ctx, prmNetworkInfo)
client := neofsClient.LockAndGet()
resNetworkInfo, err := client.NetworkInfo(ctx, prmNetworkInfo)
neofsClient.Unlock()
if err != nil {
return response.Error(err)
Expand Down

0 comments on commit a51e772

Please sign in to comment.