diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -344,7 +344,7 @@ CScript redeem_script(data.begin(), data.end()); std::set scripts = {redeem_script}; - pwallet->ImportScripts(scripts); + pwallet->ImportScripts(scripts, 0 /* timestamp */); if (fP2SH) { scripts.insert(GetScriptForDestination( @@ -1487,7 +1487,7 @@ // All good, time to import pwallet->MarkDirty(); - if (!pwallet->ImportScripts(import_data.import_scripts)) { + if (!pwallet->ImportScripts(import_data.import_scripts, timestamp)) { throw JSONRPCError(RPC_WALLET_ERROR, "Error adding script to wallet"); } diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1267,7 +1267,7 @@ bool DummySignInput(CTxIn &tx_in, const CTxOut &txout, bool use_max_sig = false) const; - bool ImportScripts(const std::set scripts) + bool ImportScripts(const std::set scripts, int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); bool ImportPrivKeys(const std::map &privkey_map, const int64_t timestamp) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1828,7 +1828,8 @@ return true; } -bool CWallet::ImportScripts(const std::set scripts) { +bool CWallet::ImportScripts(const std::set scripts, + int64_t timestamp) { WalletBatch batch(*database); for (const auto &entry : scripts) { CScriptID id(entry); @@ -1840,7 +1841,15 @@ if (!AddCScriptWithDB(batch, entry)) { return false; } + + if (timestamp > 0) { + m_script_metadata[CScriptID(entry)].nCreateTime = timestamp; + } } + if (timestamp > 0) { + UpdateTimeFirstKey(timestamp); + } + return true; }