cosmos-sdk/x/stake/client/rest/utils.go
Federico Kunze d195cc15ed Merge PR #2249: Staking Querier pt1
* Cherry picked commits from prev branch

* Added new keepers for querier functionalities

* Renaming

* Fixed gov errors and messages

* Added Querier to stake and app

* Update delegation keepers

* REST Queriers not working

* Fix marshalling error

* Querier tests working

* Pool and params working

* sdk.NewCoin for test handler

* Refactor and renaming

* Update LCD queries and added more tests for queriers

* use sdk.NewCoin

* Delegator summary query and tests

* Added more tests for keeper

* Update PENDING.md

* Update stake rest query

* Format and replaced panics for sdk.Error

* Refactor and addressed comments from Sunny and Aleks

* Fixed some of the errors produced by addr type change

* Fixed remaining errors

* Updated and fixed lite tests

* JSON Header and consistency on errors

* Increased cov for genesis

* Added comment for maxRetrieve param in keepers

* Comment on DelegationWithoutDec

* Bech32Validator Keepers

* Changed Bech validator

* Updated remaining tests and bech32 validator

* Addressed most of Rigel's comments

* Updated tests and types

* Make codec to be unexported from keeper

* Moved logic to query_utils and updated tests

* Fix linter err and PENDING

* Fix err

* Fix err

* Fixed tests

* Update PENDING description

* Update UpdateBondedValidatorsFull

* Update iterator

* defer iterator.Close()

* delete comment

* Address some of Aleks comments, need to fix tests

* export querier

* Fixed tests

* Address Rigel's comments

* More tests

* return error for GetDelegatorValidator

* Fixed conflicts

* Fix linter warnings

* Address @rigelrozanski comments

* Delete comments

* wire ––> codec
2018-09-13 17:23:44 -04:00

35 lines
848 B
Go

package rest
import (
"fmt"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/x/stake/tags"
rpcclient "github.com/tendermint/tendermint/rpc/client"
)
// contains checks if the a given query contains one of the tx types
func contains(stringSlice []string, txType string) bool {
for _, word := range stringSlice {
if word == txType {
return true
}
}
return false
}
// queries staking txs
func queryTxs(node rpcclient.Client, cdc *codec.Codec, tag string, delegatorAddr string) ([]tx.Info, error) {
page := 0
perPage := 100
prove := false
query := fmt.Sprintf("%s='%s' AND %s='%s'", tags.Action, tag, tags.Delegator, delegatorAddr)
res, err := node.TxSearch(query, prove, page, perPage)
if err != nil {
return nil, err
}
return tx.FormatTxResults(cdc, res.Txs)
}