-
Notifications
You must be signed in to change notification settings - Fork 231
/
module.go
69 lines (58 loc) · 2.05 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
package bank
import (
"encoding/json"
"github.com/forbole/bdjuno/database"
junomessages "github.com/desmos-labs/juno/modules/messages"
"github.com/cosmos/cosmos-sdk/simapp/params"
sdk "github.com/cosmos/cosmos-sdk/types"
authttypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/desmos-labs/juno/modules"
"github.com/desmos-labs/juno/types"
tmctypes "github.com/tendermint/tendermint/rpc/core/types"
tmtypes "github.com/tendermint/tendermint/types"
)
var (
_ modules.Module = &Module{}
_ modules.GenesisModule = &Module{}
_ modules.BlockModule = &Module{}
_ modules.MessageModule = &Module{}
)
// Module represents the x/bank module
type Module struct {
messageParser junomessages.MessageAddressesParser
encodingConfig *params.EncodingConfig
authClient authttypes.QueryClient
bankClient banktypes.QueryClient
db *database.Db
}
// NewModule returns a new Module instance
func NewModule(
messageParser junomessages.MessageAddressesParser,
authClient authttypes.QueryClient, bankClient banktypes.QueryClient,
encodingConfig *params.EncodingConfig, db *database.Db,
) *Module {
return &Module{
messageParser: messageParser,
encodingConfig: encodingConfig,
authClient: authClient,
bankClient: bankClient,
db: db,
}
}
// Name implements modules.Module
func (m *Module) Name() string {
return "bank"
}
// HandleGenesis implements modules.GenesisModule
func (m *Module) HandleGenesis(doc *tmtypes.GenesisDoc, appState map[string]json.RawMessage) error {
return HandleGenesis(doc, appState, m.encodingConfig.Marshaler, m.db)
}
// HandleBlock implements modules.BlockModule
func (m *Module) HandleBlock(block *tmctypes.ResultBlock, _ []*types.Tx, _ *tmctypes.ResultValidators) error {
return HandleBlock(block, m.bankClient, m.db)
}
// HandleMsg implements modules.MessageModule
func (m *Module) HandleMsg(_ int, msg sdk.Msg, tx *types.Tx) error {
return HandleMsg(tx, msg, m.messageParser, m.bankClient, m.encodingConfig.Marshaler, m.db)
}