[#11] Trim the old functionality

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-08-21 14:32:03 +03:00 committed by Alex Vanin
parent 783ec72d56
commit a87fdab324
235 changed files with 39 additions and 36211 deletions

View file

@ -1,35 +1,11 @@
package wrapper
import (
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
"github.com/nspcc-dev/neofs-node/pkg/core/container"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/balance"
"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.OwnerID.
type OwnerID = container.OwnerID
// FIXME: correct the definition.
type OwnerID struct{}
// BalanceOf receives the amount of funds in the client's account
// through the Balance contract call, and returns it.
func (w *Wrapper) BalanceOf(ownerID OwnerID) (int64, error) {
// convert Neo wallet address to Uint160
u160, err := address.StringToUint160(ownerID.String())
if err != nil {
return 0, errors.Wrap(err, "could not convert wallet address to Uint160")
}
// prepare invocation arguments
args := balance.GetBalanceOfArgs{}
args.SetWallet(u160.BytesBE())
values, err := w.client.BalanceOf(args)
if err != nil {
return 0, errors.Wrap(err, "could not invoke smart contract")
}
return values.Amount(), nil
panic("implement me")
}

View file

@ -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")
}

View file

@ -1,33 +1,13 @@
package wrapper
import (
eacl "github.com/nspcc-dev/neofs-api-go/acl/extended"
"github.com/nspcc-dev/neofs-node/pkg/core/container/acl/extended/storage"
contract "github.com/nspcc-dev/neofs-node/pkg/morph/client/container"
"github.com/pkg/errors"
)
// Table represents extended ACL rule table.
//
// It is a type alias of
// github.com/nspcc-dev/neofs-node/pkg/core/container/acl/extended/storage.Table.
type Table = storage.Table
// FIXME: correct the definition.
type Table struct{}
// GetEACL reads the extended ACL table from NeoFS system
// through Container contract call.
func (w *Wrapper) GetEACL(cid CID) (Table, error) {
// prepare invocation arguments
args := contract.EACLArgs{}
args.SetCID(cid.Bytes())
// invoke smart contract call
values, err := w.client.EACL(args)
if err != nil {
return nil, errors.Wrap(err, "could not invoke smart contract")
}
// unmarshal and return eACL table
return eacl.UnmarshalTable(values.EACL())
panic("implement me")
}
// PutEACL saves the extended ACL table in NeoFS system
@ -35,17 +15,5 @@ func (w *Wrapper) GetEACL(cid CID) (Table, error) {
//
// Returns any error encountered that caused the saving to interrupt.
func (w *Wrapper) PutEACL(cid CID, table Table, sig []byte) error {
// prepare invocation arguments
args := contract.SetEACLArgs{}
args.SetEACL(eacl.MarshalTable(table))
args.SetCID(cid.Bytes())
args.SetSignature(sig)
// invoke smart contract call
//
// Note: errors.Wrap return nil on nil error arg.
return errors.Wrap(
w.client.SetEACL(args),
"could not invoke smart contract",
)
panic("implement me")
}

View file

@ -1,7 +1,6 @@
package wrapper
import (
"github.com/nspcc-dev/neofs-node/pkg/core/container/storage"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/container"
)
@ -12,10 +11,8 @@ import (
type Client = container.Client
// CID represents the container identifier.
//
// CID is a type alias of
// github.com/nspcc-dev/neofs-node/pkg/core/container/storage.CID.
type CID = storage.CID
// FIXME: correct the definition.
type CID struct{}
// Wrapper is a wrapper over container contract
// client which implements container storage and

View file

@ -1,37 +1,10 @@
package wrapper
import (
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
contract "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
"github.com/pkg/errors"
)
// NodeInfo groups information about NeoFS storage node.
type NodeInfo struct{}
// AddPeer registers peer in NeoFS network through
// Netmap contract call.
func (w *Wrapper) AddPeer(nodeInfo netmap.Info) error {
// prepare invocation arguments
args := contract.AddPeerArgs{}
info := contract.PeerInfo{}
info.SetPublicKey(nodeInfo.PublicKey())
info.SetAddress([]byte(nodeInfo.Address()))
opts := nodeInfo.Options()
binOpts := make([][]byte, 0, len(opts))
for i := range opts {
binOpts = append(binOpts, []byte(opts[i]))
}
info.SetOptions(binOpts)
args.SetInfo(info)
// invoke smart contract call
//
// Note: errors.Wrap returns nil on nil error arg.
return errors.Wrap(
w.client.AddPeer(args),
"could not invoke smart contract",
)
func (w *Wrapper) AddPeer(nodeInfo NodeInfo) error {
panic("implement me")
}

View file

@ -1,60 +1,12 @@
package wrapper
import (
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
contract "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
"github.com/pkg/errors"
)
// NetMap represents the NeoFS network map.
//
// It is a type alias of
// github.com/nspcc-dev/neofs-node/pkg/core/NetMap.
type NetMap = netmap.NetMap
// Info represents node information.
//
// It is a type alias of
// github.com/nspcc-dev/neofs-node/pkg/core/netmap.Info.
type Info = netmap.Info
// FIXME: correct the definition.
type NetMap struct{}
// GetNetMap receives information list about storage nodes
// through the Netmap contract call, composes network map
// from them and returns it.
func (w *Wrapper) GetNetMap() (*NetMap, error) {
// prepare invocation arguments
args := contract.GetNetMapArgs{}
// invoke smart contract call
values, err := w.client.NetMap(args)
if err != nil {
return nil, errors.Wrap(err, "could not invoke smart contract")
}
// parse response and fill the network map
nm := netmap.New()
peerList := values.Peers()
for i := range peerList {
info := Info{}
info.SetPublicKey(peerList[i].PublicKey())
info.SetAddress(string(peerList[i].Address()))
binOpts := peerList[i].Options()
opts := make([]string, 0, len(binOpts))
for j := range binOpts {
opts = append(opts, string(binOpts[j]))
}
info.SetOptions(opts)
if err := nm.AddNode(info); err != nil {
return nil, errors.Wrapf(err, "could not add node #%d to network map", i)
}
}
return nm, nil
panic("implement me")
}

View file

@ -1,23 +1,11 @@
package wrapper
import (
"github.com/nspcc-dev/neofs-node/pkg/core/netmap/epoch"
contract "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
"github.com/pkg/errors"
)
// Epoch represents the NeoFS epoch.
// FIXME: correct the definition.
type Epoch struct{}
// NewEpoch updates NeoFS epoch number through
// Netmap contract call.
func (w *Wrapper) NewEpoch(e epoch.Epoch) error {
// prepare invocation arguments
args := contract.NewEpochArgs{}
args.SetEpochNumber(int64(epoch.ToUint64(e)))
// invoke smart contract call
//
// Note: errors.Wrap returns nil on nil error arg.
return errors.Wrap(
w.client.NewEpoch(args),
"could not invoke smart contract",
)
func (w *Wrapper) NewEpoch(e Epoch) error {
panic("implement me")
}