2018-08-08 03:38:39 -07:00
|
|
|
package rest
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2018-09-25 14:43:26 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/client/context"
|
2018-08-08 03:38:39 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/client/tx"
|
2018-09-13 11:17:32 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
2018-08-08 03:38:39 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/stake/tags"
|
2018-09-25 14:43:26 -07:00
|
|
|
|
2018-08-08 03:38:39 -07:00
|
|
|
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
|
2018-09-14 11:41:21 -07:00
|
|
|
func queryTxs(node rpcclient.Client, cliCtx context.CLIContext, cdc *codec.Codec, tag string, delegatorAddr string) ([]tx.Info, error) {
|
2018-08-08 03:38:39 -07:00
|
|
|
page := 0
|
|
|
|
perPage := 100
|
2018-09-14 11:41:21 -07:00
|
|
|
prove := !cliCtx.TrustNode
|
2018-08-08 03:38:39 -07:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2018-09-14 11:41:21 -07:00
|
|
|
if prove {
|
|
|
|
for _, txData := range res.Txs {
|
|
|
|
err := tx.ValidateTxResult(cliCtx, txData)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-17 07:13:11 -07:00
|
|
|
return tx.FormatTxResults(cdc, res.Txs)
|
2018-08-08 03:38:39 -07:00
|
|
|
}
|