mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-25 23:42:23 +00:00
rpcclient: add Waiter.Config
Include Waiter.PollConfig into Waiter.Config and use extended Waiter configuration where needed. Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
This commit is contained in:
parent
92c6361be8
commit
42555668da
2 changed files with 20 additions and 14 deletions
|
@ -106,10 +106,10 @@ type Options struct {
|
||||||
// before it's signed (other methods that perform test invocations
|
// before it's signed (other methods that perform test invocations
|
||||||
// use CheckerModifier). MakeUnsigned* methods do not run it.
|
// use CheckerModifier). MakeUnsigned* methods do not run it.
|
||||||
Modifier TransactionModifier
|
Modifier TransactionModifier
|
||||||
// waiter.PollConfig is used by [waiter.Waiter] constructor to customize
|
// WaiterConfig is used by [waiter.Waiter] constructor to customize
|
||||||
// [waiter.PollingBased] behaviour. This option may be kept empty for default
|
// awaiting behaviour. This option may be kept empty for default
|
||||||
// polling behaviour.
|
// awaiting behaviour.
|
||||||
waiter.PollConfig
|
WaiterConfig waiter.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates an Actor instance using the specified RPC interface and the set of
|
// New creates an Actor instance using the specified RPC interface and the set of
|
||||||
|
@ -187,7 +187,7 @@ func NewTuned(ra RPCActor, signers []SignerAccount, opts Options) (*Actor, error
|
||||||
if opts.Modifier != nil {
|
if opts.Modifier != nil {
|
||||||
a.opts.Modifier = opts.Modifier
|
a.opts.Modifier = opts.Modifier
|
||||||
}
|
}
|
||||||
a.Waiter = waiter.NewCustom(ra, a.version, opts.PollConfig)
|
a.Waiter = waiter.NewCustom(ra, a.version, opts.WaiterConfig)
|
||||||
return a, err
|
return a, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -90,6 +90,12 @@ type PollingBased struct {
|
||||||
config PollConfig
|
config PollConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Config is a unified configuration for [Waiter] implementations that allows to
|
||||||
|
// customize awaiting behaviour.
|
||||||
|
type Config struct {
|
||||||
|
PollConfig
|
||||||
|
}
|
||||||
|
|
||||||
// PollConfig is a configuration for PollingBased waiter.
|
// PollConfig is a configuration for PollingBased waiter.
|
||||||
type PollConfig struct {
|
type PollConfig struct {
|
||||||
// PollInterval is a time interval between subsequent polls. If not set, then
|
// PollInterval is a time interval between subsequent polls. If not set, then
|
||||||
|
@ -118,7 +124,7 @@ func errIsAlreadyExists(err error) bool {
|
||||||
// or not an implementation of these two interfaces. It returns websocket-based
|
// or not an implementation of these two interfaces. It returns websocket-based
|
||||||
// waiter, polling-based waiter or a stub correspondingly.
|
// waiter, polling-based waiter or a stub correspondingly.
|
||||||
func New(base any, v *result.Version) Waiter {
|
func New(base any, v *result.Version) Waiter {
|
||||||
return NewCustom(base, v, PollConfig{})
|
return NewCustom(base, v, Config{})
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCustom creates Waiter instance. It can be either websocket-based or
|
// NewCustom creates Waiter instance. It can be either websocket-based or
|
||||||
|
@ -128,16 +134,16 @@ func New(base any, v *result.Version) Waiter {
|
||||||
// waiter, polling-based waiter or a stub correspondingly. As the second
|
// waiter, polling-based waiter or a stub correspondingly. As the second
|
||||||
// argument it accepts the RPC node version necessary for awaiting behaviour
|
// argument it accepts the RPC node version necessary for awaiting behaviour
|
||||||
// customisation. As a third argument it accepts the configuration of
|
// customisation. As a third argument it accepts the configuration of
|
||||||
// [PollingBased] [Waiter].
|
// [Waiter].
|
||||||
func NewCustom(base any, v *result.Version, pollConfig PollConfig) Waiter {
|
func NewCustom(base any, v *result.Version, config Config) Waiter {
|
||||||
if eventW, ok := base.(RPCEventBased); ok {
|
if eventW, ok := base.(RPCEventBased); ok {
|
||||||
return &EventBased{
|
return &EventBased{
|
||||||
ws: eventW,
|
ws: eventW,
|
||||||
polling: newCustomPollingBased(eventW, v, pollConfig),
|
polling: newCustomPollingBased(eventW, v, config.PollConfig),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if pollW, ok := base.(RPCPollingBased); ok {
|
if pollW, ok := base.(RPCPollingBased); ok {
|
||||||
return newCustomPollingBased(pollW, v, pollConfig)
|
return newCustomPollingBased(pollW, v, config.PollConfig)
|
||||||
}
|
}
|
||||||
return NewNull()
|
return NewNull()
|
||||||
}
|
}
|
||||||
|
@ -244,15 +250,15 @@ func (w *PollingBased) WaitAny(ctx context.Context, vub uint32, hashes ...util.U
|
||||||
// EventBased contains PollingBased under the hood and falls back to polling when subscription-based
|
// EventBased contains PollingBased under the hood and falls back to polling when subscription-based
|
||||||
// awaiting fails.
|
// awaiting fails.
|
||||||
func NewEventBased(waiter RPCEventBased) (*EventBased, error) {
|
func NewEventBased(waiter RPCEventBased) (*EventBased, error) {
|
||||||
return NewCustomEventBased(waiter, PollConfig{})
|
return NewCustomEventBased(waiter, Config{})
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCustomEventBased creates an instance of Waiter supporting websocket event-based transaction awaiting.
|
// NewCustomEventBased creates an instance of Waiter supporting websocket event-based transaction awaiting.
|
||||||
// EventBased contains PollingBased under the hood and falls back to polling when subscription-based
|
// EventBased contains PollingBased under the hood and falls back to polling when subscription-based
|
||||||
// awaiting fails. PollingBased configuration options may be specified via pollConfig parameter
|
// awaiting fails. Waiter configuration options may be specified via config parameter
|
||||||
// (defaults are used if not specified).
|
// (defaults are used if not specified).
|
||||||
func NewCustomEventBased(waiter RPCEventBased, pollConfig PollConfig) (*EventBased, error) {
|
func NewCustomEventBased(waiter RPCEventBased, config Config) (*EventBased, error) {
|
||||||
polling, err := NewCustomPollingBased(waiter, pollConfig)
|
polling, err := NewCustomPollingBased(waiter, config.PollConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue