-
Notifications
You must be signed in to change notification settings - Fork 319
/
protocol.go
86 lines (69 loc) · 2.67 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// 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/probationList/unproductiveDelegates
SystemNamespace = "System"
)
// Protocol defines the protocol interfaces atop IoTeX blockchain
type Protocol interface {
ActionHandler
ReadState(context.Context, StateReader, []byte, ...[]byte) ([]byte, uint64, error)
Register(*Registry) error
ForceRegister(*Registry) error
Name() string
}
// Starter starts the protocol
type Starter interface {
Start(context.Context, StateReader) (interface{}, error)
}
// GenesisStateCreator creates some genesis states
type GenesisStateCreator interface {
CreateGenesisStates(context.Context, StateManager) error
}
// PreStatesCreator creates preliminary states for state manager
type PreStatesCreator interface {
CreatePreStates(context.Context, StateManager) error
}
// Committer performs commit action of the protocol
type Committer interface {
Commit(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, StateReader) 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)
}
// View stores the view for all protocols
type View map[string]interface{}
func (view View) Read(name string) (interface{}, error) {
if v, hit := view[name]; hit {
return v, nil
}
return nil, ErrNoName
}
func (view View) Write(name string, v interface{}) error {
view[name] = v
return nil
}