Skip to content

Commit f617e05

Browse files
committed
Merge #14679: importmulti: Don't add internal addresses to address book
7afddfa importmulti: Don't add internal addresses to address book (Gregory Sanders) Pull request description: Currently anything imported with `internal` will not be treated as change since checking the address book is a primary test of this. Added basic tests of all combinations of arguments and change identification. Resolves bitcoin/bitcoin#14662 Tree-SHA512: a1f08dc624a3fadee93cc5392d50c4796b0c5eedf38e295382f71570f2066d9e978ed6e3962084b902989863fe1273a8642d8fdb094a266d69de10622a4176b0
2 parents c651265 + 7afddfa commit f617e05

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
@@ -1009,8 +1009,9 @@ static UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, con
10091009
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding scriptPubKey script to wallet");
10101010
}
10111011

1012-
// add to address book or update label
1013-
if (IsValidDestination(scriptpubkey_dest)) {
1012+
// if not internal add to address book or update label
1013+
if (!internal) {
1014+
assert(IsValidDestination(scriptpubkey_dest));
10141015
pwallet->SetAddressBook(scriptpubkey_dest, label, "receive");
10151016
}
10161017

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