From 279ab5e62f4e4344061d54b341d8d36af874fb88 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Sat, 5 Mar 2011 15:32:32 +0100 Subject: [PATCH 1/2] setaccount should return if an invalid address is provided. This prevents setaccount from creating new accounts which do not have any addresses. --- rpc.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/rpc.cpp b/rpc.cpp index 1c6f228e5b..e01ea0e3b6 100644 --- a/rpc.cpp +++ b/rpc.cpp @@ -381,6 +381,12 @@ Value setaccount(const Array& params, bool fHelp) "Sets the account associated with the given address."); string strAddress = params[0].get_str(); + uint160 hash160; + bool isValid = AddressToHash160(strAddress, hash160); + if (!isValid) + throw runtime_error("provided address is not valid"); + + string strAccount; if (params.size() > 1) strAccount = AccountFromValue(params[1]); From c1f74f152b278ca11390519fded87c09e7f05437 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Sat, 5 Mar 2011 16:45:56 +0100 Subject: [PATCH 2/2] throw JSONRPCError(-5, "Invalid bitcoin address") instead. --- rpc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpc.cpp b/rpc.cpp index e01ea0e3b6..dd94acc050 100644 --- a/rpc.cpp +++ b/rpc.cpp @@ -384,7 +384,7 @@ Value setaccount(const Array& params, bool fHelp) uint160 hash160; bool isValid = AddressToHash160(strAddress, hash160); if (!isValid) - throw runtime_error("provided address is not valid"); + throw JSONRPCError(-5, "Invalid bitcoin address"); string strAccount;