many renames / golint compliance

This commit is contained in:
rigelrozanski
2018-04-19 00:49:24 -04:00
parent 1f9184a24b
commit d28efaac27
92 changed files with 792 additions and 943 deletions
+8 -1
View File
@@ -126,7 +126,14 @@ func (ctx CoreContext) SignAndBuild(name, passphrase string, msg sdk.Msg, cdc *w
}
// sign and build the transaction from the msg
func (ctx CoreContext) SignBuildBroadcast(name string, msg sdk.Msg, cdc *wire.Codec) (*ctypes.ResultBroadcastTxCommit, error) {
func (ctx CoreContext) EnsureSignBuildBroadcast(name string, msg sdk.Msg, cdc *wire.Codec) (res *ctypes.ResultBroadcastTxCommit, err error) {
// default to next sequence number if none provided
ctx, err = EnsureSequence(ctx)
if err != nil {
return nil, err
}
passphrase, err := ctx.GetPassphraseFromStdin(name)
if err != nil {
return nil, err
+4
View File
@@ -135,14 +135,17 @@ func printCreate(info keys.Info, seed string) {
}
}
/////////////////////////////
// REST
// new key request REST body
type NewKeyBody struct {
Name string `json:"name"`
Password string `json:"password"`
Seed string `json:"seed"`
}
// add new key REST handler
func AddNewKeyRequestHandler(w http.ResponseWriter, r *http.Request) {
var kb keys.Keybase
var m NewKeyBody
@@ -208,6 +211,7 @@ func getSeed(algo keys.CryptoAlgo) string {
return seed
}
// Seed REST request handler
func SeedRequestHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
algoType := vars["type"]
+3
View File
@@ -48,12 +48,15 @@ func runDeleteCmd(cmd *cobra.Command, args []string) error {
return nil
}
////////////////////////
// REST
// delete key request REST body
type DeleteKeyBody struct {
Password string `json:"password"`
}
// delete key REST handler
func DeleteKeyRequestHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
name := vars["name"]
+3 -1
View File
@@ -31,8 +31,10 @@ func runListCmd(cmd *cobra.Command, args []string) error {
return err
}
//REST
/////////////////////////
// REST
// query key list REST handler
func QueryKeysRequestHandler(w http.ResponseWriter, r *http.Request) {
kb, err := GetKeyBase()
if err != nil {
+1
View File
@@ -29,6 +29,7 @@ func Commands() *cobra.Command {
return cmd
}
// resgister REST routes
func RegisterRoutes(r *mux.Router) {
r.HandleFunc("/keys", QueryKeysRequestHandler).Methods("GET")
r.HandleFunc("/keys", AddNewKeyRequestHandler).Methods("POST")
+2
View File
@@ -42,8 +42,10 @@ func runShowCmd(cmd *cobra.Command, args []string) error {
return err
}
///////////////////////////
// REST
// get key REST handler
func GetKeyRequestHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
name := vars["name"]
+3
View File
@@ -53,13 +53,16 @@ func runUpdateCmd(cmd *cobra.Command, args []string) error {
return nil
}
///////////////////////
// REST
// update key request REST body
type UpdateKeyBody struct {
NewPassword string `json:"new_password"`
OldPassword string `json:"old_password"`
}
// update key REST handler
func UpdateKeyRequestHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
name := vars["name"]
+1 -1
View File
@@ -66,7 +66,7 @@ func startRESTServerFn(cdc *wire.Codec) func(cmd *cobra.Command, args []string)
func createHandler(cdc *wire.Codec) http.Handler {
r := mux.NewRouter()
r.HandleFunc("/version", version.VersionRequestHandler).Methods("GET")
r.HandleFunc("/version", version.RequestHandler).Methods("GET")
kb, err := keys.GetKeyBase() //XXX
if err != nil {
+3
View File
@@ -55,6 +55,7 @@ func getBlock(height *int64) ([]byte, error) {
return output, nil
}
// get the current blockchain height
func GetChainHeight() (int64, error) {
node, err := context.NewCoreContextFromViper().GetNode()
if err != nil {
@@ -94,6 +95,7 @@ func printBlock(cmd *cobra.Command, args []string) error {
// REST
// REST handler to get a block
func BlockRequestHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
height, err := strconv.ParseInt(vars["height"], 10, 64)
@@ -117,6 +119,7 @@ func BlockRequestHandler(w http.ResponseWriter, r *http.Request) {
w.Write(output)
}
// REST handler to get the latest block
func LatestBlockRequestHandler(w http.ResponseWriter, r *http.Request) {
height, err := GetChainHeight()
if err != nil {
+3 -2
View File
@@ -44,11 +44,12 @@ func initClientCommand() *cobra.Command {
return cmd
}
// Register REST endpoints
func RegisterRoutes(r *mux.Router) {
r.HandleFunc("/node_info", NodeInfoRequestHandler).Methods("GET")
r.HandleFunc("/syncing", NodeSyncingRequestHandler).Methods("GET")
r.HandleFunc("/blocks/latest", LatestBlockRequestHandler).Methods("GET")
r.HandleFunc("/blocks/{height}", BlockRequestHandler).Methods("GET")
r.HandleFunc("/validatorsets/latest", LatestValidatorsetRequestHandler).Methods("GET")
r.HandleFunc("/validatorsets/{height}", ValidatorsetRequestHandler).Methods("GET")
r.HandleFunc("/validatorsets/latest", LatestValidatorSetRequestHandler).Methods("GET")
r.HandleFunc("/validatorsets/{height}", ValidatorSetRequestHandler).Methods("GET")
}
+2
View File
@@ -51,6 +51,7 @@ func printNodeStatus(cmd *cobra.Command, args []string) error {
// REST
// REST handler for node info
func NodeInfoRequestHandler(w http.ResponseWriter, r *http.Request) {
status, err := getNodeStatus()
if err != nil {
@@ -69,6 +70,7 @@ func NodeInfoRequestHandler(w http.ResponseWriter, r *http.Request) {
w.Write(output)
}
// REST handler for node syncing
func NodeSyncingRequestHandler(w http.ResponseWriter, r *http.Request) {
status, err := getNodeStatus()
if err != nil {
+10 -6
View File
@@ -12,6 +12,8 @@ import (
"github.com/cosmos/cosmos-sdk/client/context"
)
// TODO these next two functions feel kinda hacky based on their placement
func validatorCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "validatorset <height>",
@@ -24,7 +26,7 @@ func validatorCommand() *cobra.Command {
return cmd
}
func GetValidators(height *int64) ([]byte, error) {
func getValidators(height *int64) ([]byte, error) {
// get the node
node, err := context.NewCoreContextFromViper().GetNode()
if err != nil {
@@ -59,7 +61,7 @@ func printValidators(cmd *cobra.Command, args []string) error {
}
}
output, err := GetValidators(height)
output, err := getValidators(height)
if err != nil {
return err
}
@@ -70,7 +72,8 @@ func printValidators(cmd *cobra.Command, args []string) error {
// REST
func ValidatorsetRequestHandler(w http.ResponseWriter, r *http.Request) {
// Validator Set at a height REST handler
func ValidatorSetRequestHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
height, err := strconv.ParseInt(vars["height"], 10, 64)
if err != nil {
@@ -84,7 +87,7 @@ func ValidatorsetRequestHandler(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("ERROR: Requested block height is bigger then the chain length."))
return
}
output, err := GetValidators(&height)
output, err := getValidators(&height)
if err != nil {
w.WriteHeader(500)
w.Write([]byte(err.Error()))
@@ -93,14 +96,15 @@ func ValidatorsetRequestHandler(w http.ResponseWriter, r *http.Request) {
w.Write(output)
}
func LatestValidatorsetRequestHandler(w http.ResponseWriter, r *http.Request) {
// Latest Validator Set REST handler
func LatestValidatorSetRequestHandler(w http.ResponseWriter, r *http.Request) {
height, err := GetChainHeight()
if err != nil {
w.WriteHeader(500)
w.Write([]byte(err.Error()))
return
}
output, err := GetValidators(&height)
output, err := getValidators(&height)
if err != nil {
w.WriteHeader(500)
w.Write([]byte(err.Error()))
+2
View File
@@ -7,10 +7,12 @@ import (
"github.com/cosmos/cosmos-sdk/client/context"
)
// Tx Broadcast Body
type BroadcastTxBody struct {
TxBytes string `json="tx"`
}
// BroadcastTx REST Handler
func BroadcastTxRequestHandler(w http.ResponseWriter, r *http.Request) {
var m BroadcastTxBody
+24 -27
View File
@@ -21,19 +21,37 @@ import (
)
// Get the default command for a tx query
func QueryTxCmd(cmdr commander) *cobra.Command {
func QueryTxCmd(cdc *wire.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "tx [hash]",
Short: "Matches this txhash over all committed blocks",
RunE: cmdr.queryAndPrintTx,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 || len(args[0]) == 0 {
return errors.New("You must provide a tx hash")
}
// find the key to look up the account
hashHexStr := args[0]
trustNode := viper.GetBool(client.FlagTrustNode)
output, err := queryTx(cdc, hashHexStr, trustNode)
if err != nil {
return err
}
fmt.Println(string(output))
return nil
},
}
cmd.Flags().StringP(client.FlagNode, "n", "tcp://localhost:46657", "Node to connect to")
// TODO: change this to false when we can
cmd.Flags().Bool(client.FlagTrustNode, true, "Don't verify proofs for responses")
return cmd
}
func (c commander) queryTx(hashHexStr string, trustNode bool) ([]byte, error) {
func queryTx(cdc *wire.Codec, hashHexStr string, trustNode bool) ([]byte, error) {
hash, err := hex.DecodeString(hashHexStr)
if err != nil {
return nil, err
@@ -49,7 +67,7 @@ func (c commander) queryTx(hashHexStr string, trustNode bool) ([]byte, error) {
if err != nil {
return nil, err
}
info, err := formatTxResult(c.cdc, res)
info, err := formatTxResult(cdc, res)
if err != nil {
return nil, err
}
@@ -88,31 +106,10 @@ func parseTx(cdc *wire.Codec, txBytes []byte) (sdk.Tx, error) {
return tx, nil
}
// CMD
// command to query for a transaction
func (c commander) queryAndPrintTx(cmd *cobra.Command, args []string) error {
if len(args) != 1 || len(args[0]) == 0 {
return errors.New("You must provide a tx hash")
}
// find the key to look up the account
hashHexStr := args[0]
trustNode := viper.GetBool(client.FlagTrustNode)
output, err := c.queryTx(hashHexStr, trustNode)
if err != nil {
return err
}
fmt.Println(string(output))
return nil
}
// REST
// transaction query REST handler
func QueryTxRequestHandler(cdc *wire.Codec) func(http.ResponseWriter, *http.Request) {
c := commander{cdc}
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
hashHexStr := vars["hash"]
@@ -122,7 +119,7 @@ func QueryTxRequestHandler(cdc *wire.Codec) func(http.ResponseWriter, *http.Requ
trustNode = true
}
output, err := c.queryTx(hashHexStr, trustNode)
output, err := queryTx(cdc, hashHexStr, trustNode)
if err != nil {
w.WriteHeader(500)
w.Write([]byte(err.Error()))
+4 -9
View File
@@ -7,23 +7,18 @@ import (
"github.com/cosmos/cosmos-sdk/wire"
)
// type used to pass around the provided cdc
type commander struct {
cdc *wire.Codec
}
// AddCommands adds a number of tx-query related subcommands
func AddCommands(cmd *cobra.Command, cdc *wire.Codec) {
cmdr := commander{cdc}
cmd.AddCommand(
SearchTxCmd(cmdr),
QueryTxCmd(cmdr),
SearchTxCmd(cdc),
QueryTxCmd(cdc),
)
}
// register REST routes
func RegisterRoutes(r *mux.Router, cdc *wire.Codec) {
// r.HandleFunc("/txs", SearchTxRequestHandler(cdc)).Methods("GET")
r.HandleFunc("/txs/{hash}", QueryTxRequestHandler(cdc)).Methods("GET")
// r.HandleFunc("/txs", SearchTxRequestHandler(cdc)).Methods("GET")
// r.HandleFunc("/txs/sign", SignTxRequstHandler).Methods("POST")
// r.HandleFunc("/txs/broadcast", BroadcastTxRequestHandler).Methods("POST")
}
+19 -21
View File
@@ -22,13 +22,24 @@ const (
)
// default client command to search through tagged transactions
func SearchTxCmd(cmdr commander) *cobra.Command {
func SearchTxCmd(cdc *wire.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "txs",
Short: "Search for all transactions that match the given tags",
RunE: cmdr.searchAndPrintTx,
RunE: func(cmd *cobra.Command, args []string) error {
tags := viper.GetStringSlice(flagTags)
output, err := searchTx(cdc, tags)
if err != nil {
return err
}
fmt.Println(string(output))
return nil
},
}
cmd.Flags().StringP(client.FlagNode, "n", "tcp://localhost:46657", "Node to connect to")
// TODO: change this to false once proofs built in
cmd.Flags().Bool(client.FlagTrustNode, true, "Don't verify proofs for responses")
cmd.Flags().StringSlice(flagTags, nil, "Tags that must match (may provide multiple)")
@@ -36,7 +47,7 @@ func SearchTxCmd(cmdr commander) *cobra.Command {
return cmd
}
func (c commander) searchTx(tags []string) ([]byte, error) {
func searchTx(cdc *wire.Codec, tags []string) ([]byte, error) {
if len(tags) == 0 {
return nil, errors.New("Must declare at least one tag to search")
}
@@ -55,12 +66,12 @@ func (c commander) searchTx(tags []string) ([]byte, error) {
return nil, err
}
info, err := formatTxResults(c.cdc, res)
info, err := formatTxResults(cdc, res)
if err != nil {
return nil, err
}
output, err := c.cdc.MarshalJSON(info)
output, err := cdc.MarshalJSON(info)
if err != nil {
return nil, err
}
@@ -79,24 +90,11 @@ func formatTxResults(cdc *wire.Codec, res []*ctypes.ResultTx) ([]txInfo, error)
return out, nil
}
// CMD
func (c commander) searchAndPrintTx(cmd *cobra.Command, args []string) error {
tags := viper.GetStringSlice(flagTags)
output, err := c.searchTx(tags)
if err != nil {
return err
}
fmt.Println(string(output))
return nil
}
/////////////////////////////////////////
// REST
// Search Tx REST Handler
func SearchTxRequestHandler(cdc *wire.Codec) func(http.ResponseWriter, *http.Request) {
c := commander{cdc}
return func(w http.ResponseWriter, r *http.Request) {
tag := r.FormValue("tag")
if tag == "" {
@@ -106,7 +104,7 @@ func SearchTxRequestHandler(cdc *wire.Codec) func(http.ResponseWriter, *http.Req
}
tags := []string{tag}
output, err := c.searchTx(tags)
output, err := searchTx(cdc, tags)
if err != nil {
w.WriteHeader(500)
w.Write([]byte(err.Error()))
+3
View File
@@ -8,12 +8,15 @@ import (
keys "github.com/tendermint/go-crypto/keys"
)
// REST request body
// TODO does this need to be exposed?
type SignTxBody struct {
Name string `json="name"`
Password string `json="password"`
TxBytes string `json="tx"`
}
// sign transaction REST Handler
func SignTxRequstHandler(w http.ResponseWriter, r *http.Request) {
var kb keys.Keybase
var m SignTxBody