2021-05-31 17:25:34 +00:00
|
|
|
package neofscontract
|
|
|
|
|
|
|
|
import (
|
2021-11-10 10:41:27 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
2021-05-31 17:25:34 +00:00
|
|
|
neofscontract "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofs"
|
|
|
|
)
|
|
|
|
|
2021-11-10 10:41:27 +00:00
|
|
|
// ManageKeysPrm groups parameters of ManageKeys operation.
|
|
|
|
type ManageKeysPrm struct {
|
|
|
|
scriptHash []byte
|
|
|
|
ks [][]byte
|
|
|
|
bind bool
|
|
|
|
|
|
|
|
client.InvokePrmOptional
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetScriptHash sets script hash.
|
|
|
|
func (m *ManageKeysPrm) SetScriptHash(scriptHash []byte) {
|
|
|
|
m.scriptHash = scriptHash
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetKeys sets keys.
|
|
|
|
func (m *ManageKeysPrm) SetKeys(ks [][]byte) {
|
|
|
|
m.ks = ks
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetBind sets operation type: bind/unbind.
|
|
|
|
func (m *ManageKeysPrm) SetBind(bind bool) {
|
|
|
|
m.bind = bind
|
|
|
|
}
|
|
|
|
|
2021-05-31 17:25:34 +00:00
|
|
|
// ManageKeys binds/unbinds list of public keys from NeoFS account by script hash.
|
2021-11-10 10:41:27 +00:00
|
|
|
func (x *ClientWrapper) ManageKeys(prm ManageKeysPrm) error {
|
2021-05-31 17:25:34 +00:00
|
|
|
type args interface {
|
|
|
|
SetScriptHash([]byte)
|
|
|
|
SetKeys([][]byte)
|
2021-11-10 10:41:27 +00:00
|
|
|
SetOptionalPrm(optional client.InvokePrmOptional)
|
2021-05-31 17:25:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
a args
|
|
|
|
call func(args) error
|
|
|
|
)
|
|
|
|
|
2021-11-10 10:41:27 +00:00
|
|
|
if prm.bind {
|
2021-05-31 17:25:34 +00:00
|
|
|
a = new(neofscontract.BindKeysArgs)
|
|
|
|
call = func(a args) error {
|
2021-09-15 10:48:00 +00:00
|
|
|
return x.client.BindKeys(*a.(*neofscontract.BindKeysArgs))
|
2021-05-31 17:25:34 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
a = new(neofscontract.UnbindKeysArgs)
|
|
|
|
call = func(a args) error {
|
2021-09-15 10:48:00 +00:00
|
|
|
return x.client.UnbindKeys(*a.(*neofscontract.UnbindKeysArgs))
|
2021-05-31 17:25:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-10 10:41:27 +00:00
|
|
|
a.SetScriptHash(prm.scriptHash)
|
|
|
|
a.SetKeys(prm.ks)
|
|
|
|
a.SetOptionalPrm(prm.InvokePrmOptional)
|
2021-05-31 17:25:34 +00:00
|
|
|
|
|
|
|
return call(a)
|
|
|
|
}
|