Return error when importmulti called with invalid address.
Lack of error checking noticed by Alex Morcos <morcos@chaincode.com>
This commit is contained in:
parent
d978c41e1e
commit
9acf25cc01
2 changed files with 13 additions and 0 deletions
|
@ -59,6 +59,16 @@ class ImportMultiTest (BitcoinTestFramework):
|
||||||
assert_equal(address_assert['iswatchonly'], True)
|
assert_equal(address_assert['iswatchonly'], True)
|
||||||
assert_equal(address_assert['ismine'], False)
|
assert_equal(address_assert['ismine'], False)
|
||||||
|
|
||||||
|
print("Should not import an invalid address")
|
||||||
|
result = self.nodes[1].importmulti([{
|
||||||
|
"scriptPubKey": {
|
||||||
|
"address": "not valid address",
|
||||||
|
},
|
||||||
|
"timestamp": "now",
|
||||||
|
}])
|
||||||
|
assert_equal(result[0]['success'], False)
|
||||||
|
assert_equal(result[0]['error']['code'], -5)
|
||||||
|
assert_equal(result[0]['error']['message'], 'Invalid address')
|
||||||
|
|
||||||
# ScriptPubKey + internal
|
# ScriptPubKey + internal
|
||||||
print("Should import a scriptPubKey with internal flag")
|
print("Should import a scriptPubKey with internal flag")
|
||||||
|
|
|
@ -671,6 +671,9 @@ UniValue processImport(const UniValue& data) {
|
||||||
|
|
||||||
if (!isScript) {
|
if (!isScript) {
|
||||||
address = CBitcoinAddress(output);
|
address = CBitcoinAddress(output);
|
||||||
|
if (!address.IsValid()) {
|
||||||
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
|
||||||
|
}
|
||||||
script = GetScriptForDestination(address.Get());
|
script = GetScriptForDestination(address.Get());
|
||||||
} else {
|
} else {
|
||||||
if (!IsHex(output)) {
|
if (!IsHex(output)) {
|
||||||
|
|
Loading…
Reference in a new issue