From 9a54b286c9c0a908fbf87a84208018ea5a74ed51 Mon Sep 17 00:00:00 2001 From: Dan Aharoni Date: Tue, 26 Nov 2019 13:50:36 +0200 Subject: [PATCH] [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 --- apiserver/controllers/transaction.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/apiserver/controllers/transaction.go b/apiserver/controllers/transaction.go index 876895fc0..e4b9f2c8b 100644 --- a/apiserver/controllers/transaction.go +++ b/apiserver/controllers/transaction.go @@ -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