rpcclient: integrate customizable Waiter with Actor

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
This commit is contained in:
Anna Shaleva 2024-08-14 10:54:11 +03:00
parent afbb51e78c
commit 92c6361be8
2 changed files with 19 additions and 2 deletions

View file

@ -106,6 +106,10 @@ type Options struct {
// before it's signed (other methods that perform test invocations
// use CheckerModifier). MakeUnsigned* methods do not run it.
Modifier TransactionModifier
// waiter.PollConfig is used by [waiter.Waiter] constructor to customize
// [waiter.PollingBased] behaviour. This option may be kept empty for default
// polling behaviour.
waiter.PollConfig
}
// New creates an Actor instance using the specified RPC interface and the set of
@ -183,6 +187,7 @@ func NewTuned(ra RPCActor, signers []SignerAccount, opts Options) (*Actor, error
if opts.Modifier != nil {
a.opts.Modifier = opts.Modifier
}
a.Waiter = waiter.NewCustom(ra, a.version, opts.PollConfig)
return a, err
}

View file

@ -118,14 +118,26 @@ func errIsAlreadyExists(err error) bool {
// or not an implementation of these two interfaces. It returns websocket-based
// waiter, polling-based waiter or a stub correspondingly.
func New(base any, v *result.Version) Waiter {
return NewCustom(base, v, PollConfig{})
}
// NewCustom creates Waiter instance. It can be either websocket-based or
// polling-base, otherwise Waiter stub is returned. As a first argument
// it accepts RPCEventBased implementation, RPCPollingBased implementation
// or not an implementation of these two interfaces. It returns websocket-based
// waiter, polling-based waiter or a stub correspondingly. As the second
// argument it accepts the RPC node version necessary for awaiting behaviour
// customisation. As a third argument it accepts the configuration of
// [PollingBased] [Waiter].
func NewCustom(base any, v *result.Version, pollConfig PollConfig) Waiter {
if eventW, ok := base.(RPCEventBased); ok {
return &EventBased{
ws: eventW,
polling: newCustomPollingBased(eventW, v, PollConfig{}),
polling: newCustomPollingBased(eventW, v, pollConfig),
}
}
if pollW, ok := base.(RPCPollingBased); ok {
return newCustomPollingBased(pollW, v, PollConfig{})
return newCustomPollingBased(pollW, v, pollConfig)
}
return NewNull()
}