From a51e772855c0a874e381d8cde0bc4cbf337d0cd6 Mon Sep 17 00:00:00 2001 From: Michael Bucher Date: Mon, 7 Nov 2022 16:38:52 +0100 Subject: [PATCH] (Minor) Get client for accounting.go in lib.go and fix other minor issues --- accounting/accounting.go | 11 +++-------- client/client.go | 1 - container/container.go | 5 +++-- lib.go | 12 ++++++------ netmap/netmap.go | 19 ++++++------------- 5 files changed, 18 insertions(+), 30 deletions(-) diff --git a/accounting/accounting.go b/accounting/accounting.go index 438eb75..424077b 100644 --- a/accounting/accounting.go +++ b/accounting/accounting.go @@ -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" @@ -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) diff --git a/client/client.go b/client/client.go index 4c8e609..f9b75bf 100644 --- a/client/client.go +++ b/client/client.go @@ -1,6 +1,5 @@ package client -import "C" import ( "crypto/ecdsa" "fmt" diff --git a/container/container.go b/container/container.go index b4271a7..5f135ec 100644 --- a/container/container.go +++ b/container/container.go @@ -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) @@ -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 { diff --git a/lib.go b/lib.go index 8809e10..22dad16 100644 --- a/lib.go +++ b/lib.go @@ -31,7 +31,7 @@ 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)) } @@ -39,7 +39,7 @@ func GetBalance(clientID *C.char, publicKey *C.char) C.pointerResponse { if err != nil { return responseToC(response.Error(err)) } - return responseToC(accounting.GetBalance(id, key)) + return responseToC(accounting.GetBalance(c, key)) } // endregion accounting @@ -47,20 +47,20 @@ func GetBalance(clientID *C.char, publicKey *C.char) C.pointerResponse { //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 diff --git a/netmap/netmap.go b/netmap/netmap.go index 3a6b6aa..5b8ea59 100644 --- a/netmap/netmap.go +++ b/netmap/netmap.go @@ -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" @@ -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) @@ -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)