-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
88 lines (76 loc) · 3 KB
/
main.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
package main
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/desmos-labs/desmos/v6/app"
"github.com/go-co-op/gocron"
"google.golang.org/grpc"
"github.com/desmos-labs/caerus/branch"
client "github.com/desmos-labs/caerus/chain"
"github.com/desmos-labs/caerus/database"
notificationsclient "github.com/desmos-labs/caerus/notifications"
"github.com/desmos-labs/caerus/routes/applications"
"github.com/desmos-labs/caerus/routes/files"
"github.com/desmos-labs/caerus/routes/grants"
"github.com/desmos-labs/caerus/routes/links"
"github.com/desmos-labs/caerus/routes/notifications"
"github.com/desmos-labs/caerus/routes/users"
"github.com/desmos-labs/caerus/runner"
"github.com/desmos-labs/caerus/scheduler"
"github.com/desmos-labs/caerus/scheduler/operations"
)
func main() {
// Setup Cosmos-related stuff
app.SetupConfig(sdk.GetConfig())
encodingCfg := app.MakeEncodingConfig()
txConfig, cdc, amino := encodingCfg.TxConfig, encodingCfg.Codec, encodingCfg.Amino
// Build the database
db, err := database.NewDatabaseFromEnvVariables(cdc)
if err != nil {
panic(err)
}
// Build the client
chainClient, err := client.NewClientFromEnvVariables(txConfig, cdc)
if err != nil {
panic(err)
}
// Build the various clients
firebaseClient, err := notificationsclient.NewClientFromEnvVariables(db)
if err != nil {
panic(err)
}
branchClient, err := branch.NewClientFromEnvVariables()
if err != nil {
panic(err)
}
// Build a scheduler - This will be started by the server runner instance
cronScheduler := scheduler.New(scheduler.Context{
ChainClient: chainClient,
FirebaseClient: firebaseClient,
Database: db,
})
// Register the scheduler operations
cronScheduler.SetOperationsRegistrar(func(context scheduler.Context, scheduler *gocron.Scheduler) {
operations.RegisterGrantsOperations(context, scheduler)
})
// Build the runner
serverRunner := runner.New(runner.Context{
Codec: cdc,
Amino: amino,
ChainClient: chainClient,
NotificationsClient: firebaseClient,
BranchClient: branchClient,
Scheduler: cronScheduler,
Database: db,
})
// Register the default routes
serverRunner.SetServiceRegistrar(func(context runner.Context, server *grpc.Server) {
applications.RegisterApplicationServiceServer(server, applications.NewServerFromEnvVariables(context.Database))
files.RegisterFilesServiceServer(server, files.NewServerFromEnvVariables())
grants.RegisterGrantsServiceServer(server, grants.NewServerFromEnvVariables(context.ChainClient, context.Codec, context.Database))
notifications.RegisterNotificationsServiceServer(server, notifications.NewServerFromEnvVariables(context.NotificationsClient, context.Database))
users.RegisterUsersServiceServer(server, users.NewServerFromEnvVariables(context.Codec, context.Amino, context.Database))
links.RegisterLinksServiceServer(server, links.NewServerFromEnvVariables(context.BranchClient, context.Database))
})
// Run the server instance
serverRunner.Run()
}