-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#13 Added cli and REST query support, cancel upgrade proposal to cons…
…ortium module
- Loading branch information
Showing
10 changed files
with
131 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
package consortium | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
) | ||
|
||
// RegisterCodec registers concrete types on the Amino codec | ||
func RegisterCodec(cdc *codec.Codec) { | ||
cdc.RegisterConcrete(ActionScheduleUpgrade{}, "consortium/ActionScheduleUpgrade", nil) | ||
cdc.RegisterConcrete(ActionCancelUpgrade{}, "consortium/ActionCancelUpgrade", nil) | ||
cdc.RegisterConcrete(ActionChangeValidatorSet{}, "consortium/ActionChangeValidatorSet", nil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
"github.com/cosmos/cosmos-sdk/client/context" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
"github.com/regen-network/regen-ledger/x/upgrade" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func GetQueryCmd(cmdName string, storeName string, cdc *codec.Codec) *cobra.Command { | ||
return &cobra.Command{ | ||
Use: cmdName, | ||
Short: "get upgrade plan (if one exists)", | ||
Args: cobra.ExactArgs(0), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
cliCtx := context.NewCLIContext().WithCodec(cdc) | ||
|
||
res, err := cliCtx.QueryStore([]byte(upgrade.PlanKey), storeName) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if len(res) == 0 { | ||
return fmt.Errorf("no upgrade scheduled") | ||
} | ||
|
||
var plan upgrade.Plan | ||
err = cdc.UnmarshalBinaryBare(res, &plan) | ||
if err != nil { | ||
return err | ||
} | ||
return cliCtx.PrintOutput(plan) | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package rest | ||
|
||
import ( | ||
"fmt" | ||
"github.com/cosmos/cosmos-sdk/client/context" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
"github.com/cosmos/cosmos-sdk/types/rest" | ||
"github.com/gorilla/mux" | ||
"github.com/regen-network/regen-ledger/x/upgrade" | ||
"net/http" | ||
) | ||
|
||
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec, routeName string, storeName string) { | ||
r.HandleFunc(fmt.Sprintf("/%s", routeName), getUpgradePlanHandler(cdc, cliCtx, storeName)).Methods("GET") | ||
} | ||
|
||
func getUpgradePlanHandler(cdc *codec.Codec, cliCtx context.CLIContext, storeName string) func(http.ResponseWriter, *http.Request) { | ||
return func(w http.ResponseWriter, request *http.Request) { | ||
res, err := cliCtx.QueryStore([]byte(upgrade.PlanKey), storeName) | ||
if err != nil { | ||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) | ||
return | ||
} | ||
|
||
if len(res) == 0 { | ||
http.NotFound(w, request) | ||
return | ||
} | ||
|
||
var plan upgrade.Plan | ||
err = cdc.UnmarshalBinaryBare(res, &plan) | ||
if err != nil { | ||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) | ||
return | ||
} | ||
|
||
rest.PostProcessResponse(w, cdc, plan, cliCtx.Indent) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package upgrade | ||
|
||
/* | ||
Package upgrade | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters