Skip to content

Commit

Permalink
Merge PR #4637: Update Search Txs by Events APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbez authored Jun 28, 2019
1 parent b2f8c58 commit 3a39e9d
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 31 deletions.
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.
2 changes: 1 addition & 1 deletion client/lcd/statik/statik.go

Large diffs are not rendered by default.

16 changes: 7 additions & 9 deletions client/lcd/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -225,21 +225,19 @@ paths:
tags:
- Transactions
summary: Search transactions
description: Search transactions by tag(s).
description: Search transactions by events.
produces:
- application/json
parameters:
- in: query
name: action
name: message.action
type: string
description: "transaction tags such as 'action=send' which results in the following endpoint: 'GET /txs?action=send'"
required: true
description: "transaction events such as 'message.action=send' which results in the following endpoint: 'GET /txs?message.action=send'"
x-example: "send"
- in: query
name: sender
name: message.sender
type: string
description: "transaction tags with sender: 'GET /txs?action=send&sender=cosmos16xyempempp92x9hyzz9wrgf94r6j9h5f06pxxv'"
required: true
description: "transaction tags with sender: 'GET /txs?message.action=send&message.sender=cosmos16xyempempp92x9hyzz9wrgf94r6j9h5f06pxxv'"
x-example: "cosmos16xyempempp92x9hyzz9wrgf94r6j9h5f06pxxv"
- in: query
name: page
Expand All @@ -253,11 +251,11 @@ paths:
x-example: 1
responses:
200:
description: All txs matching the provided tags
description: All txs matching the provided events
schema:
$ref: "#/definitions/PaginatedQueryTxs"
400:
description: Invalid search tags
description: Invalid search events
500:
description: Internal Server Error
post:
Expand Down
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

0 comments on commit 3a39e9d

Please sign in to comment.