diff --git a/client/app/app.go b/client/app/app.go index f941fe85..a59d2577 100644 --- a/client/app/app.go +++ b/client/app/app.go @@ -18,10 +18,12 @@ import ( authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" + slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" "github.com/piplabs/story/client/app/keepers" "github.com/piplabs/story/client/comet" + evmstakingkeeper "github.com/piplabs/story/client/x/evmstaking/keeper" "github.com/piplabs/story/lib/errors" "github.com/piplabs/story/lib/ethclient" @@ -177,10 +179,18 @@ func (a App) SetCometAPI(api comet.API) { a.Keepers.EVMEngKeeper.SetCometAPI(api) } +func (a App) GetEvmStakingKeeper() *evmstakingkeeper.Keeper { + return a.Keepers.EvmStakingKeeper +} + func (a App) GetStakingKeeper() *stakingkeeper.Keeper { return a.Keepers.StakingKeeper } +func (a App) GetSlashingKeeper() slashingkeeper.Keeper { + return a.Keepers.SlashingKeeper +} + func (a App) GetAccountKeeper() authkeeper.AccountKeeper { return a.Keepers.AccountKeeper } diff --git a/client/server/auth.go b/client/server/auth.go index 3288502f..485a9852 100644 --- a/client/server/auth.go +++ b/client/server/auth.go @@ -8,14 +8,31 @@ import ( "github.com/cosmos/cosmos-sdk/types/query" "github.com/cosmos/cosmos-sdk/x/auth/keeper" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/gorilla/mux" "github.com/piplabs/story/client/server/utils" ) func (s *Server) initAuthRoute() { + s.httpMux.HandleFunc("/auth/params", utils.SimpleWrap(s.aminoCodec, s.GetAuthParams)) + s.httpMux.HandleFunc("/auth/accounts", utils.AutoWrap(s.aminoCodec, s.GetAccounts)) - s.httpMux.HandleFunc("/auth/accounts/{address}", utils.SimpleWrap(s.aminoCodec, s.GetAccountsByAddress)) + + s.httpMux.HandleFunc("/auth/bech32", utils.SimpleWrap(s.aminoCodec, s.GetBech32Prefix)) +} + +// GetAuthParams queries all parameters of auth module. +func (s *Server) GetAuthParams(r *http.Request) (resp any, err error) { + queryContext, err := s.createQueryContextByHeader(r) + if err != nil { + return nil, err + } + + queryResp, err := keeper.NewQueryServer(s.store.GetAccountKeeper()).Params(queryContext, &authtypes.QueryParamsRequest{}) + if err != nil { + return nil, err + } + + return queryResp, nil } // GetAccounts returns all the existing accounts. @@ -39,8 +56,7 @@ func (s *Server) GetAccounts(req *getAccountsRequest, r *http.Request) (resp any } for _, account := range queryResp.Accounts { - err = s.prepareUnpackInterfaces(utils.WrapTypeAny[types.AccountI](account)) - if err != nil { + if err := s.prepareUnpackInterfaces(utils.WrapTypeAny[types.AccountI](account)); err != nil { return nil, err } } @@ -48,22 +64,14 @@ func (s *Server) GetAccounts(req *getAccountsRequest, r *http.Request) (resp any return queryResp, nil } -// GetAccountsByAddress returns account details based on address. -func (s *Server) GetAccountsByAddress(r *http.Request) (resp any, err error) { +// GetBech32Prefix queries bech32Prefix. +func (s *Server) GetBech32Prefix(r *http.Request) (resp any, err error) { queryContext, err := s.createQueryContextByHeader(r) if err != nil { return nil, err } - queryResp, err := keeper.NewQueryServer(s.store.GetAccountKeeper()).Account(queryContext, &authtypes.QueryAccountRequest{ - Address: mux.Vars(r)["address"], - }) - - if err != nil { - return nil, err - } - - err = s.prepareUnpackInterfaces(utils.WrapTypeAny[types.AccountI](queryResp.Account)) + queryResp, err := keeper.NewQueryServer(s.store.GetAccountKeeper()).Bech32Prefix(queryContext, &authtypes.Bech32PrefixRequest{}) if err != nil { return nil, err } diff --git a/client/server/bank.go b/client/server/bank.go index db77384e..3a4c82b5 100644 --- a/client/server/bank.go +++ b/client/server/bank.go @@ -12,10 +12,54 @@ import ( ) func (s *Server) initBankRoute() { + s.httpMux.HandleFunc("/bank/params", utils.SimpleWrap(s.aminoCodec, s.GetBankParams)) + + s.httpMux.HandleFunc("/bank/supply", utils.AutoWrap(s.aminoCodec, s.GetSupply)) s.httpMux.HandleFunc("/bank/supply/by_denom", utils.AutoWrap(s.aminoCodec, s.GetSupplyByDenom)) s.httpMux.HandleFunc("/bank/balances/{address}", utils.AutoWrap(s.aminoCodec, s.GetBalancesByAddress)) s.httpMux.HandleFunc("/bank/balances/{address}/by_denom", utils.AutoWrap(s.aminoCodec, s.GetBalancesByAddressDenom)) + + s.httpMux.HandleFunc("/bank/denom_owners/{denom}", utils.AutoWrap(s.aminoCodec, s.GetDenomOwners)) + s.httpMux.HandleFunc("/bank/denom_owners_by_query", utils.AutoWrap(s.aminoCodec, s.GetDenomOwnersByQuery)) +} + +// GetBankParams queries the parameters of x/bank module. +func (s *Server) GetBankParams(r *http.Request) (resp any, err error) { + queryContext, err := s.createQueryContextByHeader(r) + if err != nil { + return nil, err + } + + queryResp, err := s.store.GetBankKeeper().Params(queryContext, &banktypes.QueryParamsRequest{}) + if err != nil { + return nil, err + } + + return queryResp, nil +} + +// GetSupply queries the total supply of all coins. +func (s *Server) GetSupply(req *getSupplyRequest, r *http.Request) (resp any, err error) { + queryContext, err := s.createQueryContextByHeader(r) + if err != nil { + return nil, err + } + + queryResp, err := s.store.GetBankKeeper().TotalSupply(queryContext, &banktypes.QueryTotalSupplyRequest{ + Pagination: &query.PageRequest{ + Key: []byte(req.Pagination.Key), + Offset: req.Pagination.Offset, + Limit: req.Pagination.Limit, + CountTotal: req.Pagination.CountTotal, + Reverse: req.Pagination.Reverse, + }, + }) + if err != nil { + return nil, err + } + + return queryResp, err } // GetSupplyByDenom queries the supply of a single coin. @@ -78,3 +122,51 @@ func (s *Server) GetBalancesByAddressDenom(req *getBalancesByAddressDenomRequest return queryResp, nil } + +// GetDenomOwners queries for all account addresses that own a particular token denomination. +func (s *Server) GetDenomOwners(req *getDenomOwnersRequest, r *http.Request) (resp any, err error) { + queryContext, err := s.createQueryContextByHeader(r) + if err != nil { + return nil, err + } + + queryResp, err := s.store.GetBankKeeper().DenomOwners(queryContext, &banktypes.QueryDenomOwnersRequest{ + Denom: mux.Vars(r)["denom"], + Pagination: &query.PageRequest{ + Key: []byte(req.Pagination.Key), + Offset: req.Pagination.Offset, + Limit: req.Pagination.Limit, + CountTotal: req.Pagination.CountTotal, + Reverse: req.Pagination.Reverse, + }, + }) + if err != nil { + return nil, err + } + + return queryResp, err +} + +// GetDenomOwnersByQuery queries for all account addresses that own a particular token denomination. +func (s *Server) GetDenomOwnersByQuery(req *getDenomOwnersByQueryRequest, r *http.Request) (resp any, err error) { + queryContext, err := s.createQueryContextByHeader(r) + if err != nil { + return nil, err + } + + queryResp, err := s.store.GetBankKeeper().DenomOwnersByQuery(queryContext, &banktypes.QueryDenomOwnersByQueryRequest{ + Denom: req.Denom, + Pagination: &query.PageRequest{ + Key: []byte(req.Pagination.Key), + Offset: req.Pagination.Offset, + Limit: req.Pagination.Limit, + CountTotal: req.Pagination.CountTotal, + Reverse: req.Pagination.Reverse, + }, + }) + if err != nil { + return nil, err + } + + return queryResp, err +} diff --git a/client/server/distribution.go b/client/server/distribution.go index e5315216..66c87816 100644 --- a/client/server/distribution.go +++ b/client/server/distribution.go @@ -15,6 +15,8 @@ import ( ) func (s *Server) initDistributionRoute() { + s.httpMux.HandleFunc("/distribution/params", utils.SimpleWrap(s.aminoCodec, s.GetDistributionParams)) + s.httpMux.HandleFunc("/distribution/validators/{validator_address}", utils.SimpleWrap(s.aminoCodec, s.GetDistributionValidatorByValidatorAddress)) s.httpMux.HandleFunc("/distribution/validators/{validator_address}/commission", utils.SimpleWrap(s.aminoCodec, s.GetValidatorCommissionByValidatorAddress)) s.httpMux.HandleFunc("/distribution/validators/{validator_address}/outstanding_rewards", utils.SimpleWrap(s.aminoCodec, s.GetValidatorOutstandingRewardsByValidatorAddress)) @@ -27,6 +29,21 @@ func (s *Server) initDistributionRoute() { s.httpMux.HandleFunc("/distribution/delegators/{delegator_address}/withdraw_address", utils.SimpleWrap(s.aminoCodec, s.GetDelegatorWithdrawAddressByDelegatorAddress)) } +// GetDistributionParams queries params of the distribution module. +func (s *Server) GetDistributionParams(r *http.Request) (resp any, err error) { + queryContext, err := s.createQueryContextByHeader(r) + if err != nil { + return nil, err + } + + queryResp, err := keeper.NewQuerier(s.store.GetDistrKeeper()).Params(queryContext, &distributiontypes.QueryParamsRequest{}) + if err != nil { + return nil, err + } + + return queryResp, nil +} + // GetDistributionValidatorByValidatorAddress queries validator commission and self-delegation rewards for validator. func (s *Server) GetDistributionValidatorByValidatorAddress(r *http.Request) (resp any, err error) { queryContext, err := s.createQueryContextByHeader(r) @@ -37,7 +54,6 @@ func (s *Server) GetDistributionValidatorByValidatorAddress(r *http.Request) (re queryResp, err := keeper.NewQuerier(s.store.GetDistrKeeper()).ValidatorDistributionInfo(queryContext, &distributiontypes.QueryValidatorDistributionInfoRequest{ ValidatorAddress: mux.Vars(r)["validator_address"], }) - if err != nil { return nil, err } diff --git a/client/server/evmstaking.go b/client/server/evmstaking.go new file mode 100644 index 00000000..2ea82283 --- /dev/null +++ b/client/server/evmstaking.go @@ -0,0 +1,27 @@ +package server + +import ( + "net/http" + + "github.com/piplabs/story/client/server/utils" + evmstakingtypes "github.com/piplabs/story/client/x/evmstaking/types" +) + +func (s *Server) initEvmStakingRoute() { + s.httpMux.HandleFunc("/evmstaking/params", utils.SimpleWrap(s.aminoCodec, s.GetEvmStakingParams)) +} + +// GetEvmStakingParams queries the parameters of evmstaking module. +func (s *Server) GetEvmStakingParams(r *http.Request) (resp any, err error) { + queryContext, err := s.createQueryContextByHeader(r) + if err != nil { + return nil, err + } + + queryResp, err := s.store.GetEvmStakingKeeper().Params(queryContext, &evmstakingtypes.QueryParamsRequest{}) + if err != nil { + return nil, err + } + + return queryResp, nil +} diff --git a/client/server/payload.go b/client/server/payload.go index 94854121..6fccde7b 100644 --- a/client/server/payload.go +++ b/client/server/payload.go @@ -13,34 +13,11 @@ type pagination struct { Reverse bool `mapstructure:"reverse"` } -type getValidatorsRequest struct { - Status string `mapstructure:"status"` - Pagination pagination `mapstructure:"pagination"` -} - -type getValidatorDelegationsByValidatorAddressRequest struct { - Pagination pagination `mapstructure:"pagination"` -} - -type getDelegationsByDelegatorAddressRequest struct { - Pagination pagination `mapstructure:"pagination"` -} - -type getRedelegationsByDelegatorAddressRequest struct { - SrcValidatorAddr string `mapstructure:"src_validator_addr"` - DstValidatorAddr string `mapstructure:"dst_validator_addr"` - Pagination pagination `mapstructure:"pagination"` -} - -type getUnbondingDelegationsByDelegatorAddressRequest struct { - Pagination pagination `mapstructure:"pagination"` -} - -type getValidatorsByDelegatorAddressRequest struct { +type getAccountsRequest struct { Pagination pagination `mapstructure:"pagination"` } -type getAccountsRequest struct { +type getSupplyRequest struct { Pagination pagination `mapstructure:"pagination"` } @@ -54,14 +31,16 @@ type getBalancesByAddressRequest struct { } type getBalancesByAddressDenomRequest struct { - Denom string `mapstructure:"denom"` + Denom string `mapstructure:"denom"` +} + +type getDenomOwnersRequest struct { Pagination pagination `mapstructure:"pagination"` } -type getValidatorSlashesByValidatorAddressRequest struct { - StartingHeight uint64 `mapstructure:"starting_height"` - EndingHeight uint64 `mapstructure:"ending_height"` - Pagination pagination `mapstructure:"pagination"` +type getDenomOwnersByQueryRequest struct { + Denom string `mapstructure:"denom"` + Pagination pagination `mapstructure:"pagination"` } type getComebftBlockEventsRequest struct { @@ -85,6 +64,47 @@ type getAllValidatorOutstandingRewardsRequestBlockResults struct { Validators map[string]sdk.DecCoins `json:"validators"` } +type getValidatorSlashesByValidatorAddressRequest struct { + StartingHeight uint64 `mapstructure:"starting_height"` + EndingHeight uint64 `mapstructure:"ending_height"` + Pagination pagination `mapstructure:"pagination"` +} + +type getSigningInfosRequest struct { + Pagination pagination `mapstructure:"pagination"` +} + +type getValidatorsRequest struct { + Status string `mapstructure:"status"` + Pagination pagination `mapstructure:"pagination"` +} + +type getValidatorDelegationsByValidatorAddressRequest struct { + Pagination pagination `mapstructure:"pagination"` +} + +type getValidatorUnbondingDelegationsRequest struct { + Pagination pagination `mapstructure:"pagination"` +} + +type getDelegationsByDelegatorAddressRequest struct { + Pagination pagination `mapstructure:"pagination"` +} + +type getRedelegationsByDelegatorAddressRequest struct { + SrcValidatorAddr string `mapstructure:"src_validator_addr"` + DstValidatorAddr string `mapstructure:"dst_validator_addr"` + Pagination pagination `mapstructure:"pagination"` +} + +type getUnbondingDelegationsByDelegatorAddressRequest struct { + Pagination pagination `mapstructure:"pagination"` +} + +type getValidatorsByDelegatorAddressRequest struct { + Pagination pagination `mapstructure:"pagination"` +} + type getModuleVersionsRequest struct { ModuleName string `mapstructure:"module_name"` } diff --git a/client/server/server.go b/client/server/server.go index 6e9b76c6..ce31c476 100644 --- a/client/server/server.go +++ b/client/server/server.go @@ -21,15 +21,20 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" + slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" "github.com/cosmos/gogoproto/proto" "github.com/gorilla/handlers" "github.com/gorilla/mux" + + evmstakingkeeper "github.com/piplabs/story/client/x/evmstaking/keeper" ) type Store interface { CreateQueryContext(height int64, prove bool) (sdk.Context, error) + GetEvmStakingKeeper() *evmstakingkeeper.Keeper GetStakingKeeper() *stakingkeeper.Keeper + GetSlashingKeeper() slashingkeeper.Keeper GetAccountKeeper() authkeeper.AccountKeeper GetBankKeeper() bankkeeper.Keeper GetDistrKeeper() distrkeeper.Keeper @@ -108,11 +113,13 @@ func (s *Server) prepareUnpackInterfaces(v codectypes.UnpackInterfacesMessage) e } func (s *Server) registerHandle() { - s.initStakingRoute() s.initAuthRoute() s.initBankRoute() - s.initDistributionRoute() s.initComeBFTRoute() + s.initDistributionRoute() + s.initEvmStakingRoute() + s.initSlashingRoute() + s.initStakingRoute() s.initUpgradeRoute() } diff --git a/client/server/slashing.go b/client/server/slashing.go new file mode 100644 index 00000000..e4bae4a2 --- /dev/null +++ b/client/server/slashing.go @@ -0,0 +1,74 @@ +//nolint:wrapcheck // The api server is our server, so we don't need to wrap it. +package server + +import ( + "net/http" + + "github.com/cosmos/cosmos-sdk/types/query" + "github.com/cosmos/cosmos-sdk/x/slashing/keeper" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" + "github.com/gorilla/mux" + + "github.com/piplabs/story/client/server/utils" +) + +func (s *Server) initSlashingRoute() { + s.httpMux.HandleFunc("/slashing/params", utils.SimpleWrap(s.aminoCodec, s.GetSlashingParams)) + s.httpMux.HandleFunc("/slashing/signing_infos", utils.AutoWrap(s.aminoCodec, s.GetSigningInfos)) + s.httpMux.HandleFunc("/slashing/signing_infos/{cons_address}", utils.SimpleWrap(s.aminoCodec, s.GetSigningInfo)) +} + +// GetSlashingParams queries the parameters of slashing module. +func (s *Server) GetSlashingParams(r *http.Request) (resp any, err error) { + queryContext, err := s.createQueryContextByHeader(r) + if err != nil { + return nil, err + } + + queryResp, err := keeper.NewQuerier(s.store.GetSlashingKeeper()).Params(queryContext, &slashingtypes.QueryParamsRequest{}) + if err != nil { + return nil, err + } + + return queryResp, nil +} + +// GetSigningInfos queries signing info of all validators. +func (s *Server) GetSigningInfos(req *getSigningInfosRequest, r *http.Request) (resp any, err error) { + queryContext, err := s.createQueryContextByHeader(r) + if err != nil { + return nil, err + } + + queryResp, err := keeper.NewQuerier(s.store.GetSlashingKeeper()).SigningInfos(queryContext, &slashingtypes.QuerySigningInfosRequest{ + Pagination: &query.PageRequest{ + Key: []byte(req.Pagination.Key), + Offset: req.Pagination.Offset, + Limit: req.Pagination.Limit, + CountTotal: req.Pagination.CountTotal, + Reverse: req.Pagination.Reverse, + }, + }) + if err != nil { + return nil, err + } + + return queryResp, nil +} + +// GetSigningInfo queries the signing info of given cons address. +func (s *Server) GetSigningInfo(r *http.Request) (resp any, err error) { + queryContext, err := s.createQueryContextByHeader(r) + if err != nil { + return nil, err + } + + queryResp, err := keeper.NewQuerier(s.store.GetSlashingKeeper()).SigningInfo(queryContext, &slashingtypes.QuerySigningInfoRequest{ + ConsAddress: mux.Vars(r)["cons_address"], + }) + if err != nil { + return nil, err + } + + return queryResp, nil +} diff --git a/client/server/staking.go b/client/server/staking.go index 9fe17472..2f712875 100644 --- a/client/server/staking.go +++ b/client/server/staking.go @@ -3,6 +3,7 @@ package server import ( "net/http" + "strconv" "github.com/cosmos/cosmos-sdk/types/query" "github.com/cosmos/cosmos-sdk/x/staking/keeper" @@ -13,12 +14,16 @@ import ( ) func (s *Server) initStakingRoute() { + s.httpMux.HandleFunc("/staking/params", utils.SimpleWrap(s.aminoCodec, s.GetStakingParams)) s.httpMux.HandleFunc("/staking/pool", utils.SimpleWrap(s.aminoCodec, s.GetStakingPool)) + s.httpMux.HandleFunc("/staking/historical_info/{height}", utils.SimpleWrap(s.aminoCodec, s.GetHistoricalInfoByHeight)) s.httpMux.HandleFunc("/staking/validators", utils.AutoWrap(s.aminoCodec, s.GetValidators)) s.httpMux.HandleFunc("/staking/validators/{validator_addr}", utils.SimpleWrap(s.aminoCodec, s.GetValidatorByValidatorAddress)) s.httpMux.HandleFunc("/staking/validators/{validator_addr}/delegations", utils.AutoWrap(s.aminoCodec, s.GetValidatorDelegationsByValidatorAddress)) s.httpMux.HandleFunc("/staking/validators/{validator_addr}/delegations/{delegator_addr}", utils.SimpleWrap(s.aminoCodec, s.GetDelegationByValidatorAddressDelegatorAddress)) + s.httpMux.HandleFunc("/staking/validators/{validator_addr}/unbonding_delegations", utils.AutoWrap(s.aminoCodec, s.GetValidatorUnbondingDelegations)) + s.httpMux.HandleFunc("/staking/validators/{validator_addr}/delegations/{delegator_addr}/unbonding_delegation", utils.SimpleWrap(s.aminoCodec, s.GetDelegatorUnbondingDelegation)) s.httpMux.HandleFunc("/staking/delegations/{delegator_addr}", utils.AutoWrap(s.aminoCodec, s.GetDelegationsByDelegatorAddress)) s.httpMux.HandleFunc("/staking/delegators/{delegator_addr}/redelegations", utils.AutoWrap(s.aminoCodec, s.GetRedelegationsByDelegatorAddress)) @@ -27,6 +32,21 @@ func (s *Server) initStakingRoute() { s.httpMux.HandleFunc("/staking/delegators/{delegator_addr}/validators/{validator_addr}", utils.SimpleWrap(s.aminoCodec, s.GetValidatorsByDelegatorAddressValidatorAddress)) } +// GetStakingParams queries the staking parameters. +func (s *Server) GetStakingParams(r *http.Request) (resp any, err error) { + queryContext, err := s.createQueryContextByHeader(r) + if err != nil { + return nil, err + } + + queryResp, err := keeper.NewQuerier(s.store.GetStakingKeeper()).Params(queryContext, &stakingtypes.QueryParamsRequest{}) + if err != nil { + return nil, err + } + + return queryResp, nil +} + // GetStakingPool queries the staking pool info. func (s *Server) GetStakingPool(r *http.Request) (resp any, err error) { queryContext, err := s.createQueryContextByHeader(r) @@ -42,6 +62,33 @@ func (s *Server) GetStakingPool(r *http.Request) (resp any, err error) { return queryResp, nil } +// GetHistoricalInfoByHeight queries the historical info for given height. +func (s *Server) GetHistoricalInfoByHeight(r *http.Request) (resp any, err error) { + queryContext, err := s.createQueryContextByHeader(r) + if err != nil { + return nil, err + } + + heightStr := mux.Vars(r)["height"] + height, err := strconv.ParseInt(heightStr, 10, 64) + if err != nil { + return nil, err + } + + queryResp, err := keeper.NewQuerier(s.store.GetStakingKeeper()).HistoricalInfo(queryContext, &stakingtypes.QueryHistoricalInfoRequest{ + Height: height, + }) + if err != nil { + return nil, err + } + + if err := s.prepareUnpackInterfaces(queryResp.Hist); err != nil { + return nil, err + } + + return queryResp, nil +} + // GetValidators queries all validators that match the given status. func (s *Server) GetValidators(req *getValidatorsRequest, r *http.Request) (resp any, err error) { queryContext, err := s.createQueryContextByHeader(r) @@ -65,8 +112,7 @@ func (s *Server) GetValidators(req *getValidatorsRequest, r *http.Request) (resp } for _, validator := range queryResp.Validators { - err = s.prepareUnpackInterfaces(validator) - if err != nil { + if err := s.prepareUnpackInterfaces(validator); err != nil { return nil, err } } @@ -89,8 +135,7 @@ func (s *Server) GetValidatorByValidatorAddress(r *http.Request) (resp any, err return nil, err } - err = s.prepareUnpackInterfaces(queryResp.Validator) - if err != nil { + if err := s.prepareUnpackInterfaces(queryResp.Validator); err != nil { return nil, err } @@ -141,6 +186,49 @@ func (s *Server) GetDelegationByValidatorAddressDelegatorAddress(r *http.Request return queryResp, nil } +// GetValidatorUnbondingDelegations queries unbonding delegations of a validator. +func (s *Server) GetValidatorUnbondingDelegations(req *getValidatorUnbondingDelegationsRequest, r *http.Request) (resp any, err error) { + queryContext, err := s.createQueryContextByHeader(r) + if err != nil { + return nil, err + } + + queryResp, err := keeper.NewQuerier(s.store.GetStakingKeeper()).ValidatorUnbondingDelegations(queryContext, &stakingtypes.QueryValidatorUnbondingDelegationsRequest{ + ValidatorAddr: mux.Vars(r)["validator_addr"], + Pagination: &query.PageRequest{ + Key: []byte(req.Pagination.Key), + Offset: req.Pagination.Offset, + Limit: req.Pagination.Limit, + CountTotal: req.Pagination.CountTotal, + Reverse: req.Pagination.Reverse, + }, + }) + if err != nil { + return nil, err + } + + return queryResp, nil +} + +// GetDelegatorUnbondingDelegation queries unbonding info for given validator delegator pair. +func (s *Server) GetDelegatorUnbondingDelegation(r *http.Request) (resp any, err error) { + queryContext, err := s.createQueryContextByHeader(r) + if err != nil { + return nil, err + } + + muxVars := mux.Vars(r) + queryResp, err := keeper.NewQuerier(s.store.GetStakingKeeper()).UnbondingDelegation(queryContext, &stakingtypes.QueryUnbondingDelegationRequest{ + ValidatorAddr: muxVars["validator_addr"], + DelegatorAddr: muxVars["delegator_addr"], + }) + if err != nil { + return nil, err + } + + return queryResp, nil +} + // GetDelegationsByDelegatorAddress queries all delegations of a given delegator address. func (s *Server) GetDelegationsByDelegatorAddress(req *getDelegationsByDelegatorAddressRequest, r *http.Request) (resp any, err error) { queryContext, err := s.createQueryContextByHeader(r) @@ -241,8 +329,7 @@ func (s *Server) GetValidatorsByDelegatorAddress(req *getValidatorsByDelegatorAd } for _, validator := range queryResp.Validators { - err = s.prepareUnpackInterfaces(validator) - if err != nil { + if err = s.prepareUnpackInterfaces(validator); err != nil { return nil, err } } @@ -267,8 +354,7 @@ func (s *Server) GetValidatorsByDelegatorAddressValidatorAddress(r *http.Request return nil, err } - err = s.prepareUnpackInterfaces(queryResp.Validator) - if err != nil { + if err := s.prepareUnpackInterfaces(queryResp.Validator); err != nil { return nil, err } diff --git a/client/server/upgrade.go b/client/server/upgrade.go index 4766d5bc..f7f33c8b 100644 --- a/client/server/upgrade.go +++ b/client/server/upgrade.go @@ -6,14 +6,66 @@ import ( upgradetypes "cosmossdk.io/x/upgrade/types" + "github.com/gorilla/mux" + "github.com/piplabs/story/client/server/utils" ) func (s *Server) initUpgradeRoute() { + s.httpMux.HandleFunc("/upgrade/applied_plan/{name}", utils.SimpleWrap(s.aminoCodec, s.GetAppliedPlan)) + s.httpMux.HandleFunc("/upgrade/authority", utils.SimpleWrap(s.aminoCodec, s.GetAuthority)) + s.httpMux.HandleFunc("/upgrade/current_plan", utils.SimpleWrap(s.aminoCodec, s.GetCurrentPlan)) s.httpMux.HandleFunc("/upgrade/module_versions", utils.AutoWrap(s.aminoCodec, s.ModuleVersions)) } -// GetAccounts returns all the existing accounts. +// GetAppliedPlan queries a previously applied upgrade plan by its name. +func (s *Server) GetAppliedPlan(r *http.Request) (resp any, err error) { + queryContext, err := s.createQueryContextByHeader(r) + if err != nil { + return nil, err + } + + queryResp, err := s.store.GetUpgradeKeeper().AppliedPlan(queryContext, &upgradetypes.QueryAppliedPlanRequest{ + Name: mux.Vars(r)["name"], + }) + if err != nil { + return nil, err + } + + return queryResp, nil +} + +// GetAuthority returns the account with authority to conduct upgrades. +func (s *Server) GetAuthority(r *http.Request) (resp any, err error) { + queryContext, err := s.createQueryContextByHeader(r) + if err != nil { + return nil, err + } + + queryResp, err := s.store.GetUpgradeKeeper().Authority(queryContext, &upgradetypes.QueryAuthorityRequest{}) + if err != nil { + return nil, err + } + + return queryResp, nil +} + +// GetCurrentPlan queries the current upgrade plan. +func (s *Server) GetCurrentPlan(r *http.Request) (resp any, err error) { + queryContext, err := s.createQueryContextByHeader(r) + if err != nil { + return nil, err + } + + queryResp, err := s.store.GetUpgradeKeeper().CurrentPlan(queryContext, &upgradetypes.QueryCurrentPlanRequest{}) + if err != nil { + return nil, err + } + + return queryResp, nil +} + +// ModuleVersions queries the list of module versions from state. func (s *Server) ModuleVersions(req *getModuleVersionsRequest, r *http.Request) (resp any, err error) { queryContext, err := s.createQueryContextByHeader(r) if err != nil {