forked from 0xPolygon/polygon-edge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hook.go
86 lines (63 loc) · 1.94 KB
/
hook.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
package hook
import (
"github.com/Gabulhas/polygon-external-consensus/state"
"github.com/Gabulhas/polygon-external-consensus/types"
)
type ShouldWriteTransactionsFunc func(uint64) bool
type ModifyHeaderFunc func(*types.Header, types.Address) error
type VerifyHeaderFunc func(*types.Header) error
type VerifyBlockFunc func(*types.Block) error
type ProcessHeaderFunc func(*types.Header) error
type PreCommitStateFunc func(*types.Header, *state.Transition) error
type PostInsertBlockFunc func(*types.Block) error
type Hooks struct {
ShouldWriteTransactionFunc ShouldWriteTransactionsFunc
ModifyHeaderFunc ModifyHeaderFunc
VerifyHeaderFunc VerifyHeaderFunc
VerifyBlockFunc VerifyBlockFunc
ProcessHeaderFunc ProcessHeaderFunc
PreCommitStateFunc PreCommitStateFunc
PostInsertBlockFunc PostInsertBlockFunc
}
func (m *Hooks) ShouldWriteTransactions(height uint64) bool {
if m.ShouldWriteTransactionFunc != nil {
return m.ShouldWriteTransactionFunc(height)
}
return true
}
func (m *Hooks) ModifyHeader(header *types.Header, proposer types.Address) error {
if m.ModifyHeaderFunc != nil {
return m.ModifyHeaderFunc(header, proposer)
}
return nil
}
func (m *Hooks) VerifyHeader(header *types.Header) error {
if m.VerifyHeaderFunc != nil {
return m.VerifyHeaderFunc(header)
}
return nil
}
func (m *Hooks) VerifyBlock(block *types.Block) error {
if m.VerifyBlockFunc != nil {
return m.VerifyBlockFunc(block)
}
return nil
}
func (m *Hooks) ProcessHeader(header *types.Header) error {
if m.ProcessHeaderFunc != nil {
return m.ProcessHeaderFunc(header)
}
return nil
}
func (m *Hooks) PreCommitState(header *types.Header, txn *state.Transition) error {
if m.PreCommitStateFunc != nil {
return m.PreCommitStateFunc(header, txn)
}
return nil
}
func (m *Hooks) PostInsertBlock(block *types.Block) error {
if m.PostInsertBlockFunc != nil {
return m.PostInsertBlockFunc(block)
}
return nil
}