forked from TrueCloudLab/frostfs-node
[#496] morph/container: Construct client wrapper in notary mode
Some of the client wrapper's methods should produce notary contract's invocations. In previous implementation all wrappers provided separate methods to do it. Since notary and non-notary invocation scenarios have very different goals, it makes sense to separate the scenarios of using the client wrapper at the stage of its creation. Define `Option` constructor for container client wrapper. Add `TryNotary` option which enables tries of the notary invocations on underlying static client. Mark all notary-dedicated methods as deprecated. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
b794aeab63
commit
9f122f279a
4 changed files with 38 additions and 2 deletions
|
@ -48,6 +48,8 @@ func Put(w *Wrapper, cnr *container.Container, sig *pkg.Signature) (*container.I
|
|||
//
|
||||
// Returns calculated container identifier and any error
|
||||
// encountered that caused the saving to interrupt.
|
||||
//
|
||||
// If TryNotary is provided, call notary contract.
|
||||
func (w *Wrapper) Put(cnr, key, sig []byte) error {
|
||||
if len(sig) == 0 || len(key) == 0 {
|
||||
return errNilArgument
|
||||
|
@ -136,6 +138,8 @@ func Delete(w *Wrapper, cid *container.ID, sig *pkg.Signature) error {
|
|||
//
|
||||
// Returns any error encountered that caused
|
||||
// the removal to interrupt.
|
||||
//
|
||||
// If TryNotary is provided, calls notary contract.
|
||||
func (w *Wrapper) Delete(cid, signature []byte) error {
|
||||
if len(signature) == 0 {
|
||||
return errNilArgument
|
||||
|
|
|
@ -56,6 +56,8 @@ func (w *Wrapper) GetEACL(cid *containerSDK.ID) (*eacl.Table, *pkg.Signature, er
|
|||
// along with sig.Key() and sig.Sign().
|
||||
//
|
||||
// Returns error if table is nil.
|
||||
//
|
||||
// If TryNotary is provided, calls notary contract.
|
||||
func PutEACL(w *Wrapper, table *eacl.Table, sig *pkg.Signature) error {
|
||||
if table == nil {
|
||||
return errNilArgument
|
||||
|
|
|
@ -14,6 +14,9 @@ func (w *Wrapper) StartEstimation(epoch uint64) error {
|
|||
|
||||
// StartEstimationNotary votes to produce start estimation notification through
|
||||
// notary contract.
|
||||
//
|
||||
// Deprecated: provide TryNotary() option to NewFromMorph
|
||||
// and use StartEstimation.
|
||||
func (w *Wrapper) StartEstimationNotary(epoch uint64) error {
|
||||
args := container.StartEstimation{}
|
||||
args.SetEpoch(int64(epoch))
|
||||
|
@ -31,6 +34,9 @@ func (w *Wrapper) StopEstimation(epoch uint64) error {
|
|||
|
||||
// StopEstimationNotary votes to produce stop estimation notification through
|
||||
// notary contract.
|
||||
//
|
||||
// Deprecated: provide TryNotary() option to NewFromMorph
|
||||
// and use StopEstimation.
|
||||
func (w *Wrapper) StopEstimationNotary(epoch uint64) error {
|
||||
args := container.StopEstimation{}
|
||||
args.SetEpoch(int64(epoch))
|
||||
|
|
|
@ -21,9 +21,33 @@ type Wrapper struct {
|
|||
client *container.Client
|
||||
}
|
||||
|
||||
// Option allows to set an optional
|
||||
// parameter of ClientWrapper.
|
||||
type Option func(*opts)
|
||||
|
||||
type opts []client.StaticClientOption
|
||||
|
||||
func defaultOpts() *opts {
|
||||
return new(opts)
|
||||
}
|
||||
|
||||
// TryNotaryInvoke returns option to enable
|
||||
// notary invocation tries.
|
||||
func TryNotary() Option {
|
||||
return func(o *opts) {
|
||||
*o = append(*o, client.TryNotary())
|
||||
}
|
||||
}
|
||||
|
||||
// NewFromMorph returns the wrapper instance from the raw morph client.
|
||||
func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8) (*Wrapper, error) {
|
||||
staticClient, err := client.NewStatic(cli, contract, fee)
|
||||
func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8, opts ...Option) (*Wrapper, error) {
|
||||
o := defaultOpts()
|
||||
|
||||
for i := range opts {
|
||||
opts[i](o)
|
||||
}
|
||||
|
||||
staticClient, err := client.NewStatic(cli, contract, fee, ([]client.StaticClientOption)(*o)...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("can't create container static client: %w", err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue