Merge #14679: importmulti: Don't add internal addresses to address book (#4402)

* importmulti: Don't add internal addresses to address book

* Update test/functional/wallet_importmulti.py

Co-authored-by: PastaPastaPasta <6443210+PastaPastaPasta@users.noreply.github.com>

* Update test/functional/wallet_importmulti.py

Co-authored-by: PastaPastaPasta <6443210+PastaPastaPasta@users.noreply.github.com>

* Updated rpcdump

* Update test/functional/wallet_importmulti.py

* fix whitespace in rpcdump.cpp to be inline with upstream

Co-authored-by: PastaPastaPasta <6443210+PastaPastaPasta@users.noreply.github.com>
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
This commit is contained in:
Odysseas Gabrielides 2021-09-11 22:56:58 +03:00 committed by GitHub
parent f8ecee7e6f
commit 12218473f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View File

@ -1283,8 +1283,9 @@ static UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, con
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding address to wallet"); throw JSONRPCError(RPC_WALLET_ERROR, "Error adding address to wallet");
} }
// add to address book or update label // if not internal add to address book or update label
if (IsValidDestination(dest)) { if (!internal) {
assert(IsValidDestination(dest));
pwallet->SetAddressBook(dest, label, "receive"); pwallet->SetAddressBook(dest, label, "receive");
} }
@ -1349,7 +1350,7 @@ UniValue importmulti(const JSONRPCRequest& mainRequest)
" \"redeemscript\": \"<script>\" , (string, optional) Allowed only if the scriptPubKey is a P2SH address or a P2SH scriptPubKey\n" " \"redeemscript\": \"<script>\" , (string, optional) Allowed only if the scriptPubKey is a P2SH address or a P2SH scriptPubKey\n"
" \"pubkeys\": [\"<pubKey>\", ... ] , (array, optional) Array of strings giving pubkeys that must occur in the output or redeemscript\n" " \"pubkeys\": [\"<pubKey>\", ... ] , (array, optional) Array of strings giving pubkeys that must occur in the output or redeemscript\n"
" \"keys\": [\"<key>\", ... ] , (array, optional) Array of strings giving private keys whose corresponding public keys must occur in the output or redeemscript\n" " \"keys\": [\"<key>\", ... ] , (array, optional) Array of strings giving private keys whose corresponding public keys must occur in the output or redeemscript\n"
" \"internal\": <true> , (boolean, optional, default: false) Stating whether matching outputs should be treated as not incoming payments\n" " \"internal\": <true> , (boolean, optional, default: false) Stating whether matching outputs should be treated as not incoming payments aka change\n"
" \"watchonly\": <true> , (boolean, optional, default: false) Stating whether matching outputs should be considered watched even when they're not spendable, only allowed if keys are empty\n" " \"watchonly\": <true> , (boolean, optional, default: false) Stating whether matching outputs should be considered watched even when they're not spendable, only allowed if keys are empty\n"
" \"label\": <label> , (string, optional, default: '') Label to assign to the address (aka account name, for now), only allowed with internal=false\n" " \"label\": <label> , (string, optional, default: '') Label to assign to the address (aka account name, for now), only allowed with internal=false\n"
" }\n" " }\n"

View File

@ -43,7 +43,7 @@ class ImportMultiTest(BitcoinTestFramework):
# RPC importmulti ----------------------------------------------- # RPC importmulti -----------------------------------------------
# Bitcoin Address # Bitcoin Address (implicit non-internal)
self.log.info("Should import an address") self.log.info("Should import an address")
address = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress()) address = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
result = self.nodes[1].importmulti([{ result = self.nodes[1].importmulti([{
@ -57,6 +57,7 @@ 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)
assert_equal(address_assert['timestamp'], timestamp) assert_equal(address_assert['timestamp'], timestamp)
assert_equal(address_assert['ischange'], False)
watchonly_address = address['address'] watchonly_address = address['address']
watchonly_timestamp = timestamp watchonly_timestamp = timestamp
@ -84,6 +85,7 @@ 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)
assert_equal(address_assert['timestamp'], timestamp) assert_equal(address_assert['timestamp'], timestamp)
assert_equal(address_assert['ischange'], True)
# Nonstandard scriptPubKey + !internal # Nonstandard scriptPubKey + !internal
self.log.info("Should not import a nonstandard scriptPubKey without internal flag") self.log.info("Should not import a nonstandard scriptPubKey without internal flag")
@ -102,7 +104,7 @@ class ImportMultiTest(BitcoinTestFramework):
assert_equal('timestamp' in address_assert, False) assert_equal('timestamp' in address_assert, False)
# Address + Public key + !Internal # Address + Public key + !Internal(explicit)
self.log.info("Should import an address with public key") self.log.info("Should import an address with public key")
address = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress()) address = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
result = self.nodes[1].importmulti([{ result = self.nodes[1].importmulti([{
@ -110,7 +112,8 @@ class ImportMultiTest(BitcoinTestFramework):
"address": address['address'] "address": address['address']
}, },
"timestamp": "now", "timestamp": "now",
"pubkeys": [ address['pubkey'] ] "pubkeys": [ address['pubkey'] ],
"internal": False
}]) }])
assert_equal(result[0]['success'], True) assert_equal(result[0]['success'], True)
address_assert = self.nodes[1].getaddressinfo(address['address']) address_assert = self.nodes[1].getaddressinfo(address['address'])