Merge PR #4637: Update Search Txs by Events APIs
This commit is contained in:
parent
b2f8c58ec4
commit
3a39e9d558
|
@ -0,0 +1,2 @@
|
|||
#4633 Update old Tx search by tags APIs to use new Events
|
||||
nomenclature.
|
File diff suppressed because one or more lines are too long
|
@ -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
|
||||
|
@ -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:
|
||||
|
|
|
@ -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",
|
||||
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue