[#755] morph: Drop FrostFSID contract usage

Unused.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-11-20 14:32:26 +03:00
parent d5c9dd3c83
commit 1cd2bfe51a
18 changed files with 16 additions and 844 deletions

View file

@ -1,71 +0,0 @@
package frostfscontract
import (
"fmt"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
)
type commonBindArgs struct {
scriptHash []byte // script hash of account identifier
keys [][]byte // list of serialized public keys
client.InvokePrmOptional
}
// SetOptionalPrm sets optional client parameters.
func (x *commonBindArgs) SetOptionalPrm(op client.InvokePrmOptional) {
x.InvokePrmOptional = op
}
// SetScriptHash sets script hash of the FrostFS account identifier.
func (x *commonBindArgs) SetScriptHash(v []byte) {
x.scriptHash = v
}
// SetKeys sets a list of public keys in a binary format.
func (x *commonBindArgs) SetKeys(v [][]byte) {
x.keys = v
}
// BindKeysPrm groups parameters of BindKeys operation.
type BindKeysPrm struct {
commonBindArgs
}
// BindKeys binds list of public keys from FrostFS account by script hash.
func (x *Client) BindKeys(p BindKeysPrm) error {
prm := client.InvokePrm{}
prm.SetMethod(bindKeysMethod)
prm.SetArgs(p.scriptHash, p.keys)
prm.InvokePrmOptional = p.InvokePrmOptional
_, err := x.client.Invoke(prm)
if err != nil {
return fmt.Errorf("could not invoke method (%s): %w", bindKeysMethod, err)
}
return nil
}
// UnbindKeysPrm groups parameters of UnbindKeys operation.
type UnbindKeysPrm struct {
commonBindArgs
}
// UnbindKeys invokes the call of key unbinding method
// of FrostFS contract.
func (x *Client) UnbindKeys(args UnbindKeysPrm) error {
prm := client.InvokePrm{}
prm.SetMethod(unbindKeysMethod)
prm.SetArgs(args.scriptHash, args.keys)
prm.InvokePrmOptional = args.InvokePrmOptional
_, err := x.client.Invoke(prm)
if err != nil {
return fmt.Errorf("could not invoke method (%s): %w", unbindKeysMethod, err)
}
return nil
}

View file

@ -21,8 +21,6 @@ type Client struct {
}
const (
bindKeysMethod = "bind"
unbindKeysMethod = "unbind"
alphabetUpdateMethod = "alphabetUpdate"
chequeMethod = "cheque"
)

View file

@ -1,61 +0,0 @@
package frostfsid
import (
"fmt"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
)
type CommonBindPrm struct {
ownerID []byte // FrostFS account identifier
keys [][]byte // list of serialized public keys
client.InvokePrmOptional
}
func (x *CommonBindPrm) SetOptionalPrm(prm client.InvokePrmOptional) {
x.InvokePrmOptional = prm
}
// SetOwnerID sets FrostFS account identifier.
func (x *CommonBindPrm) SetOwnerID(v []byte) {
x.ownerID = v
}
// SetKeys sets a list of public keys in a binary format.
func (x *CommonBindPrm) SetKeys(v [][]byte) {
x.keys = v
}
// AddKeys adds a list of public keys to/from FrostFS account.
func (x *Client) AddKeys(p CommonBindPrm) error {
prm := client.InvokePrm{}
prm.SetMethod(addKeysMethod)
prm.SetArgs(p.ownerID, p.keys)
prm.InvokePrmOptional = p.InvokePrmOptional
_, err := x.client.Invoke(prm)
if err != nil {
return fmt.Errorf("could not invoke method (%s): %w", addKeysMethod, err)
}
return nil
}
// RemoveKeys removes a list of public keys to/from FrostFS account.
func (x *Client) RemoveKeys(args CommonBindPrm) error {
prm := client.InvokePrm{}
prm.SetMethod(removeKeysMethod)
prm.SetArgs(args.ownerID, args.keys)
prm.InvokePrmOptional = args.InvokePrmOptional
_, err := x.client.Invoke(prm)
if err != nil {
return fmt.Errorf("could not invoke method (%s): %w", removeKeysMethod, err)
}
return nil
}

View file

@ -1,72 +0,0 @@
package frostfsid
import (
"fmt"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
"github.com/nspcc-dev/neo-go/pkg/util"
)
// Client is a wrapper over StaticClient
// which makes calls with the names and arguments
// of the FrostFS ID contract.
//
// Working client must be created via constructor New.
// Using the Client that has been created with new(Client)
// expression (or just declaring a Client variable) is unsafe
// and can lead to panic.
type Client struct {
client *client.StaticClient // static FrostFS ID contract client
}
const (
keyListingMethod = "key"
addKeysMethod = "addKey"
removeKeysMethod = "removeKey"
)
// NewFromMorph wraps client to work with FrostFS ID contract.
func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8, opts ...Option) (*Client, error) {
o := defaultOpts()
for i := range opts {
opts[i](o)
}
sc, err := client.NewStatic(cli, contract, fee, ([]client.StaticClientOption)(*o)...)
if err != nil {
return nil, fmt.Errorf("could not create client of FrostFS ID contract: %w", err)
}
return &Client{client: sc}, nil
}
// Option allows to set an optional
// parameter of ClientWrapper.
type Option func(*opts)
type opts []client.StaticClientOption
func defaultOpts() *opts {
return new(opts)
}
// TryNotary returns option to enable
// notary invocation tries.
func TryNotary() Option {
return func(o *opts) {
*o = append(*o, client.TryNotary())
}
}
// AsAlphabet returns option to sign main TX
// of notary requests with client's private
// key.
//
// Considered to be used by IR nodes only.
func AsAlphabet() Option {
return func(o *opts) {
*o = append(*o, client.AsAlphabet())
}
}

View file

@ -1,54 +0,0 @@
package frostfsid
import (
"crypto/elliptic"
"fmt"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
)
// AccountKeysPrm groups parameters of AccountKeys operation.
type AccountKeysPrm struct {
id user.ID
}
// SetID sets owner ID.
func (a *AccountKeysPrm) SetID(id user.ID) {
a.id = id
}
// AccountKeys requests public keys of FrostFS account from FrostFS ID contract.
func (x *Client) AccountKeys(p AccountKeysPrm) (keys.PublicKeys, error) {
prm := client.TestInvokePrm{}
prm.SetMethod(keyListingMethod)
prm.SetArgs(p.id.WalletBytes())
items, err := x.client.TestInvoke(prm)
if err != nil {
return nil, fmt.Errorf("could not perform test invocation (%s): %w", keyListingMethod, err)
} else if ln := len(items); ln != 1 {
return nil, fmt.Errorf("unexpected stack item count (%s): %d", keyListingMethod, ln)
}
items, err = client.ArrayFromStackItem(items[0])
if err != nil {
return nil, fmt.Errorf("1st stack item must be an array (%s)", keyListingMethod)
}
pubs := make(keys.PublicKeys, len(items))
for i := range items {
rawPub, err := client.BytesFromStackItem(items[i])
if err != nil {
return nil, fmt.Errorf("invalid stack item, expected byte array (%s)", keyListingMethod)
}
pubs[i], err = keys.NewPublicKeyFromBytes(rawPub, elliptic.P256())
if err != nil {
return nil, fmt.Errorf("received invalid key (%s): %w", keyListingMethod, err)
}
}
return pubs, nil
}