2022-12-23 17:35:35 +00:00
|
|
|
package frostfscontract
|
2021-05-31 17:22:43 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2021-11-09 20:52:29 +00:00
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
|
2021-05-31 17:22:43 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type commonBindArgs struct {
|
|
|
|
scriptHash []byte // script hash of account identifier
|
|
|
|
|
|
|
|
keys [][]byte // list of serialized public keys
|
2021-11-10 10:41:27 +00:00
|
|
|
|
|
|
|
client.InvokePrmOptional
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetOptionalPrm sets optional client parameters.
|
|
|
|
func (x *commonBindArgs) SetOptionalPrm(op client.InvokePrmOptional) {
|
|
|
|
x.InvokePrmOptional = op
|
2021-05-31 17:22:43 +00:00
|
|
|
}
|
|
|
|
|
2023-02-05 15:59:38 +00:00
|
|
|
// SetScriptHash sets script hash of the FrostFS account identifier.
|
2021-05-31 17:22:43 +00:00
|
|
|
func (x *commonBindArgs) SetScriptHash(v []byte) {
|
|
|
|
x.scriptHash = v
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// SetKeys sets a list of public keys in a binary format.
|
2021-05-31 17:22:43 +00:00
|
|
|
func (x *commonBindArgs) SetKeys(v [][]byte) {
|
|
|
|
x.keys = v
|
|
|
|
}
|
|
|
|
|
2022-01-31 10:15:36 +00:00
|
|
|
// BindKeysPrm groups parameters of BindKeys operation.
|
|
|
|
type BindKeysPrm struct {
|
|
|
|
commonBindArgs
|
|
|
|
}
|
2021-11-09 20:52:29 +00:00
|
|
|
|
2023-02-05 15:59:38 +00:00
|
|
|
// BindKeys binds list of public keys from FrostFS account by script hash.
|
2022-01-31 10:15:36 +00:00
|
|
|
func (x *Client) BindKeys(p BindKeysPrm) error {
|
|
|
|
prm := client.InvokePrm{}
|
2022-01-29 13:06:36 +00:00
|
|
|
prm.SetMethod(bindKeysMethod)
|
2022-01-31 10:15:36 +00:00
|
|
|
prm.SetArgs(p.scriptHash, p.keys)
|
|
|
|
prm.InvokePrmOptional = p.InvokePrmOptional
|
2021-11-09 20:52:29 +00:00
|
|
|
|
|
|
|
err := x.client.Invoke(prm)
|
2021-05-31 17:22:43 +00:00
|
|
|
if err != nil {
|
2022-01-29 13:06:36 +00:00
|
|
|
return fmt.Errorf("could not invoke method (%s): %w", bindKeysMethod, err)
|
2021-05-31 17:22:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-01-31 10:15:36 +00:00
|
|
|
// UnbindKeysPrm groups parameters of UnbindKeys operation.
|
|
|
|
type UnbindKeysPrm struct {
|
|
|
|
commonBindArgs
|
|
|
|
}
|
|
|
|
|
2021-05-31 17:22:43 +00:00
|
|
|
// UnbindKeys invokes the call of key unbinding method
|
2023-02-05 15:59:38 +00:00
|
|
|
// of FrostFS contract.
|
2022-01-31 10:15:36 +00:00
|
|
|
func (x *Client) UnbindKeys(args UnbindKeysPrm) error {
|
2021-11-09 20:52:29 +00:00
|
|
|
prm := client.InvokePrm{}
|
2022-01-29 13:06:36 +00:00
|
|
|
prm.SetMethod(unbindKeysMethod)
|
2021-11-09 20:52:29 +00:00
|
|
|
prm.SetArgs(args.scriptHash, args.keys)
|
2021-11-10 10:41:27 +00:00
|
|
|
prm.InvokePrmOptional = args.InvokePrmOptional
|
2021-11-09 20:52:29 +00:00
|
|
|
|
|
|
|
err := x.client.Invoke(prm)
|
2021-05-31 17:22:43 +00:00
|
|
|
if err != nil {
|
2022-01-29 13:06:36 +00:00
|
|
|
return fmt.Errorf("could not invoke method (%s): %w", unbindKeysMethod, err)
|
2021-05-31 17:22:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|