/
module.go
99 lines (84 loc) · 3.97 KB
/
module.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
87
88
89
90
91
92
93
94
95
96
97
98
99
package modules
import (
"encoding/json"
"strings"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/go-co-op/gocron"
tmctypes "github.com/tendermint/tendermint/rpc/core/types"
tmtypes "github.com/tendermint/tendermint/types"
"github.com/forbole/juno/v2/types"
)
// Module represents a generic module without any particular handling of data
type Module interface {
// Name returns the module name
Name() string
}
// Modules represents a slice of Module objects
type Modules []Module
// FindByName returns the module having the given name inside the m slice.
// If no modules are found, returns nil and false.
func (m Modules) FindByName(name string) (module Module, found bool) {
for _, m := range m {
if strings.EqualFold(m.Name(), name) {
return m, true
}
}
return nil, false
}
// --------------------------------------------------------------------------------------------------------------------
type AdditionalOperationsModule interface {
// RunAdditionalOperations runs all the additional operations required by the module.
// This is the perfect place where to initialize all the operations that subscribe to websockets or other
// external sources.
// NOTE. This method will only be run ONCE before starting the parsing of the blocks.
RunAdditionalOperations() error
}
type AsyncOperationsModule interface {
// RunAsyncOperations runs all the async operations associated with a module.
// This method will be run on a separate goroutine, that will stop only when the user stops the entire process.
// For this reason, this method cannot return an error, and all raised errors should be signaled by panicking.
RunAsyncOperations()
}
type PeriodicOperationsModule interface {
// RegisterPeriodicOperations allows to register all the operations that will be run on a periodic basis.
// The given scheduler can be used to define the periodicity of each task.
// NOTE. This method will only be run ONCE during the module initialization.
RegisterPeriodicOperations(scheduler *gocron.Scheduler) error
}
type FastSyncModule interface {
// DownloadState allows to download the module state at the given height.
// This will be called only when the fast sync is used, and only once for the initial height.
// It should query the gRPC and get all the possible data.
// NOTE. If an error is returned, following modules will still be called.
DownloadState(height int64) error
}
type GenesisModule interface {
// HandleGenesis allows to handle the genesis state.
// For convenience of use, the already-unmarshalled AppState is provided along with the full GenesisDoc.
// NOTE. The returned error will be logged using the GenesisError method. All other modules' handlers
// will still be called.
HandleGenesis(doc *tmtypes.GenesisDoc, appState map[string]json.RawMessage) error
}
type BlockModule interface {
// HandleBlock allows to handle a single block.
// For convenience of use, all the transactions present inside the given block will be passed as well.
// For each transaction present inside the block, HandleTx will be called as well.
// NOTE. The returned error will be logged using the BlockError method. All other modules' handlers
// will still be called.
HandleBlock(block *tmctypes.ResultBlock, results *tmctypes.ResultBlockResults, txs []*types.Tx, vals *tmctypes.ResultValidators) error
}
type TransactionModule interface {
// HandleTx handles a single transaction.
// For each message present inside the transaction, HandleMsg will be called as well.
// NOTE. The returned error will be logged using the TxError method. All other modules' handlers
// will still be called.
HandleTx(tx *types.Tx) error
}
type MessageModule interface {
// HandleMsg handles a single message.
// For convenience of usa, the index of the message inside the transaction and the transaction itself
// are passed as well.
// NOTE. The returned error will be logged using the MsgError method. All other modules' handlers
// will still be called.
HandleMsg(index int, msg sdk.Msg, tx *types.Tx) error
}