[#625] client/container: remove intermediate wrapper

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-01-31 16:34:01 +03:00 committed by Alex Vanin
parent 819d80a7a9
commit c34cfa1f35
28 changed files with 556 additions and 1168 deletions

View file

@ -3,51 +3,75 @@ package container
import (
"fmt"
core "github.com/nspcc-dev/neofs-node/pkg/core/container"
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
)
// DeleteArgs groups the arguments
// of delete container invocation call.
type DeleteArgs struct {
cid []byte // container identifier
// Delete marshals container ID, and passes it to Wrapper's Delete method
// along with signature and session token.
//
// Returns error if container ID is nil.
func Delete(c *Client, witness core.RemovalWitness) error {
id := witness.ContainerID()
if id == nil {
return errNilArgument
}
sig []byte // container identifier signature
binToken, err := witness.SessionToken().Marshal()
if err != nil {
return fmt.Errorf("could not marshal session token: %w", err)
}
token []byte // binary session token
return c.Delete(
DeletePrm{
cid: id.ToV2().GetValue(),
signature: witness.Signature(),
token: binToken,
})
}
// DeletePrm groups parameters of Delete client operation.
type DeletePrm struct {
cid []byte
signature []byte
token []byte
client.InvokePrmOptional
}
// SetCID sets the container identifier
// in a binary format.
func (p *DeleteArgs) SetCID(v []byte) {
p.cid = v
// SetCID sets container ID.
func (d *DeletePrm) SetCID(cid []byte) {
d.cid = cid
}
// SetSignature sets the container identifier
// owner's signature.
func (p *DeleteArgs) SetSignature(v []byte) {
p.sig = v
// SetSignature sets signature.
func (d *DeletePrm) SetSignature(signature []byte) {
d.signature = signature
}
// SetSessionToken sets token of the session
// within which the container was removed
// in a NeoFS API binary format.
func (p *DeleteArgs) SetSessionToken(v []byte) {
p.token = v
// SetToken sets session token.
func (d *DeletePrm) SetToken(token []byte) {
d.token = token
}
// Delete invokes the call of delete container
// method of NeoFS Container contract.
func (c *Client) Delete(args DeleteArgs) error {
// Delete removes the container from NeoFS system
// through Container contract call.
//
// Returns any error encountered that caused
// the removal to interrupt.
//
// If TryNotary is provided, calls notary contract.
func (c *Client) Delete(p DeletePrm) error {
if len(p.signature) == 0 {
return errNilArgument
}
prm := client.InvokePrm{}
prm.SetMethod(deleteMethod)
prm.SetArgs(args.cid, args.sig, args.token)
prm.InvokePrmOptional = args.InvokePrmOptional
prm.SetArgs(p.cid, p.signature, p.token)
prm.InvokePrmOptional = p.InvokePrmOptional
err := c.client.Invoke(prm)
if err != nil {
return fmt.Errorf("could not invoke method (%s): %w", deleteMethod, err)
}