Skip to content

Commit 78941da

Browse files
committed
Optionally allow ImportScripts to set script creation timestamp
Behavior changes: * scripts imported in importmulti that are not explicilty scriptPubKeys will have timestamps set for them
1 parent 94bf156 commit 78941da

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

src/wallet/rpcdump.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ UniValue importprivkey(const JSONRPCRequest& request)
194194

195195
// Add the wpkh script for this key if possible
196196
if (pubkey.IsCompressed()) {
197-
pwallet->ImportScripts({GetScriptForDestination(WitnessV0KeyHash(vchAddress))});
197+
pwallet->ImportScripts({GetScriptForDestination(WitnessV0KeyHash(vchAddress))}, 0 /* timestamp */);
198198
}
199199
}
200200
}
@@ -316,7 +316,7 @@ UniValue importaddress(const JSONRPCRequest& request)
316316
CScript redeem_script(data.begin(), data.end());
317317

318318
std::set<CScript> scripts = {redeem_script};
319-
pwallet->ImportScripts(scripts);
319+
pwallet->ImportScripts(scripts, 0 /* timestamp */);
320320

321321
if (fP2SH) {
322322
scripts.insert(GetScriptForDestination(ScriptHash(CScriptID(redeem_script))));
@@ -1251,7 +1251,7 @@ static UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, con
12511251

12521252
// All good, time to import
12531253
pwallet->MarkDirty();
1254-
if (!pwallet->ImportScripts(import_data.import_scripts)) {
1254+
if (!pwallet->ImportScripts(import_data.import_scripts, timestamp)) {
12551255
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding script to wallet");
12561256
}
12571257
if (!pwallet->ImportPrivKeys(privkey_map, timestamp)) {

src/wallet/wallet.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1661,7 +1661,7 @@ bool CWallet::DummySignTx(CMutableTransaction &txNew, const std::vector<CTxOut>
16611661
return true;
16621662
}
16631663

1664-
bool CWallet::ImportScripts(const std::set<CScript> scripts)
1664+
bool CWallet::ImportScripts(const std::set<CScript> scripts, int64_t timestamp)
16651665
{
16661666
WalletBatch batch(*database);
16671667
for (const auto& entry : scripts) {
@@ -1673,7 +1673,15 @@ bool CWallet::ImportScripts(const std::set<CScript> scripts)
16731673
if (!AddCScriptWithDB(batch, entry)) {
16741674
return false;
16751675
}
1676+
1677+
if (timestamp > 0) {
1678+
m_script_metadata[CScriptID(entry)].nCreateTime = timestamp;
1679+
}
16761680
}
1681+
if (timestamp > 0) {
1682+
UpdateTimeFirstKey(timestamp);
1683+
}
1684+
16771685
return true;
16781686
}
16791687

src/wallet/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ class CWallet final : public CCryptoKeyStore, private interfaces::Chain::Notific
10921092
bool DummySignTx(CMutableTransaction &txNew, const std::vector<CTxOut> &txouts, bool use_max_sig = false) const;
10931093
bool DummySignInput(CTxIn &tx_in, const CTxOut &txout, bool use_max_sig = false) const;
10941094

1095-
bool ImportScripts(const std::set<CScript> scripts) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
1095+
bool ImportScripts(const std::set<CScript> scripts, int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
10961096
bool ImportPrivKeys(const std::map<CKeyID, CKey>& privkey_map, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
10971097
bool ImportPubKeys(const std::vector<CKeyID>& ordered_pubkeys, const std::map<CKeyID, CPubKey>& pubkey_map, const std::map<CKeyID, std::pair<CPubKey, KeyOriginInfo>>& key_origins, const bool add_keypool, const bool internal, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
10981098
bool ImportScriptPubKeys(const std::string& label, const std::set<CScript>& script_pub_keys, const bool have_solving_data, const bool apply_label, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);

0 commit comments

Comments
 (0)