/
protocol.go
61 lines (49 loc) · 2.09 KB
/
protocol.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (c) 2019 IoTeX Foundation
// This is an alpha (internal) release and is not suitable for production. This source code is provided 'as is' and no
// warranties are given as to title or non-infringement, merchantability or fitness for purpose and, to the extent
// permitted by law, all liability for your use of the code is disclaimed. This source code is governed by Apache
// License 2.0 that can be found in the LICENSE file.
package protocol
import (
"context"
"github.com/pkg/errors"
"github.com/iotexproject/iotex-core/action"
)
var (
// ErrUnimplemented indicates a method is not implemented yet
ErrUnimplemented = errors.New("method is unimplemented")
)
const (
// SystemNamespace is the namespace to store system information such as candidates/blacklist/unproductiveDelegates
SystemNamespace = "System"
)
// Protocol defines the protocol interfaces atop IoTeX blockchain
type Protocol interface {
ActionValidator
ActionHandler
ReadState(context.Context, StateReader, []byte, ...[]byte) ([]byte, error)
Register(*Registry) error
ForceRegister(*Registry) error
}
// GenesisStateCreator creates some genesis states
type GenesisStateCreator interface {
CreateGenesisStates(context.Context, StateManager) error
}
// PreStatesCreator creates state manager
type PreStatesCreator interface {
CreatePreStates(context.Context, StateManager) error
}
// PostSystemActionsCreator creates a list of system actions to be appended to block actions
type PostSystemActionsCreator interface {
CreatePostSystemActions(context.Context, StateReader) ([]action.Envelope, error)
}
// ActionValidator is the interface of validating an action
type ActionValidator interface {
Validate(context.Context, action.Action) error
}
// ActionHandler is the interface for the action handlers. For each incoming action, the assembled actions will be
// called one by one to process it. ActionHandler implementation is supposed to parse the sub-type of the action to
// decide if it wants to handle this action or not.
type ActionHandler interface {
Handle(context.Context, action.Action, StateManager) (*action.Receipt, error)
}