frostfs-node/pkg/morph/client/container/client.go
Evgenii Stratonikov 84b4051b4d
All checks were successful
Tests and linters / Run gofumpt (pull_request) Successful in 3m42s
DCO action / DCO (pull_request) Successful in 4m23s
Vulncheck / Vulncheck (pull_request) Successful in 5m24s
Build / Build Components (pull_request) Successful in 5m59s
Tests and linters / Staticcheck (pull_request) Successful in 5m58s
Tests and linters / gopls check (pull_request) Successful in 6m3s
Pre-commit hooks / Pre-commit (pull_request) Successful in 6m13s
Tests and linters / Tests with -race (pull_request) Successful in 6m13s
Tests and linters / Lint (pull_request) Successful in 6m19s
Tests and linters / Tests (pull_request) Successful in 7m43s
Tests and linters / Run gofumpt (push) Successful in 2m13s
Vulncheck / Vulncheck (push) Successful in 2m50s
Tests and linters / Staticcheck (push) Successful in 3m0s
Build / Build Components (push) Successful in 3m36s
Pre-commit hooks / Pre-commit (push) Successful in 3m40s
Tests and linters / gopls check (push) Successful in 4m16s
Tests and linters / Lint (push) Successful in 4m27s
Tests and linters / Tests (push) Successful in 4m31s
Tests and linters / Tests with -race (push) Successful in 5m26s
[#1538] morph/container: Make opts struct similar to that of other contracts
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2024-12-04 15:30:58 +03:00

86 lines
2.2 KiB
Go

package container
import (
"errors"
"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 Container 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 Container contract client
}
const (
putMethod = "put"
deleteMethod = "delete"
getMethod = "get"
listMethod = "list"
containersOfMethod = "containersOf"
deletionInfoMethod = "deletionInfo"
// putNamedMethod is method name for container put with an alias. It is exported to provide custom fee.
putNamedMethod = "putNamed"
)
var errNilArgument = errors.New("empty argument")
// NewFromMorph returns the wrapper instance from the raw morph client.
//
// Specified fee is used for all operations by default. If WithCustomFeeForNamedPut is provided,
// the customized fee is used for Put operations with named containers.
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, *o...)
if err != nil {
return nil, fmt.Errorf("create 'container' contract client: %w", err)
}
return &Client{client: sc}, nil
}
// Morph returns raw morph client.
func (c Client) Morph() *client.Client {
return c.client.Morph()
}
// ContractAddress returns the address of the associated contract.
func (c Client) ContractAddress() util.Uint160 {
return c.client.ContractAddress()
}
// Option allows to set an optional
// parameter of Wrapper.
type Option func(*opts)
type opts []client.StaticClientOption
func defaultOpts() *opts {
return &opts{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())
}
}