Skip to content

Commit 3cf9917

Browse files
committed
Add test to check new importmulti "now" value
Easiest way to test this was to expose the timestamp via the validateaddress RPC (which was already looking up and returning key metadata).
1 parent 442887f commit 3cf9917

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

qa/rpc-tests/importmulti.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ def run_test (self):
139139
# Address + Private key + !watchonly
140140
print("Should import an address with private key")
141141
address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
142+
timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['time']
142143
result = self.nodes[1].importmulti([{
143144
"scriptPubKey": {
144145
"address": address['address']
@@ -150,6 +151,7 @@ def run_test (self):
150151
address_assert = self.nodes[1].validateaddress(address['address'])
151152
assert_equal(address_assert['iswatchonly'], False)
152153
assert_equal(address_assert['ismine'], True)
154+
assert_equal(address_assert['timestamp'], timestamp)
153155

154156
# Address + Private key + watchonly
155157
print("Should not import an address with private key and with watchonly")

src/rpc/misc.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ UniValue validateaddress(const JSONRPCRequest& request)
167167
" \"pubkey\" : \"publickeyhex\", (string) The hex value of the raw public key\n"
168168
" \"iscompressed\" : true|false, (boolean) If the address is compressed\n"
169169
" \"account\" : \"account\" (string) DEPRECATED. The account associated with the address, \"\" is the default account\n"
170+
" \"timestamp\" : timestamp, (number, optional) The creation time of the key if available in seconds since epoch (Jan 1 1970 GMT)\n"
170171
" \"hdkeypath\" : \"keypath\" (string, optional) The HD keypath if the key is HD and available\n"
171172
" \"hdmasterkeyid\" : \"<hash160>\" (string, optional) The Hash160 of the HD master pubkey\n"
172173
"}\n"
@@ -204,10 +205,16 @@ UniValue validateaddress(const JSONRPCRequest& request)
204205
if (pwalletMain && pwalletMain->mapAddressBook.count(dest))
205206
ret.push_back(Pair("account", pwalletMain->mapAddressBook[dest].name));
206207
CKeyID keyID;
207-
if (pwalletMain && address.GetKeyID(keyID) && pwalletMain->mapKeyMetadata.count(keyID) && !pwalletMain->mapKeyMetadata[keyID].hdKeypath.empty())
208-
{
209-
ret.push_back(Pair("hdkeypath", pwalletMain->mapKeyMetadata[keyID].hdKeypath));
210-
ret.push_back(Pair("hdmasterkeyid", pwalletMain->mapKeyMetadata[keyID].hdMasterKeyID.GetHex()));
208+
if (pwalletMain) {
209+
const auto& meta = pwalletMain->mapKeyMetadata;
210+
auto it = address.GetKeyID(keyID) ? meta.find(keyID) : meta.end();
211+
if (it != meta.end()) {
212+
ret.push_back(Pair("timestamp", it->second.nCreateTime));
213+
if (!it->second.hdKeypath.empty()) {
214+
ret.push_back(Pair("hdkeypath", it->second.hdKeypath));
215+
ret.push_back(Pair("hdmasterkeyid", it->second.hdMasterKeyID.GetHex()));
216+
}
217+
}
211218
}
212219
#endif
213220
}

0 commit comments

Comments
 (0)