From eb05a9cb3a7937648383d5266ffeb43f2a9820a3 Mon Sep 17 00:00:00 2001 From: jiacheng Date: Fri, 9 Nov 2018 18:38:56 +0800 Subject: [PATCH] Fix all rest api --- Makefile | 2 +- client/bank/lcd/sendtx.go | 2 +- client/distribution/lcd/query.go | 6 +++--- client/lcd/swaggerui/swagger.yaml | 5 +++++ client/lcd/test_helpers.go | 28 ++++++++++++++-------------- client/slashing/lcd/query.go | 2 +- modules/gov/keeper.go | 27 ++++++++++++++------------- 7 files changed, 39 insertions(+), 33 deletions(-) diff --git a/Makefile b/Makefile index 37695060d..f8e943aa7 100644 --- a/Makefile +++ b/Makefile @@ -48,7 +48,7 @@ update_irislcd_swagger_docs: install: update_irislcd_swagger_docs go install $(BUILD_FLAGS) ./cmd/iris go install $(BUILD_FLAGS) ./cmd/iriscli -# go install $(BUILD_FLAGS) ./cmd/irislcd + go install $(BUILD_FLAGS) ./cmd/irislcd # go install $(BUILD_FLAGS) ./cmd/irismon install_debug: diff --git a/client/bank/lcd/sendtx.go b/client/bank/lcd/sendtx.go index 87b70da83..1f10748e2 100644 --- a/client/bank/lcd/sendtx.go +++ b/client/bank/lcd/sendtx.go @@ -125,7 +125,7 @@ func SendTxRequestHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.Ha var sig = make([]auth.StdSignature, len(sendTxBody.Signatures)) for index, s := range sendTxBody.Signatures { var pubkey crypto.PubKey - if err := cdc.UnMarshalBinaryLengthPrefixedBare(s.PubKey, &pubkey); err != nil { + if err := cdc.UnmarshalBinaryBare(s.PubKey, &pubkey); err != nil { utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) return } diff --git a/client/distribution/lcd/query.go b/client/distribution/lcd/query.go index d06e20215..db2a4e1a9 100644 --- a/client/distribution/lcd/query.go +++ b/client/distribution/lcd/query.go @@ -62,7 +62,7 @@ func QueryDelegatorDistInfoHandlerFn(storeName string, cliCtx context.CLIContext var ddiList []types.DelegationDistInfo for _, kv := range resKVs { var ddi types.DelegationDistInfo - err = cliCtx.Codec.UnMarshalBinaryLengthPrefixed(kv.Value, &ddi) + err = cliCtx.Codec.UnmarshalBinaryLengthPrefixed(kv.Value, &ddi) if err != nil { utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) return @@ -105,7 +105,7 @@ func QueryDelegationDistInfoHandlerFn(storeName string, cliCtx context.CLIContex } var ddi types.DelegationDistInfo - err = cliCtx.Codec.UnMarshalBinaryLengthPrefixed(res, &ddi) + err = cliCtx.Codec.UnmarshalBinaryLengthPrefixed(res, &ddi) if err != nil { utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return @@ -139,7 +139,7 @@ func QueryValidatorDistInfoHandlerFn(storeName string, cliCtx context.CLIContext } var vdi types.ValidatorDistInfo - err = cliCtx.Codec.UnMarshalBinaryLengthPrefixed(res, &vdi) + err = cliCtx.Codec.UnmarshalBinaryLengthPrefixed(res, &vdi) if err != nil { utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return diff --git a/client/lcd/swaggerui/swagger.yaml b/client/lcd/swaggerui/swagger.yaml index b37ebd1ff..effd118a0 100644 --- a/client/lcd/swaggerui/swagger.yaml +++ b/client/lcd/swaggerui/swagger.yaml @@ -1392,6 +1392,11 @@ paths: description: proposal status, valid values can be `"DepositPeriod"`, `"VotingPeriod"`, `"Passed"`, `"Rejected"` required: false type: string + - in: query + name: limit + description: limit to latest [number] proposals. Defaults to all proposals + required: false + type: string responses: 200: description: OK diff --git a/client/lcd/test_helpers.go b/client/lcd/test_helpers.go index 062dd0798..a16f26e00 100644 --- a/client/lcd/test_helpers.go +++ b/client/lcd/test_helpers.go @@ -12,37 +12,37 @@ import ( "strings" "testing" + "github.com/cosmos/cosmos-sdk/codec" crkeys "github.com/cosmos/cosmos-sdk/crypto/keys" "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/tests" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/spf13/viper" "github.com/stretchr/testify/require" + txbuilder "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder" + "github.com/cosmos/cosmos-sdk/x/stake" + irisapp "github.com/irisnet/irishub/app" + "github.com/irisnet/irishub/client" + "github.com/irisnet/irishub/client/keys" + "github.com/irisnet/irishub/modules/gov" + "github.com/irisnet/irishub/modules/upgrade" abci "github.com/tendermint/tendermint/abci/types" tmcfg "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/ed25519" + "github.com/tendermint/tendermint/crypto/secp256k1" "github.com/tendermint/tendermint/libs/cli" dbm "github.com/tendermint/tendermint/libs/db" "github.com/tendermint/tendermint/libs/log" nm "github.com/tendermint/tendermint/node" + "github.com/tendermint/tendermint/p2p" pvm "github.com/tendermint/tendermint/privval" "github.com/tendermint/tendermint/proxy" tmrpc "github.com/tendermint/tendermint/rpc/lib/server" tmtypes "github.com/tendermint/tendermint/types" - "github.com/irisnet/irishub/client/keys" - irisapp "github.com/irisnet/irishub/app" - "github.com/irisnet/irishub/client" - "github.com/tendermint/tendermint/p2p" - "github.com/tendermint/tendermint/crypto/secp256k1" - "github.com/cosmos/cosmos-sdk/x/stake" - txbuilder "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder" - "github.com/irisnet/irishub/modules/gov" - "github.com/irisnet/irishub/modules/upgrade" ) // makePathname creates a unique pathname for each test. It will panic if it @@ -173,7 +173,7 @@ func InitializeTestLCD( msg := stake.NewMsgCreateValidator( sdk.ValAddress(operAddr), pubKey, - sdk.NewCoin("iris-atto",sdk.NewIntWithDecimal(1,delegation)), + sdk.NewCoin("iris-atto", sdk.NewIntWithDecimal(1, delegation)), stake.Description{Moniker: fmt.Sprintf("validator-%d", i+1)}, stake.NewCommissionMsg(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()), ) @@ -191,16 +191,16 @@ func InitializeTestLCD( valOperAddrs = append(valOperAddrs, sdk.ValAddress(operAddr)) } - genesisState, err := irisapp.IrisAppGenState(cdc, genTxs) + genesisState, err := irisapp.IrisAppGenState(cdc, *genDoc, genTxs) require.NoError(t, err) // add some tokens to init accounts for _, addr := range initAddrs { accAuth := auth.NewBaseAccountWithAddress(addr) - accAuth.Coins = sdk.Coins{sdk.NewCoin("iris-atto",sdk.NewIntWithDecimal(1,20))} + accAuth.Coins = sdk.Coins{sdk.NewCoin("iris-atto", sdk.NewIntWithDecimal(1, 20))} acc := irisapp.NewGenesisAccount(&accAuth) genesisState.Accounts = append(genesisState.Accounts, acc) - genesisState.StakeData.Pool.LooseTokens = genesisState.StakeData.Pool.LooseTokens.Add(sdk.NewDecFromInt(sdk.NewIntWithDecimal(1,20))) + genesisState.StakeData.Pool.LooseTokens = genesisState.StakeData.Pool.LooseTokens.Add(sdk.NewDecFromInt(sdk.NewIntWithDecimal(1, 20))) } genesisState.GovData = gov.DefaultGenesisStateForLCDTest() diff --git a/client/slashing/lcd/query.go b/client/slashing/lcd/query.go index 1b9aa42f3..7d42d92ff 100644 --- a/client/slashing/lcd/query.go +++ b/client/slashing/lcd/query.go @@ -37,7 +37,7 @@ func signingInfoHandlerFn(cliCtx context.CLIContext, storeName string, cdc *code var signingInfo slashing.ValidatorSigningInfo - err = cdc.UnMarshalBinaryLengthPrefixed(res, &signingInfo) + err = cdc.UnmarshalBinaryLengthPrefixed(res, &signingInfo) if err != nil { utils.WriteErrorResponse(w, http.StatusInternalServerError, fmt.Sprintf("couldn't decode signing info. Error: %s", err.Error())) return diff --git a/modules/gov/keeper.go b/modules/gov/keeper.go index 820693817..63c02ede0 100644 --- a/modules/gov/keeper.go +++ b/modules/gov/keeper.go @@ -1,11 +1,11 @@ package gov import ( - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/bank" - "github.com/irisnet/irishub/modules/gov/params" "github.com/irisnet/irishub/iparam" + "github.com/irisnet/irishub/modules/gov/params" "github.com/tendermint/tendermint/crypto" "time" ) @@ -15,6 +15,7 @@ var ( DepositedCoinsAccAddr = sdk.AccAddress(crypto.AddressHash([]byte("govDepositedCoins"))) BurnedDepositCoinsAccAddr = sdk.AccAddress(crypto.AddressHash([]byte("govBurnedDepositCoins"))) ) + // Governance Keeper type Keeper struct { @@ -42,14 +43,14 @@ type Keeper struct { // - depositing funds into proposals, and activating upon sufficient funds being deposited // - users voting on proposals, with weight proportional to stake in the system // - and tallying the result of the vote. -func NewKeeper(cdc *codec.Codec, key sdk.StoreKey,ck bank.Keeper, ds sdk.DelegationSet, codespace sdk.CodespaceType) Keeper { +func NewKeeper(cdc *codec.Codec, key sdk.StoreKey, ck bank.Keeper, ds sdk.DelegationSet, codespace sdk.CodespaceType) Keeper { return Keeper{ - storeKey: key, - ck: ck, - ds: ds, - vs: ds.GetValidatorSet(), - cdc: cdc, - codespace: codespace, + storeKey: key, + ck: ck, + ds: ds, + vs: ds.GetValidatorSet(), + cdc: cdc, + codespace: codespace, } } @@ -68,8 +69,8 @@ func (keeper Keeper) NewProposal(ctx sdk.Context, title string, description stri } return nil } -//////////////////// iris end ///////////////////////////// +//////////////////// iris end ///////////////////////////// // ===================================================== // Proposals @@ -154,8 +155,8 @@ func (keeper Keeper) NewUpgradeProposal(ctx sdk.Context, title string, descripti keeper.InsertInactiveProposalQueue(ctx, proposal.GetDepositEndTime(), proposalID) return proposal } -//////////////////// iris end ///////////////////////////// +//////////////////// iris end ///////////////////////////// // Get Proposal from store by ProposalID func (keeper Keeper) GetProposal(ctx sdk.Context, proposalID uint64) Proposal { @@ -197,7 +198,7 @@ func (keeper Keeper) GetProposalsFiltered(ctx sdk.Context, voterAddr sdk.AccAddr matchingProposals := []Proposal{} - if numLatest == 0 { + if numLatest == 0 || maxProposalID < numLatest { numLatest = maxProposalID } @@ -495,4 +496,4 @@ func (keeper Keeper) InsertInactiveProposalQueue(ctx sdk.Context, endTime time.T func (keeper Keeper) RemoveFromInactiveProposalQueue(ctx sdk.Context, endTime time.Time, proposalID uint64) { store := ctx.KVStore(keeper.storeKey) store.Delete(KeyInactiveProposalQueueProposal(endTime, proposalID)) -} \ No newline at end of file +}