2020-10-12 10:17:40 +00:00
|
|
|
package alphabet
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
|
2020-10-12 10:17:40 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
2021-05-31 11:50:11 +00:00
|
|
|
nmWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap/wrapper"
|
2020-10-12 10:17:40 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
|
|
|
"github.com/panjf2000/ants/v2"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
// Indexer is a callback interface for inner ring global state.
|
|
|
|
Indexer interface {
|
2021-03-23 15:20:44 +00:00
|
|
|
AlphabetIndex() int
|
2020-10-12 10:17:40 +00:00
|
|
|
}
|
|
|
|
|
2021-02-21 06:53:18 +00:00
|
|
|
// Contracts is an interface of the storage
|
|
|
|
// of the alphabet contract addresses.
|
|
|
|
Contracts interface {
|
2021-06-23 13:29:46 +00:00
|
|
|
// GetByIndex must return address of the
|
2021-02-21 06:53:18 +00:00
|
|
|
// alphabet contract by index of the glagolitic
|
|
|
|
// letter (e.g 0 for Az, 40 for Izhitsa).
|
|
|
|
//
|
|
|
|
// Must return false if index does not
|
|
|
|
// match to any alphabet contract.
|
|
|
|
GetByIndex(int) (util.Uint160, bool)
|
|
|
|
}
|
|
|
|
|
2020-10-12 10:17:40 +00:00
|
|
|
// Processor of events produced for alphabet contracts in sidechain.
|
|
|
|
Processor struct {
|
|
|
|
log *zap.Logger
|
|
|
|
pool *ants.Pool
|
2021-02-21 06:53:18 +00:00
|
|
|
alphabetContracts Contracts
|
2021-05-31 11:50:11 +00:00
|
|
|
netmapClient *nmWrapper.Wrapper
|
2020-10-12 10:17:40 +00:00
|
|
|
morphClient *client.Client
|
|
|
|
irList Indexer
|
2020-11-03 08:03:15 +00:00
|
|
|
storageEmission uint64
|
2020-10-12 10:17:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Params of the processor constructor.
|
|
|
|
Params struct {
|
|
|
|
Log *zap.Logger
|
|
|
|
PoolSize int
|
2021-02-21 06:53:18 +00:00
|
|
|
AlphabetContracts Contracts
|
2021-05-31 11:50:11 +00:00
|
|
|
NetmapClient *nmWrapper.Wrapper
|
2020-10-12 10:17:40 +00:00
|
|
|
MorphClient *client.Client
|
|
|
|
IRList Indexer
|
2020-11-03 08:03:15 +00:00
|
|
|
StorageEmission uint64
|
2020-10-12 10:17:40 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
// New creates neofs mainnet contract processor instance.
|
|
|
|
func New(p *Params) (*Processor, error) {
|
|
|
|
switch {
|
|
|
|
case p.Log == nil:
|
|
|
|
return nil, errors.New("ir/alphabet: logger is not set")
|
|
|
|
case p.MorphClient == nil:
|
|
|
|
return nil, errors.New("ir/alphabet: neo:morph client is not set")
|
|
|
|
case p.IRList == nil:
|
|
|
|
return nil, errors.New("ir/alphabet: global state is not set")
|
|
|
|
}
|
|
|
|
|
|
|
|
p.Log.Debug("alphabet worker pool", zap.Int("size", p.PoolSize))
|
|
|
|
|
|
|
|
pool, err := ants.NewPool(p.PoolSize, ants.WithNonblocking(true))
|
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("ir/neofs: can't create worker pool: %w", err)
|
2020-10-12 10:17:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &Processor{
|
|
|
|
log: p.Log,
|
|
|
|
pool: pool,
|
|
|
|
alphabetContracts: p.AlphabetContracts,
|
2021-05-31 11:50:11 +00:00
|
|
|
netmapClient: p.NetmapClient,
|
2020-10-12 10:17:40 +00:00
|
|
|
morphClient: p.MorphClient,
|
|
|
|
irList: p.IRList,
|
2020-11-03 08:03:15 +00:00
|
|
|
storageEmission: p.StorageEmission,
|
2020-10-12 10:17:40 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-08-12 15:24:17 +00:00
|
|
|
// ListenerNotificationParsers for the 'event.Listener' event producer.
|
2021-09-08 08:28:41 +00:00
|
|
|
func (ap *Processor) ListenerNotificationParsers() []event.NotificationParserInfo {
|
2020-10-12 10:17:40 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-08-12 15:24:17 +00:00
|
|
|
// ListenerNotificationHandlers for the 'event.Listener' event producer.
|
2021-09-08 08:28:41 +00:00
|
|
|
func (ap *Processor) ListenerNotificationHandlers() []event.NotificationHandlerInfo {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListenerNotaryParsers for the 'event.Listener' event producer.
|
|
|
|
func (ap *Processor) ListenerNotaryParsers() []event.NotaryParserInfo {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListenerNotaryHandlers for the 'event.Listener' event producer.
|
|
|
|
func (ap *Processor) ListenerNotaryHandlers() []event.NotaryHandlerInfo {
|
2020-10-12 10:17:40 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// TimersHandlers for the 'Timers' event producer.
|
2021-09-08 08:28:41 +00:00
|
|
|
func (ap *Processor) TimersHandlers() []event.NotificationHandlerInfo {
|
2021-01-22 15:49:52 +00:00
|
|
|
return nil
|
2020-10-12 10:17:40 +00:00
|
|
|
}
|