-
Notifications
You must be signed in to change notification settings - Fork 5
/
proposal_handler.go
45 lines (37 loc) · 1.13 KB
/
proposal_handler.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
package client
import (
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client"
legacyclient "github.com/cosmos/cosmos-sdk/x/gov/client"
"github.com/atomone-hub/govgen/x/gov/client/rest"
)
// function to create the rest handler
type RESTHandlerFn func(client.Context) rest.ProposalRESTHandler
// function to create the cli handler
type CLIHandlerFn func() *cobra.Command
// The combined type for a proposal handler for both cli and rest
type ProposalHandler struct {
CLIHandler CLIHandlerFn
RESTHandler RESTHandlerFn
}
// NewProposalHandler creates a new ProposalHandler object
func NewProposalHandler(cliHandler CLIHandlerFn, restHandler RESTHandlerFn) ProposalHandler {
return ProposalHandler{
CLIHandler: cliHandler,
RESTHandler: restHandler,
}
}
func WrapPropposalHandler(h legacyclient.ProposalHandler) ProposalHandler {
return ProposalHandler{
CLIHandler: func() *cobra.Command {
return h.CLIHandler()
},
RESTHandler: func(ctx client.Context) rest.ProposalRESTHandler {
handler := h.RESTHandler(ctx)
return rest.ProposalRESTHandler{
SubRoute: handler.SubRoute,
Handler: handler.Handler,
}
},
}
}