Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R4R: Code formatting and cleaning #1989

Merged
merged 4 commits into from
Sep 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"strings"

"github.com/irisnet/irishub/app/protocol"
"github.com/irisnet/irishub/app/v0"
"github.com/irisnet/irishub/app/v1"
"github.com/irisnet/irishub/app/v2"
v0 "github.com/irisnet/irishub/app/v0"
v1 "github.com/irisnet/irishub/app/v1"
v2 "github.com/irisnet/irishub/app/v2"
"github.com/irisnet/irishub/codec"
"github.com/irisnet/irishub/modules/auth"
"github.com/irisnet/irishub/store"
Expand All @@ -28,9 +28,12 @@ import (
const (
appName = "IrisApp"
appPrometheusNamespace = "iris"
FlagReplay = "replay-last-block"
DefaultSyncableHeight = store.NumStoreEvery // Multistore saves a snapshot every 10000 blocks
DefaultCacheSize = store.NumRecent // Multistore saves last 100 blocks
// FlagReplay used for replaying last block
FlagReplay = "replay-last-block"
// Multistore saves a snapshot every 10000 blocks
DefaultSyncableHeight = store.NumStoreEvery
// Multistore saves last 100 blocks
DefaultCacheSize = store.NumRecent
)

// default home directories for expected binaries
Expand All @@ -40,11 +43,12 @@ var (
DefaultNodeHome = os.ExpandEnv("$HOME/.iris")
)

// Extended ABCI application
//IrisApp Extended ABCI application
type IrisApp struct {
*BaseApp
}

// NewIrisApp generates an iris application
func NewIrisApp(logger log.Logger, db dbm.DB, config *cfg.InstrumentationConfig, traceStore io.Writer, baseAppOptions ...func(*BaseApp)) *IrisApp {
bApp := NewBaseApp(appName, logger, db, baseAppOptions...)
bApp.SetCommitMultiStoreTracer(traceStore)
Expand Down Expand Up @@ -87,16 +91,18 @@ func NewIrisApp(logger log.Logger, db dbm.DB, config *cfg.InstrumentationConfig,
return app
}

// latest version of codec
// MakeLatestCodec loads the lastest verson codec
func MakeLatestCodec() *codec.Codec {
var cdc = v2.MakeCodec() // replace with latest protocol version
return cdc
}

// LastBlockHeight returns the last blcok height
func (app *IrisApp) LastBlockHeight() int64 {
return app.BaseApp.LastBlockHeight()
}

// ResetOrReplay returns whether you need to reset or replay
func (app *IrisApp) ResetOrReplay(replayHeight int64) (replay bool, height int64) {
lastBlockHeight := app.BaseApp.LastBlockHeight()
if replayHeight > lastBlockHeight {
Expand Down Expand Up @@ -157,12 +163,13 @@ func (app *IrisApp) ResetOrReplay(replayHeight int64) (replay bool, height int64

}

// export the state of iris for a genesis file
// ExportAppStateAndValidators exports the state of iris for a genesis file
func (app *IrisApp) ExportAppStateAndValidators(forZeroHeight bool) (appState json.RawMessage, validators []tmtypes.GenesisValidator, err error) {
ctx := app.NewContext(true, abci.Header{Height: app.LastBlockHeight()})
return app.Engine.GetCurrentProtocol().ExportAppStateAndValidators(ctx, forZeroHeight)
}

// LoadHeight loads to the specified height
func (app *IrisApp) LoadHeight(height int64) error {
return app.LoadVersion(height, protocol.KeyMain, false)
}
Expand Down
2 changes: 1 addition & 1 deletion app/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ func (app *BaseApp) cacheTxContext(ctx sdk.Context, txBytes []byte) (
return ctx.WithMultiStore(msCache), msCache
}

// runTx processes a transaction. The transactions is proccessed via an
// runTx processes a transaction. The transactions is processed via an
// anteHandler. txBytes may be nil in some cases, eg. in tests. Also, in the
// future we may support "internal" transactions.
func (app *BaseApp) runTx(mode RunTxMode, txBytes []byte, tx sdk.Tx) (result sdk.Result) {
Expand Down
2 changes: 1 addition & 1 deletion app/v1/mock/baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ func (app *BaseApp) initializeContext(ctx sdk.Context, mode RunTxMode) sdk.Conte
return ctx
}

// runTx processes a transaction. The transactions is proccessed via an
// runTx processes a transaction. The transactions is processed via an
// anteHandler. txBytes may be nil in some cases, eg. in tests. Also, in the
// future we may support "internal" transactions.
func (app *BaseApp) runTx(mode RunTxMode, txBytes []byte, tx sdk.Tx) (result sdk.Result) {
Expand Down
2 changes: 1 addition & 1 deletion app/v1/params/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type QueryModuleParams struct {

func queryAll(ctx sdk.Context, keeper Keeper) ([]byte, sdk.Error) {
var paramSets ParamSets
for key, _ := range keeper.spaces {
for key := range keeper.spaces {
ps, _ := queryModule(ctx, key, keeper)
paramSets = append(paramSets, ps)
}
Expand Down
2 changes: 1 addition & 1 deletion app/v2/coinswap/internal/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,4 @@ func getTokenPairByDenom(inputDenom, outputDenom string) string {
}

return fmt.Sprintf("%s-%s", outputToken, inputToken)
}
}
2 changes: 1 addition & 1 deletion client/coinswap/lcd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Co
// queryLiquidityHandlerFn performs liquidity information query
func queryLiquidityHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc {
return queryLiquidity(cliCtx, cdc, "custom/coinswap/liquidities/{id}")
}
}
12 changes: 6 additions & 6 deletions client/coinswap/lcd/sendtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,19 @@ func addLiquidityHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.Han

maxToken, ok := sdk.NewIntFromString(req.MaxToken)
if !ok || !maxToken.IsPositive() {
utils.WriteErrorResponse(w, http.StatusBadRequest, "invalid max token amount: " + req.MaxToken)
utils.WriteErrorResponse(w, http.StatusBadRequest, "invalid max token amount: "+req.MaxToken)
return
}

exactIrisAmt, ok := sdk.NewIntFromString(req.ExactIrisAmt)
if !ok {
utils.WriteErrorResponse(w, http.StatusBadRequest, "invalid exact iris amount: " + req.ExactIrisAmt)
utils.WriteErrorResponse(w, http.StatusBadRequest, "invalid exact iris amount: "+req.ExactIrisAmt)
return
}

minLiquidity, ok := sdk.NewIntFromString(req.MinLiquidity)
if !ok {
utils.WriteErrorResponse(w, http.StatusBadRequest, "invalid min liquidity amount: " + req.MinLiquidity)
utils.WriteErrorResponse(w, http.StatusBadRequest, "invalid min liquidity amount: "+req.MinLiquidity)
return
}

Expand Down Expand Up @@ -183,19 +183,19 @@ func removeLiquidityHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.

minToken, ok := sdk.NewIntFromString(req.MinToken)
if !ok {
utils.WriteErrorResponse(w, http.StatusBadRequest, "invalid min token amount: " + req.MinToken)
utils.WriteErrorResponse(w, http.StatusBadRequest, "invalid min token amount: "+req.MinToken)
return
}

minIris, ok := sdk.NewIntFromString(req.MinIrisAmt)
if !ok {
utils.WriteErrorResponse(w, http.StatusBadRequest, "invalid min iris amount: " + req.MinIrisAmt)
utils.WriteErrorResponse(w, http.StatusBadRequest, "invalid min iris amount: "+req.MinIrisAmt)
return
}

liquidityAmt, ok := sdk.NewIntFromString(req.WithdrawLiquidity)
if !ok || !liquidityAmt.IsPositive() {
utils.WriteErrorResponse(w, http.StatusBadRequest, "invalid liquidity amount: " + req.WithdrawLiquidity)
utils.WriteErrorResponse(w, http.StatusBadRequest, "invalid liquidity amount: "+req.WithdrawLiquidity)
return
}

Expand Down
2 changes: 1 addition & 1 deletion client/coinswap/lcd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func queryLiquidity(cliCtx context.CLIContext, cdc *codec.Codec, endpoint string
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
id := vars["id"]
params := coinswap.QueryLiquidityParams {
params := coinswap.QueryLiquidityParams{
Id: id,
}

Expand Down
6 changes: 2 additions & 4 deletions client/gov/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"fmt"

"github.com/irisnet/irishub/app/protocol"
"github.com/irisnet/irishub/app/v1/gov"
"github.com/irisnet/irishub/client/context"
Expand Down Expand Up @@ -50,7 +51,6 @@ func GetCmdQueryProposal(cdc *codec.Codec) *cobra.Command {
return cmd
}

// nolint: gocyclo
// GetCmdQueryProposals implements a query proposals command.
func GetCmdQueryProposals(cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Expand Down Expand Up @@ -122,7 +122,6 @@ func GetCmdQueryProposals(cdc *codec.Codec) *cobra.Command {
return cmd
}

// Command to Get a Proposal Information
// GetCmdQueryVote implements the query proposal vote command.
func GetCmdQueryVote(cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Expand Down Expand Up @@ -205,7 +204,6 @@ func GetCmdQueryVotes(cdc *codec.Codec) *cobra.Command {
return cmd
}

// Command to Get a specific Deposit Information
// GetCmdQueryDeposit implements the query proposal deposit command.
func GetCmdQueryDeposit(cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Expand Down Expand Up @@ -288,7 +286,7 @@ func GetCmdQueryDeposits(cdc *codec.Codec) *cobra.Command {
return cmd
}

// GetCmdQueryDeposits implements the command to query for proposal deposits.
// GetCmdQueryTally implements the command to query for proposal deposits.
func GetCmdQueryTally(cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "query-tally",
Expand Down
12 changes: 6 additions & 6 deletions client/gov/cli/sendtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,19 @@ func GetCmdSubmitProposal(cdc *codec.Codec) *cobra.Command {

if proposalType == gov.ProposalTypeSoftwareUpgrade {

version_ := viper.GetInt64(flagVersion)
if version_ < 0 {
versionInt := viper.GetInt64(flagVersion)
if versionInt < 0 {
return errors.Errorf("Version must greater than or equal to zero")
}

version := uint64(version_)
version := uint64(versionInt)
software := viper.GetString(flagSoftware)

switchHeight_ := viper.GetInt64(flagSwitchHeight)
if switchHeight_ < 0 {
switchHeightInt := viper.GetInt64(flagSwitchHeight)
if switchHeightInt < 0 {
return errors.Errorf("SwitchHeight must greater than or equal to zero")
}
switchHeight := uint64(switchHeight_)
switchHeight := uint64(switchHeightInt)

thresholdStr := viper.GetString(flagThreshold)
threshold, err := sdk.NewDecFromStr(thresholdStr)
Expand Down
4 changes: 2 additions & 2 deletions cmd/iristool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package main
import (
"os"

"github.com/spf13/cobra"
debugcmd "github.com/irisnet/irishub/tools/debug"
"github.com/irisnet/irishub/app"
debugcmd "github.com/irisnet/irishub/tools/debug"
"github.com/spf13/cobra"
"github.com/tendermint/tendermint/libs/cli"
)

Expand Down
2 changes: 1 addition & 1 deletion mock/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (

"github.com/irisnet/irishub/modules/auth"
"github.com/irisnet/irishub/modules/bank"
stakeTypes "github.com/irisnet/irishub/modules/stake/types"
sdk "github.com/irisnet/irishub/types"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
stakeTypes "github.com/irisnet/irishub/modules/stake/types"
)

type (
Expand Down
2 changes: 1 addition & 1 deletion mock/baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ func (app *BaseApp) initializeContext(ctx sdk.Context, mode RunTxMode) sdk.Conte
return ctx
}

// runTx processes a transaction. The transactions is proccessed via an
// runTx processes a transaction. The transactions is processed via an
// anteHandler. txBytes may be nil in some cases, eg. in tests. Also, in the
// future we may support "internal" transactions.
func (app *BaseApp) runTx(mode RunTxMode, txBytes []byte, tx sdk.Tx) (result sdk.Result) {
Expand Down
2 changes: 1 addition & 1 deletion mock/baseapp/helpers.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package baseapp

import (
sdk "github.com/irisnet/irishub/types"
"github.com/tendermint/tendermint/abci/server"
abci "github.com/tendermint/tendermint/abci/types"
cmn "github.com/tendermint/tendermint/libs/common"
sdk "github.com/irisnet/irishub/types"
)

// nolint - Mostly for testing
Expand Down
2 changes: 1 addition & 1 deletion mock/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (

"github.com/irisnet/irishub/modules/auth"
"github.com/irisnet/irishub/modules/bank"
stakeTypes "github.com/irisnet/irishub/modules/stake/types"
sdk "github.com/irisnet/irishub/types"
abci "github.com/tendermint/tendermint/abci/types"
stakeTypes "github.com/irisnet/irishub/modules/stake/types"
)

// getBenchmarkMockApp initializes a mock application for this module, for purposes of benchmarking
Expand Down
2 changes: 1 addition & 1 deletion mock/simulation/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"math/rand"
"time"

sdk "github.com/irisnet/irishub/types"
bam "github.com/irisnet/irishub/mock/baseapp"
sdk "github.com/irisnet/irishub/types"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto"
)
Expand Down
14 changes: 7 additions & 7 deletions mock/simulation/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ package simulation

import (
"fmt"
"github.com/irisnet/irishub/mock"
bam "github.com/irisnet/irishub/mock/baseapp"
sdk "github.com/irisnet/irishub/types"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/secp256k1"
"math/big"
"math/rand"
"os"
"sort"
"strings"
"testing"
"time"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/secp256k1"
"math/big"
"github.com/irisnet/irishub/mock"
bam "github.com/irisnet/irishub/mock/baseapp"
sdk "github.com/irisnet/irishub/types"
abci "github.com/tendermint/tendermint/abci/types"
)

const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
Expand Down
2 changes: 1 addition & 1 deletion modules/auth/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func TestContextWithSigners(t *testing.T) {
ms, _, _ , _, _:= setupMultiStore()
ms, _, _, _, _ := setupMultiStore()
ctx := sdk.NewContext(ms, abci.Header{ChainID: "mychainid"}, false, log.NewNopLogger())

_, _, addr1 := keyPubAddr()
Expand Down
6 changes: 3 additions & 3 deletions modules/auth/feekeeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/tendermint/tendermint/libs/log"

codec "github.com/irisnet/irishub/codec"
sdk "github.com/irisnet/irishub/types"
"github.com/irisnet/irishub/modules/params"
sdk "github.com/irisnet/irishub/types"
)

var (
Expand Down Expand Up @@ -40,7 +40,7 @@ func TestFeeCollectionKeeperGetSet(t *testing.T) {
}

func TestFeeCollectionKeeperAdd(t *testing.T) {
ms, _, capKey2, paramsKey, tParamsKey := setupMultiStore()
ms, _, capKey2, paramsKey, tParamsKey := setupMultiStore()
cdc := codec.New()

// make context and keeper
Expand All @@ -61,7 +61,7 @@ func TestFeeCollectionKeeperAdd(t *testing.T) {
}

func TestFeeCollectionKeeperClear(t *testing.T) {
ms, _, capKey2, paramsKey, tParamsKey := setupMultiStore()
ms, _, capKey2, paramsKey, tParamsKey := setupMultiStore()
cdc := codec.New()

// make context and keeper
Expand Down
Loading