From c90f054f35db2d74baf4ac5cd5aecf239180b9d7 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Thu, 1 Jul 2021 20:00:47 +0300 Subject: [PATCH] [#658] morph/neofs: Add TryNotary() option Signed-off-by: Alex Vanin --- pkg/innerring/innerring.go | 2 +- pkg/morph/client/neofs/wrapper/client.go | 28 ++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/pkg/innerring/innerring.go b/pkg/innerring/innerring.go index 82c3da69f..9c92c4417 100644 --- a/pkg/innerring/innerring.go +++ b/pkg/innerring/innerring.go @@ -423,7 +423,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error } neofsClient, err := neofsWrapper.NewFromMorph(server.mainnetClient, server.contracts.neofs, - server.feeConfig.MainChainFee()) + server.feeConfig.MainChainFee(), neofsWrapper.TryNotary()) if err != nil { return nil, err } diff --git a/pkg/morph/client/neofs/wrapper/client.go b/pkg/morph/client/neofs/wrapper/client.go index 2d647f57f..8d038ab16 100644 --- a/pkg/morph/client/neofs/wrapper/client.go +++ b/pkg/morph/client/neofs/wrapper/client.go @@ -16,9 +16,33 @@ import ( // Working ClientWrapper must be created via NewFromMorph. type ClientWrapper neofscontract.Client +// 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()) + } +} + // NewFromMorph wraps client to work with NeoFS contract. -func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8) (*ClientWrapper, error) { - sc, err := client.NewStatic(cli, contract, fee, client.TryNotary()) +func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8, opts ...Option) (*ClientWrapper, 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 NeoFS contract: %w", err) }