[NOD-462] Add error message when address is invalid for UTXO API request (#492)

* [NOD-462] Add error message when address is invalid

* [NOD-462] Fix error message

* [NOD-462] Remove function name from error message
This commit is contained in:
Dan Aharoni 2019-11-26 13:50:36 +02:00 committed by Svarog
parent 6e4b18a498
commit 9a54b286c9

View File

@ -5,6 +5,7 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"github.com/daglabs/btcd/util"
"net/http"
"github.com/daglabs/btcd/apiserver/apimodels"
@ -147,6 +148,13 @@ func areTxsInBlock(blockID uint64, txIDs []uint64) (map[uint64]bool, error) {
// GetUTXOsByAddressHandler searches for all UTXOs that belong to a certain address.
func GetUTXOsByAddressHandler(address string) (interface{}, error) {
_, err := util.DecodeAddress(address, config.ActiveConfig().ActiveNetParams.Prefix)
if err != nil {
return nil, httpserverutils.NewHandlerErrorWithCustomClientMessage(http.StatusUnprocessableEntity,
errors.Wrap(err, "error decoding address"),
"The given address is not a well-formatted P2PKH or P2SH address.")
}
db, err := database.DB()
if err != nil {
return nil, err