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

Update Search Txs by Events APIs #4637

Merged
merged 5 commits into from
Jun 28, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions .pending/breaking/sdk/4633-Update-old-Tx-s
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#4633 Update old Tx search by tags APIs to use new Events
nomenclature.
6 changes: 3 additions & 3 deletions x/auth/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ func GetAccountCmd(cdc *codec.Codec) *cobra.Command {
return flags.GetCommands(cmd)[0]
}

// QueryTxsByTagsCmd returns a command to search through tagged transactions.
func QueryTxsByTagsCmd(cdc *codec.Codec) *cobra.Command {
// QueryTxsByEventsCmd returns a command to search through transactions by events.
func QueryTxsByEventsCmd(cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "txs",
Short: "Query for paginated transactions that match a set of tags",
Expand Down Expand Up @@ -116,7 +116,7 @@ $ <appcli> query txs --tags '<tag1>:<value1>&<tag2>:<value2>' --page 1 --limit 3
limit := viper.GetInt(flagLimit)

cliCtx := context.NewCLIContext().WithCodec(cdc)
txs, err := utils.QueryTxsByTags(cliCtx, tmTags, page, limit)
txs, err := utils.QueryTxsByEvents(cliCtx, tmTags, page, limit)
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions x/auth/client/rest/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ func QueryAccountRequestHandlerFn(storeName string, cliCtx context.CLIContext) h
}
}

// QueryTxsByTagsRequestHandlerFn implements a REST handler that searches for
// transactions by tags.
func QueryTxsByTagsRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
// QueryTxsByEventsRequestHandlerFn implements a REST handler that searches for
// transactions by events.
func QueryTxsByEventsRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var (
tags []string
Expand Down Expand Up @@ -90,7 +90,7 @@ func QueryTxsByTagsRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc
return
}

searchResult, err := utils.QueryTxsByTags(cliCtx, tags, page, limit)
searchResult, err := utils.QueryTxsByEvents(cliCtx, tags, page, limit)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
Expand Down
2 changes: 1 addition & 1 deletion x/auth/client/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, storeName string)
// RegisterTxRoutes registers all transaction routes on the provided router.
func RegisterTxRoutes(cliCtx context.CLIContext, r *mux.Router) {
r.HandleFunc("/txs/{hash}", QueryTxRequestHandlerFn(cliCtx)).Methods("GET")
r.HandleFunc("/txs", QueryTxsByTagsRequestHandlerFn(cliCtx)).Methods("GET")
r.HandleFunc("/txs", QueryTxsByEventsRequestHandlerFn(cliCtx)).Methods("GET")
r.HandleFunc("/txs", BroadcastTxRequest(cliCtx)).Methods("POST")
r.HandleFunc("/txs/encode", EncodeTxRequestHandlerFn(cliCtx)).Methods("POST")
}
16 changes: 9 additions & 7 deletions x/auth/client/utils/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth/types"
)

// QueryTxsByTags performs a search for transactions for a given set of tags via
// Tendermint RPC. It returns a slice of Info object containing txs and metadata.
// An error is returned if the query fails.
func QueryTxsByTags(cliCtx context.CLIContext, tags []string, page, limit int) (*sdk.SearchTxsResult, error) {
if len(tags) == 0 {
return nil, errors.New("must declare at least one tag to search")
// QueryTxsByEvents performs a search for transactions for a given set of events
// via the Tendermint RPC. An event takes the form of:
// "{eventAttribute}.{attributeKey} = '{attributeValue}'". Each event is
// concatenated with an 'AND' operand. It returns a slice of Info object
// containing txs and metadata. An error is returned if the query fails.
func QueryTxsByEvents(cliCtx context.CLIContext, events []string, page, limit int) (*sdk.SearchTxsResult, error) {
if len(events) == 0 {
return nil, errors.New("must declare at least one event to search")
}

if page <= 0 {
Expand All @@ -31,7 +33,7 @@ func QueryTxsByTags(cliCtx context.CLIContext, tags []string, page, limit int) (
}

// XXX: implement ANY
query := strings.Join(tags, " AND ")
query := strings.Join(events, " AND ")

node, err := cliCtx.GetNode()
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions x/gov/client/utils/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func QueryDepositsByTxQuery(cliCtx context.CLIContext, params types.QueryProposa

// NOTE: SearchTxs is used to facilitate the txs query which does not currently
// support configurable pagination.
searchResult, err := utils.QueryTxsByTags(cliCtx, events, defaultPage, defaultLimit)
searchResult, err := utils.QueryTxsByEvents(cliCtx, events, defaultPage, defaultLimit)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -86,7 +86,7 @@ func QueryVotesByTxQuery(cliCtx context.CLIContext, params types.QueryProposalPa

// NOTE: SearchTxs is used to facilitate the txs query which does not currently
// support configurable pagination.
searchResult, err := utils.QueryTxsByTags(cliCtx, events, defaultPage, defaultLimit)
searchResult, err := utils.QueryTxsByEvents(cliCtx, events, defaultPage, defaultLimit)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -124,7 +124,7 @@ func QueryVoteByTxQuery(cliCtx context.CLIContext, params types.QueryVoteParams)

// NOTE: SearchTxs is used to facilitate the txs query which does not currently
// support configurable pagination.
searchResult, err := utils.QueryTxsByTags(cliCtx, events, defaultPage, defaultLimit)
searchResult, err := utils.QueryTxsByEvents(cliCtx, events, defaultPage, defaultLimit)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -164,7 +164,7 @@ func QueryDepositByTxQuery(cliCtx context.CLIContext, params types.QueryDepositP

// NOTE: SearchTxs is used to facilitate the txs query which does not currently
// support configurable pagination.
searchResult, err := utils.QueryTxsByTags(cliCtx, events, defaultPage, defaultLimit)
searchResult, err := utils.QueryTxsByEvents(cliCtx, events, defaultPage, defaultLimit)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -203,7 +203,7 @@ func QueryProposerByTxQuery(cliCtx context.CLIContext, proposalID uint64) (Propo

// NOTE: SearchTxs is used to facilitate the txs query which does not currently
// support configurable pagination.
searchResult, err := utils.QueryTxsByTags(cliCtx, events, defaultPage, defaultLimit)
searchResult, err := utils.QueryTxsByEvents(cliCtx, events, defaultPage, defaultLimit)
if err != nil {
return Proposer{}, err
}
Expand Down
2 changes: 1 addition & 1 deletion x/staking/client/rest/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func queryTxs(cliCtx context.CLIContext, action string, delegatorAddr string) (*
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeySender, delegatorAddr),
}

return utils.QueryTxsByTags(cliCtx, events, page, limit)
return utils.QueryTxsByEvents(cliCtx, events, page, limit)
}

func queryBonds(cliCtx context.CLIContext, endpoint string) http.HandlerFunc {
Expand Down