[#496] morph/client: provide notary options on client creation

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2021-06-01 12:29:32 +03:00 committed by Alex Vanin
parent 7cf0093012
commit 458fc4f5ae
5 changed files with 68 additions and 46 deletions

View file

@ -2,6 +2,7 @@ package client
import (
"context"
"fmt"
"time"
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
@ -27,6 +28,8 @@ type cfg struct {
gas util.Uint160 // native gas script-hash
waitInterval time.Duration
notaryOpts []NotaryOption
}
const (
@ -93,14 +96,22 @@ func New(key *keys.PrivateKey, endpoint string, opts ...Option) (*Client, error)
return nil, err
}
return &Client{
c := &Client{
logger: cfg.logger,
client: cli,
acc: account,
gas: gas,
designate: designate,
waitInterval: cfg.waitInterval,
}, nil
}
if len(cfg.notaryOpts) != 0 {
if err := c.enableNotarySupport(cfg.notaryOpts...); err != nil {
return nil, fmt.Errorf("can't enable notary support: %w", err)
}
}
return c, nil
}
// WithContext returns a client constructor option that
@ -144,3 +155,10 @@ func WithLogger(logger *logger.Logger) Option {
}
}
}
// WithNotaryOptions enables notary support and sets notary options for the client.
func WithNotaryOptions(opts ...NotaryOption) Option {
return func(c *cfg) {
c.notaryOpts = opts
}
}