2020-07-24 13:54:03 +00:00
|
|
|
package container
|
|
|
|
|
2021-05-18 08:12:51 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
2021-11-09 20:52:29 +00:00
|
|
|
|
2022-01-31 13:34:01 +00:00
|
|
|
core "github.com/nspcc-dev/neofs-node/pkg/core/container"
|
2021-11-09 20:52:29 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
2021-05-18 08:12:51 +00:00
|
|
|
)
|
2020-07-24 13:54:03 +00:00
|
|
|
|
2022-01-31 13:34:01 +00:00
|
|
|
// 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
|
|
|
|
}
|
2020-07-24 13:54:03 +00:00
|
|
|
|
2022-01-31 13:34:01 +00:00
|
|
|
binToken, err := witness.SessionToken().Marshal()
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("could not marshal session token: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.Delete(
|
|
|
|
DeletePrm{
|
|
|
|
cid: id.ToV2().GetValue(),
|
|
|
|
signature: witness.Signature(),
|
|
|
|
token: binToken,
|
|
|
|
})
|
|
|
|
}
|
2021-05-26 09:59:16 +00:00
|
|
|
|
2022-01-31 13:34:01 +00:00
|
|
|
// DeletePrm groups parameters of Delete client operation.
|
|
|
|
type DeletePrm struct {
|
|
|
|
cid []byte
|
|
|
|
signature []byte
|
|
|
|
token []byte
|
2021-11-12 15:14:55 +00:00
|
|
|
|
|
|
|
client.InvokePrmOptional
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
|
|
|
|
2022-01-31 13:34:01 +00:00
|
|
|
// SetCID sets container ID.
|
|
|
|
func (d *DeletePrm) SetCID(cid []byte) {
|
|
|
|
d.cid = cid
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
|
|
|
|
2022-01-31 13:34:01 +00:00
|
|
|
// SetSignature sets signature.
|
|
|
|
func (d *DeletePrm) SetSignature(signature []byte) {
|
|
|
|
d.signature = signature
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
|
|
|
|
2022-01-31 13:34:01 +00:00
|
|
|
// SetToken sets session token.
|
|
|
|
func (d *DeletePrm) SetToken(token []byte) {
|
|
|
|
d.token = token
|
2021-05-26 11:01:38 +00:00
|
|
|
}
|
|
|
|
|
2022-01-31 13:34:01 +00:00
|
|
|
// 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
|
|
|
|
}
|
2021-11-09 20:52:29 +00:00
|
|
|
|
2022-01-31 13:34:01 +00:00
|
|
|
prm := client.InvokePrm{}
|
2022-01-29 13:06:36 +00:00
|
|
|
prm.SetMethod(deleteMethod)
|
2022-01-31 13:34:01 +00:00
|
|
|
prm.SetArgs(p.cid, p.signature, p.token)
|
|
|
|
prm.InvokePrmOptional = p.InvokePrmOptional
|
2021-11-09 20:52:29 +00:00
|
|
|
|
|
|
|
err := c.client.Invoke(prm)
|
2021-05-18 08:12:51 +00:00
|
|
|
if err != nil {
|
2022-01-29 13:06:36 +00:00
|
|
|
return fmt.Errorf("could not invoke method (%s): %w", deleteMethod, err)
|
2021-05-18 08:12:51 +00:00
|
|
|
}
|
|
|
|
return nil
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|