Skip to content

Commit 7afddfa

Browse files
committed
importmulti: Don't add internal addresses to address book
1 parent 6b8d0a2 commit 7afddfa

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/wallet/rpcdump.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -994,8 +994,9 @@ static UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, con
994994
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding scriptPubKey script to wallet");
995995
}
996996

997-
// add to address book or update label
998-
if (IsValidDestination(scriptpubkey_dest)) {
997+
// if not internal add to address book or update label
998+
if (!internal) {
999+
assert(IsValidDestination(scriptpubkey_dest));
9991000
pwallet->SetAddressBook(scriptpubkey_dest, label, "receive");
10001001
}
10011002

@@ -1087,7 +1088,7 @@ UniValue importmulti(const JSONRPCRequest& mainRequest)
10871088
" \"witnessscript\": \"<script>\" , (string, optional) Allowed only if the scriptPubKey is a P2SH-P2WSH or P2WSH address/scriptPubKey\n"
10881089
" \"pubkeys\": [\"<pubKey>\", ... ] , (array, optional) Array of strings giving pubkeys that must occur in the output or redeemscript\n"
10891090
" \"keys\": [\"<key>\", ... ] , (array, optional) Array of strings giving private keys whose corresponding public keys must occur in the output or redeemscript\n"
1090-
" \"internal\": <true> , (boolean, optional, default: false) Stating whether matching outputs should be treated as not incoming payments\n"
1091+
" \"internal\": <true> , (boolean, optional, default: false) Stating whether matching outputs should be treated as not incoming payments aka change\n"
10911092
" \"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"
10921093
" \"label\": <label> , (string, optional, default: '') Label to assign to the address, only allowed with internal=false\n"
10931094
" }\n"

test/functional/wallet_importmulti.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def run_test (self):
5454

5555
# RPC importmulti -----------------------------------------------
5656

57-
# Bitcoin Address
57+
# Bitcoin Address (implicit non-internal)
5858
self.log.info("Should import an address")
5959
address = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
6060
result = self.nodes[1].importmulti([{
@@ -68,6 +68,7 @@ def run_test (self):
6868
assert_equal(address_assert['iswatchonly'], True)
6969
assert_equal(address_assert['ismine'], False)
7070
assert_equal(address_assert['timestamp'], timestamp)
71+
assert_equal(address_assert['ischange'], False)
7172
watchonly_address = address['address']
7273
watchonly_timestamp = timestamp
7374

@@ -95,6 +96,7 @@ def run_test (self):
9596
assert_equal(address_assert['iswatchonly'], True)
9697
assert_equal(address_assert['ismine'], False)
9798
assert_equal(address_assert['timestamp'], timestamp)
99+
assert_equal(address_assert['ischange'], True)
98100

99101
# ScriptPubKey + internal + label
100102
self.log.info("Should not allow a label to be specified when internal is true")
@@ -126,15 +128,16 @@ def run_test (self):
126128
assert_equal('timestamp' in address_assert, False)
127129

128130

129-
# Address + Public key + !Internal
131+
# Address + Public key + !Internal(explicit)
130132
self.log.info("Should import an address with public key")
131133
address = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
132134
result = self.nodes[1].importmulti([{
133135
"scriptPubKey": {
134136
"address": address['address']
135137
},
136138
"timestamp": "now",
137-
"pubkeys": [ address['pubkey'] ]
139+
"pubkeys": [ address['pubkey'] ],
140+
"internal": False
138141
}])
139142
assert_equal(result[0]['success'], True)
140143
address_assert = self.nodes[1].getaddressinfo(address['address'])

0 commit comments

Comments
 (0)