forked from TrueCloudLab/frostfs-node
Evgenii Stratonikov
d0ce835fbf
They are decoupled, but it is an error to have a handler without a corresponding parser. Register them together on the code level and get rid of unreachable code. Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
55 lines
1.3 KiB
Go
55 lines
1.3 KiB
Go
package event
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
|
"github.com/nspcc-dev/neo-go/pkg/network/payload"
|
|
)
|
|
|
|
// NotificationParser is a function that constructs Event
|
|
// from the StackItem list.
|
|
type NotificationParser func(*state.ContainedNotificationEvent) (Event, error)
|
|
|
|
// NotaryPreparator constructs NotaryEvent
|
|
// from the NotaryRequest event.
|
|
type NotaryPreparator interface {
|
|
Prepare(*payload.P2PNotaryRequest) (NotaryEvent, error)
|
|
}
|
|
|
|
// NotaryParser is a function that constructs Event
|
|
// from the NotaryEvent event.
|
|
type NotaryParser func(NotaryEvent) (Event, error)
|
|
|
|
// NotaryParserInfo is a structure that groups
|
|
// the parameters of particular notary request
|
|
// event parser.
|
|
type NotaryParserInfo struct {
|
|
notaryRequestTypes
|
|
|
|
p NotaryParser
|
|
}
|
|
|
|
func (n *NotaryParserInfo) parser() NotaryParser {
|
|
return n.p
|
|
}
|
|
|
|
func (n *NotaryParserInfo) SetParser(p NotaryParser) {
|
|
n.p = p
|
|
}
|
|
|
|
type wrongPrmNumber struct {
|
|
exp, act int
|
|
}
|
|
|
|
// WrongNumberOfParameters returns an error about wrong number of smart contract parameters.
|
|
func WrongNumberOfParameters(exp, act int) error {
|
|
return &wrongPrmNumber{
|
|
exp: exp,
|
|
act: act,
|
|
}
|
|
}
|
|
|
|
func (s wrongPrmNumber) Error() string {
|
|
return fmt.Errorf("wrong parameter count: expected %d, has %d", s.exp, s.act).Error()
|
|
}
|