frostfs-node/pkg/morph/client/neofs/wrapper/bind.go
Pavel Karpy 3114be39d0 [#971] morph/neofs: Add optional parameters
Add optional parameters to the client call
signature. Group parameters of a client call
into struct to improve future codebase
support.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
2021-11-19 09:58:03 +03:00

62 lines
1.3 KiB
Go

package neofscontract
import (
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
neofscontract "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofs"
)
// 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
}
// ManageKeys binds/unbinds list of public keys from NeoFS account by script hash.
func (x *ClientWrapper) ManageKeys(prm ManageKeysPrm) error {
type args interface {
SetScriptHash([]byte)
SetKeys([][]byte)
SetOptionalPrm(optional client.InvokePrmOptional)
}
var (
a args
call func(args) error
)
if prm.bind {
a = new(neofscontract.BindKeysArgs)
call = func(a args) error {
return x.client.BindKeys(*a.(*neofscontract.BindKeysArgs))
}
} else {
a = new(neofscontract.UnbindKeysArgs)
call = func(a args) error {
return x.client.UnbindKeys(*a.(*neofscontract.UnbindKeysArgs))
}
}
a.SetScriptHash(prm.scriptHash)
a.SetKeys(prm.ks)
a.SetOptionalPrm(prm.InvokePrmOptional)
return call(a)
}