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