2020-07-24 13:54:03 +00:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
2021-11-09 20:52:29 +00:00
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
2020-07-24 13:54:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// PutArgs groups the arguments
|
|
|
|
// of put container invocation call.
|
|
|
|
type PutArgs struct {
|
|
|
|
cnr []byte // container in a binary format
|
|
|
|
|
|
|
|
sig []byte // binary container signature
|
2020-09-02 16:25:46 +00:00
|
|
|
|
|
|
|
publicKey []byte // public key of container owner
|
2021-05-25 09:25:55 +00:00
|
|
|
|
|
|
|
token []byte // binary session token
|
2021-10-12 14:46:45 +00:00
|
|
|
|
|
|
|
name, zone string // native name and zone
|
2021-11-12 15:14:55 +00:00
|
|
|
|
|
|
|
client.InvokePrmOptional
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
|
|
|
|
2020-09-02 16:25:46 +00:00
|
|
|
// SetPublicKey sets the public key of container owner
|
2020-07-24 13:54:03 +00:00
|
|
|
// in a binary format.
|
2020-09-02 16:25:46 +00:00
|
|
|
func (p *PutArgs) SetPublicKey(v []byte) {
|
|
|
|
p.publicKey = v
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetContainer sets the container structure
|
|
|
|
// in a binary format.
|
|
|
|
func (p *PutArgs) SetContainer(v []byte) {
|
|
|
|
p.cnr = v
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetSignature sets the container structure
|
|
|
|
// owner's signature.
|
|
|
|
func (p *PutArgs) SetSignature(v []byte) {
|
|
|
|
p.sig = v
|
|
|
|
}
|
|
|
|
|
2021-05-25 15:34:56 +00:00
|
|
|
// SetSessionToken sets token of the session
|
|
|
|
// within which the container was created
|
|
|
|
// in a binary format.
|
|
|
|
func (p *PutArgs) SetSessionToken(v []byte) {
|
|
|
|
p.token = v
|
|
|
|
}
|
|
|
|
|
2021-10-12 14:46:45 +00:00
|
|
|
// SetNativeNameWithZone sets container native name and its zone.
|
|
|
|
func (p *PutArgs) SetNativeNameWithZone(name, zone string) {
|
|
|
|
p.name, p.zone = name, zone
|
|
|
|
}
|
|
|
|
|
|
|
|
// Put invokes the call of put (named if name is set) container method
|
2020-07-24 13:54:03 +00:00
|
|
|
// of NeoFS Container contract.
|
|
|
|
func (c *Client) Put(args PutArgs) error {
|
2021-10-12 14:46:45 +00:00
|
|
|
var (
|
|
|
|
method string
|
2021-11-09 20:52:29 +00:00
|
|
|
prm client.InvokePrm
|
2021-05-18 08:12:51 +00:00
|
|
|
)
|
|
|
|
|
2021-10-12 14:46:45 +00:00
|
|
|
if args.name != "" {
|
|
|
|
method = c.putNamedMethod
|
|
|
|
|
2021-11-09 20:52:29 +00:00
|
|
|
prm.SetArgs(args.cnr, args.sig, args.publicKey, args.token, args.name, args.zone)
|
|
|
|
} else {
|
2021-10-12 14:46:45 +00:00
|
|
|
method = c.putMethod
|
2021-11-09 20:52:29 +00:00
|
|
|
|
|
|
|
prm.SetArgs(args.cnr, args.sig, args.publicKey, args.token)
|
2021-10-12 14:46:45 +00:00
|
|
|
}
|
|
|
|
|
2021-11-09 20:52:29 +00:00
|
|
|
prm.SetMethod(method)
|
2021-11-12 15:14:55 +00:00
|
|
|
prm.InvokePrmOptional = args.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 {
|
2021-10-12 14:46:45 +00:00
|
|
|
return fmt.Errorf("could not invoke method (%s): %w", method, err)
|
2021-05-18 08:12:51 +00:00
|
|
|
}
|
2021-10-12 14:46:45 +00:00
|
|
|
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|