forked from TrueCloudLab/frostfs-node
c0093b2b79
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
package neofsid
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/neofsid"
|
|
)
|
|
|
|
// ClientWrapper is a wrapper over NeoFS ID contract
|
|
// client which provides convenient methods for
|
|
// working with a contract.
|
|
//
|
|
// Working ClientWrapper must be created via Wrap.
|
|
type ClientWrapper neofsid.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 ID contract.
|
|
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 ID contract: %w", err)
|
|
}
|
|
|
|
return (*ClientWrapper)(neofsid.New(sc)), nil
|
|
}
|