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

tx search doesn't support multiple tags #2819

Closed
4 tasks
fedekunze opened this issue Nov 14, 2018 · 1 comment
Closed
4 tasks

tx search doesn't support multiple tags #2819

fedekunze opened this issue Nov 14, 2018 · 1 comment
Assignees
Labels

Comments

@fedekunze
Copy link
Collaborator

fedekunze commented Nov 14, 2018

Summary of Bug

/txs only supports a single query using ?tag=<key='value'>, same happens with the CLI cmd

Steps to Reproduce

SearchTxRequestHandlerFn only supports a single tag to query:

func SearchTxRequestHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
tag := r.FormValue("tag")
if tag == "" {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte("You need to provide at least a tag as a key=value pair to search for. Postfix the key with _bech32 to search bech32-encoded addresses or public keys"))
return
}
keyValue := strings.Split(tag, "=")
key := keyValue[0]
value, err := url.QueryUnescape(keyValue[1])
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, sdk.AppendMsgToErr("could not decode address", err.Error()))
return
}
if strings.HasSuffix(key, "_bech32") {
bech32address := strings.Trim(value, "'")
prefix := strings.Split(bech32address, "1")[0]
bz, err := sdk.GetFromBech32(bech32address, prefix)
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}
tag = strings.TrimRight(key, "_bech32") + "='" + sdk.AccAddress(bz).String() + "'"
}
txs, err := searchTxs(cliCtx, cdc, []string{tag})
if err != nil {
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
if len(txs) == 0 {
w.Write([]byte("[]"))
return
}
utils.PostProcessResponse(w, cdc, txs, cliCtx.Indent)
}
}

This is because it uses r.FormValue, which only returns the first value:

FormValue returns the first value for the named component of the query. POST and PUT body parameters take precedence over URL query string values. FormValue calls ParseMultipartForm and ParseForm if necessary and ignores any errors returned by these functions. If key is not present, FormValue returns the empty string. To access multiple values of the same key, call ParseForm and then inspect Request.Form directly.

Source: godoc

cc: @jackzampolin @rigelrozanski @cwgoes @alexanderbez @faboweb


For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
@fedekunze
Copy link
Collaborator Author

I'll try to get this for GoS

@fedekunze fedekunze mentioned this issue Nov 16, 2018
6 tasks
@fedekunze fedekunze changed the title /txs? doesn't support multiple tags tx search doesn't support multiple tags Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant