[#1377] oid, cid: Upgrade SDK package

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2022-05-12 19:37:46 +03:00 committed by LeL
parent f65898a354
commit f15e6e888f
118 changed files with 1455 additions and 886 deletions

View file

@ -1,6 +1,7 @@
package audit
import (
"crypto/sha256"
"fmt"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
@ -36,15 +37,13 @@ func (c *Client) ListAuditResultIDByEpoch(epoch uint64) ([]ResultID, error) {
// ListAuditResultIDByCID returns a list of audit result IDs inside audit
// contract for specific epoch number and container ID.
func (c *Client) ListAuditResultIDByCID(epoch uint64, cid *cid.ID) ([]ResultID, error) {
v2 := cid.ToV2()
if v2 == nil {
return nil, errUnsupported // use other major version if there any
}
func (c *Client) ListAuditResultIDByCID(epoch uint64, cnr *cid.ID) ([]ResultID, error) {
binCnr := make([]byte, sha256.Size)
cnr.Encode(binCnr)
prm := client.TestInvokePrm{}
prm.SetMethod(listByCIDResultsMethod)
prm.SetArgs(epoch, v2.GetValue())
prm.SetArgs(epoch, binCnr)
items, err := c.client.TestInvoke(prm)
if err != nil {
@ -55,15 +54,13 @@ func (c *Client) ListAuditResultIDByCID(epoch uint64, cid *cid.ID) ([]ResultID,
// ListAuditResultIDByNode returns a list of audit result IDs inside audit
// contract for specific epoch number, container ID and inner ring public key.
func (c *Client) ListAuditResultIDByNode(epoch uint64, cid *cid.ID, nodeKey []byte) ([]ResultID, error) {
v2 := cid.ToV2()
if v2 == nil {
return nil, errUnsupported // use other major version if there any
}
func (c *Client) ListAuditResultIDByNode(epoch uint64, cnr *cid.ID, nodeKey []byte) ([]ResultID, error) {
binCnr := make([]byte, sha256.Size)
cnr.Encode(binCnr)
prm := client.TestInvokePrm{}
prm.SetMethod(listByNodeResultsMethod)
prm.SetArgs(epoch, v2.GetValue(), nodeKey)
prm.SetArgs(epoch, binCnr, nodeKey)
items, err := c.client.TestInvoke(prm)
if err != nil {

View file

@ -37,7 +37,7 @@ func TestAuditResults(t *testing.T) {
var auditRes auditAPI.Result
auditRes.ForEpoch(epoch)
auditRes.SetAuditorKey(key.PublicKey().Bytes())
auditRes.ForContainer(*id)
auditRes.ForContainer(id)
prm := PutPrm{}
prm.SetResult(&auditRes)
@ -46,7 +46,7 @@ func TestAuditResults(t *testing.T) {
time.Sleep(5 * time.Second)
list, err := auditClientWrapper.ListAuditResultIDByCID(epoch, id)
list, err := auditClientWrapper.ListAuditResultIDByCID(epoch, &id)
require.NoError(t, err)
require.Len(t, list, 1)

View file

@ -1,6 +1,7 @@
package container
import (
"crypto/sha256"
"fmt"
core "github.com/nspcc-dev/neofs-node/pkg/core/container"
@ -22,9 +23,12 @@ func Delete(c *Client, witness core.RemovalWitness) error {
return fmt.Errorf("could not marshal session token: %w", err)
}
binCnr := make([]byte, sha256.Size)
id.Encode(binCnr)
return c.Delete(
DeletePrm{
cid: id.ToV2().GetValue(),
cid: binCnr,
signature: witness.Signature(),
token: binToken,
})

View file

@ -1,6 +1,7 @@
package container
import (
"crypto/sha256"
"fmt"
"github.com/nspcc-dev/neofs-node/pkg/core/container"
@ -13,19 +14,17 @@ import (
// GetEACL reads the extended ACL table from NeoFS system
// through Container contract call.
func (c *Client) GetEACL(cid *cid.ID) (*eacl.Table, error) {
if cid == nil {
func (c *Client) GetEACL(cnr *cid.ID) (*eacl.Table, error) {
if cnr == nil {
return nil, errNilArgument
}
v2 := cid.ToV2()
if v2 == nil {
return nil, errUnsupported // use other major version if there any
}
binCnr := make([]byte, sha256.Size)
cnr.Encode(binCnr)
prm := client.TestInvokePrm{}
prm.SetMethod(eaclMethod)
prm.SetArgs(v2.GetValue())
prm.SetArgs(binCnr)
prms, err := c.client.TestInvoke(prm)
if err != nil {

View file

@ -1,6 +1,7 @@
package container
import (
"crypto/sha256"
"fmt"
"strings"
@ -29,8 +30,11 @@ func AsContainerSource(w *Client) core.Source {
// Get marshals container ID, and passes it to Wrapper's Get method.
//
// Returns error if cid is nil.
func Get(c *Client, cid *cid.ID) (*container.Container, error) {
return c.Get(cid.ToV2().GetValue())
func Get(c *Client, cnr *cid.ID) (*container.Container, error) {
binCnr := make([]byte, sha256.Size)
cnr.Encode(binCnr)
return c.Get(binCnr)
}
// Get reads the container from NeoFS system by binary identifier

View file

@ -3,7 +3,6 @@ package container
import (
"fmt"
v2refs "github.com/nspcc-dev/neofs-api-go/v2/refs"
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
"github.com/nspcc-dev/neofs-sdk-go/owner"
@ -48,10 +47,14 @@ func (c *Client) List(ownerID *owner.ID) ([]*cid.ID, error) {
return nil, fmt.Errorf("could not get byte array from stack item (%s): %w", listMethod, err)
}
v2 := new(v2refs.ContainerID)
v2.SetValue(rawCid)
var id cid.ID
cidList = append(cidList, cid.NewFromV2(v2))
err = id.Decode(rawCid)
if err != nil {
return nil, fmt.Errorf("decode container ID: %w", err)
}
cidList = append(cidList, &id)
}
return cidList, nil

View file

@ -1,6 +1,8 @@
package container
import (
"crypto/sha256"
"errors"
"fmt"
v2refs "github.com/nspcc-dev/neofs-api-go/v2/refs"
@ -32,14 +34,17 @@ func (a2 *AnnounceLoadPrm) SetReporter(key []byte) {
//
// Returns any error encountered that caused the saving to interrupt.
func (c *Client) AnnounceLoad(p AnnounceLoadPrm) error {
v2 := p.a.ContainerID().ToV2()
if v2 == nil {
return errUnsupported // use other major version if there any
cnr, ok := p.a.ContainerID()
if !ok {
return errors.New("missing container for load announcement")
}
binCnr := make([]byte, sha256.Size)
cnr.Encode(binCnr)
prm := client.InvokePrm{}
prm.SetMethod(putSizeMethod)
prm.SetArgs(p.a.Epoch(), v2.GetValue(), p.a.UsedSpace(), p.key)
prm.SetArgs(p.a.Epoch(), binCnr, p.a.UsedSpace(), p.key)
prm.InvokePrmOptional = p.InvokePrmOptional
err := c.client.Invoke(prm)
@ -130,10 +135,17 @@ func (c *Client) GetUsedSpaceEstimations(id EstimationID) (*Estimations, error)
return nil, fmt.Errorf("could not get estimation list array from stack item (%s): %w", getSizeMethod, err)
}
var cnr cid.ID
err = cnr.Decode(rawCID)
if err != nil {
return nil, fmt.Errorf("decode container ID: %w", err)
}
v2 := new(v2refs.ContainerID)
v2.SetValue(rawCID)
res := &Estimations{
ContainerID: cid.NewFromV2(v2),
ContainerID: &cnr,
Values: make([]Estimation, 0, len(prms)),
}

View file

@ -44,10 +44,10 @@ func Put(c *Client, cnr *container.Container) (*cid.ID, error) {
return nil, err
}
id := cid.New()
var id cid.ID
id.SetSHA256(sha256.Sum256(data))
return id, nil
return &id, nil
}
// PutPrm groups parameters of Put operation.