2021-05-31 17:42:32 +00:00
|
|
|
package neofsid
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2021-11-09 20:52:29 +00:00
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
2021-05-31 17:42:32 +00:00
|
|
|
)
|
|
|
|
|
2022-01-31 11:04:59 +00:00
|
|
|
type CommonBindPrm struct {
|
2021-05-31 17:42:32 +00:00
|
|
|
ownerID []byte // NeoFS account identifier
|
|
|
|
|
|
|
|
keys [][]byte // list of serialized public keys
|
2021-11-11 07:39:01 +00:00
|
|
|
|
|
|
|
client.InvokePrmOptional
|
|
|
|
}
|
|
|
|
|
2022-01-31 11:04:59 +00:00
|
|
|
func (x *CommonBindPrm) SetOptionalPrm(prm client.InvokePrmOptional) {
|
2021-11-11 07:39:01 +00:00
|
|
|
x.InvokePrmOptional = prm
|
2021-05-31 17:42:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetOwnerID sets NeoFS account identifier.
|
2022-01-31 11:04:59 +00:00
|
|
|
func (x *CommonBindPrm) SetOwnerID(v []byte) {
|
2021-05-31 17:42:32 +00:00
|
|
|
x.ownerID = v
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetKeys sets list of public keys in a binary format.
|
2022-01-31 11:04:59 +00:00
|
|
|
func (x *CommonBindPrm) SetKeys(v [][]byte) {
|
2021-05-31 17:42:32 +00:00
|
|
|
x.keys = v
|
|
|
|
}
|
|
|
|
|
2022-01-31 11:04:59 +00:00
|
|
|
// AddKeys adds a list of public keys to/from NeoFS account.
|
|
|
|
func (x *Client) AddKeys(p CommonBindPrm) error {
|
2021-11-09 20:52:29 +00:00
|
|
|
prm := client.InvokePrm{}
|
|
|
|
|
2022-01-29 13:06:36 +00:00
|
|
|
prm.SetMethod(addKeysMethod)
|
2022-01-31 11:04:59 +00:00
|
|
|
prm.SetArgs(p.ownerID, p.keys)
|
|
|
|
prm.InvokePrmOptional = p.InvokePrmOptional
|
2021-11-09 20:52:29 +00:00
|
|
|
|
|
|
|
err := x.client.Invoke(prm)
|
2021-05-31 17:42:32 +00:00
|
|
|
if err != nil {
|
2022-01-29 13:06:36 +00:00
|
|
|
return fmt.Errorf("could not invoke method (%s): %w", addKeysMethod, err)
|
2021-05-31 17:42:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-01-31 11:04:59 +00:00
|
|
|
// RemoveKeys removes a list of public keys to/from NeoFS account.
|
|
|
|
func (x *Client) RemoveKeys(args CommonBindPrm) error {
|
2021-11-09 20:52:29 +00:00
|
|
|
prm := client.InvokePrm{}
|
|
|
|
|
2022-01-29 13:06:36 +00:00
|
|
|
prm.SetMethod(removeKeysMethod)
|
2021-11-09 20:52:29 +00:00
|
|
|
prm.SetArgs(args.ownerID, args.keys)
|
2021-11-11 07:39:01 +00:00
|
|
|
prm.InvokePrmOptional = args.InvokePrmOptional
|
2021-11-09 20:52:29 +00:00
|
|
|
|
|
|
|
err := x.client.Invoke(prm)
|
2021-05-31 17:42:32 +00:00
|
|
|
if err != nil {
|
2022-01-29 13:06:36 +00:00
|
|
|
return fmt.Errorf("could not invoke method (%s): %w", removeKeysMethod, err)
|
2021-05-31 17:42:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|