forked from TrueCloudLab/frostfs-node
[#11] Trim the old functionality
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
783ec72d56
commit
a87fdab324
235 changed files with 39 additions and 36211 deletions
|
@ -1,24 +1,12 @@
|
|||
package wrapper
|
||||
|
||||
import (
|
||||
"github.com/nspcc-dev/neofs-api-go/refs"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/core/container"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/core/container/storage"
|
||||
contract "github.com/nspcc-dev/neofs-node/pkg/morph/client/container"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// OwnerID represents the container owner identifier.
|
||||
//
|
||||
// It is a type alias of
|
||||
// github.com/nspcc-dev/neofs-node/pkg/core/container/storage.OwnerID.
|
||||
type OwnerID = storage.OwnerID
|
||||
// FIXME: correct the definition.
|
||||
type OwnerID struct{}
|
||||
|
||||
// Container represents the NeoFS Container structure.
|
||||
//
|
||||
// It is a type alias of
|
||||
// github.com/nspcc-dev/neofs-node/pkg/core/container/storage.Container.
|
||||
type Container = storage.Container
|
||||
// FIXME: correct the definition.
|
||||
type Container struct{}
|
||||
|
||||
// Put saves passed container structure in NeoFS system
|
||||
// through Container contract call.
|
||||
|
@ -26,33 +14,7 @@ type Container = storage.Container
|
|||
// Returns calculated container identifier and any error
|
||||
// encountered that caused the saving to interrupt.
|
||||
func (w *Wrapper) Put(cnr *Container) (*CID, error) {
|
||||
// calculate container identifier
|
||||
//
|
||||
// Note: cid is used as return value only, but the calculation is performed
|
||||
// primarily in order to catch potential error before contract client call.
|
||||
cid, err := container.CalculateID(cnr)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not calculate container identifier")
|
||||
}
|
||||
|
||||
// marshal the container
|
||||
cnrBytes, err := cnr.MarshalBinary()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not marshal the container")
|
||||
}
|
||||
|
||||
// prepare invocation arguments
|
||||
args := contract.PutArgs{}
|
||||
args.SetOwnerID(cnr.OwnerID().Bytes())
|
||||
args.SetContainer(cnrBytes)
|
||||
args.SetSignature(nil) // TODO: set signature from request when will appear.
|
||||
|
||||
// invoke smart contract call
|
||||
if err := w.client.Put(args); err != nil {
|
||||
return nil, errors.Wrap(err, "could not invoke smart contract")
|
||||
}
|
||||
|
||||
return cid, nil
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
// Get reads the container from NeoFS system by identifier
|
||||
|
@ -61,29 +23,7 @@ func (w *Wrapper) Put(cnr *Container) (*CID, error) {
|
|||
// If an empty slice is returned for the requested identifier,
|
||||
// storage.ErrNotFound error is returned.
|
||||
func (w *Wrapper) Get(cid CID) (*Container, error) {
|
||||
// prepare invocation arguments
|
||||
args := contract.GetArgs{}
|
||||
args.SetCID(cid.Bytes())
|
||||
|
||||
// invoke smart contract call
|
||||
values, err := w.client.Get(args)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not invoke smart contract")
|
||||
}
|
||||
|
||||
cnrBytes := values.Container()
|
||||
if len(cnrBytes) == 0 {
|
||||
return nil, storage.ErrNotFound
|
||||
}
|
||||
|
||||
cnr := new(Container)
|
||||
|
||||
// unmarshal the container
|
||||
if err := cnr.UnmarshalBinary(cnrBytes); err != nil {
|
||||
return nil, errors.Wrap(err, "could not unmarshal container")
|
||||
}
|
||||
|
||||
return cnr, nil
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
// Delete removes the container from NeoFS system
|
||||
|
@ -92,19 +32,7 @@ func (w *Wrapper) Get(cid CID) (*Container, error) {
|
|||
// Returns any error encountered that caused
|
||||
// the removal to interrupt.
|
||||
func (w *Wrapper) Delete(cid CID) error {
|
||||
// prepare invocation arguments
|
||||
args := contract.DeleteArgs{}
|
||||
args.SetCID(cid.Bytes())
|
||||
args.SetOwnerID(nil) // TODO: add owner ID when will appear.
|
||||
args.SetSignature(nil) // TODO: add CID signature when will appear.
|
||||
|
||||
// invoke smart contract call
|
||||
//
|
||||
// Note: errors.Wrap return nil on nil error arg.
|
||||
return errors.Wrap(
|
||||
w.client.Delete(args),
|
||||
"could not invoke smart contract",
|
||||
)
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
// List returns a list of container identifiers belonging
|
||||
|
@ -114,35 +42,5 @@ func (w *Wrapper) Delete(cid CID) error {
|
|||
// Returns the identifiers of all NeoFS containers if pointer
|
||||
// to owner identifier is nil.
|
||||
func (w *Wrapper) List(ownerID *OwnerID) ([]CID, error) {
|
||||
// prepare invocation arguments
|
||||
args := contract.ListArgs{}
|
||||
|
||||
// Note: by default owner identifier slice is nil,
|
||||
// so client won't attach invocation arguments.
|
||||
// This behavior matches the nil argument of current method.
|
||||
// If argument is not nil, we must specify owner identifier.
|
||||
if ownerID != nil {
|
||||
args.SetOwnerID(ownerID.Bytes())
|
||||
}
|
||||
|
||||
// invoke smart contract call
|
||||
values, err := w.client.List(args)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not invoke smart contract")
|
||||
}
|
||||
|
||||
binCIDList := values.CIDList()
|
||||
cidList := make([]CID, 0, len(binCIDList))
|
||||
|
||||
// unmarshal all container identifiers
|
||||
for i := range binCIDList {
|
||||
cid, err := refs.CIDFromBytes(binCIDList[i])
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "could not decode container ID #%d", i)
|
||||
}
|
||||
|
||||
cidList = append(cidList, cid)
|
||||
}
|
||||
|
||||
return cidList, nil
|
||||
panic("implement me")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue