aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Chow <achow101-github@achow101.com>2019-06-27 21:17:42 -0400
committerAndrew Chow <achow101-github@achow101.com>2019-07-24 11:42:46 -0400
commit78941da5baf6244c7c54e86cf8ce3e09ce60c239 (patch)
treefc07b9173f4adcb604fe2242ed4b2b579c0b1c2e /src
parent94bf156f391759420465b2ff8c44f5f150246c7f (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/wallet/rpcdump.cpp6
-rw-r--r--src/wallet/wallet.cpp10
-rw-r--r--src/wallet/wallet.h2
3 files changed, 13 insertions, 5 deletions
diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp
index 964676e6b1..480832c627 100644
--- a/src/wallet/rpcdump.cpp
+++ b/src/wallet/rpcdump.cpp
@@ -194,7 +194,7 @@ UniValue importprivkey(const JSONRPCRequest& request)
// Add the wpkh script for this key if possible
if (pubkey.IsCompressed()) {
- pwallet->ImportScripts({GetScriptForDestination(WitnessV0KeyHash(vchAddress))});
+ pwallet->ImportScripts({GetScriptForDestination(WitnessV0KeyHash(vchAddress))}, 0 /* timestamp */);
}
}
}
@@ -316,7 +316,7 @@ UniValue importaddress(const JSONRPCRequest& request)
CScript redeem_script(data.begin(), data.end());
std::set<CScript> scripts = {redeem_script};
- pwallet->ImportScripts(scripts);
+ pwallet->ImportScripts(scripts, 0 /* timestamp */);
if (fP2SH) {
scripts.insert(GetScriptForDestination(ScriptHash(CScriptID(redeem_script))));
@@ -1251,7 +1251,7 @@ static UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, con
// 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");
}
if (!pwallet->ImportPrivKeys(privkey_map, timestamp)) {
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index 45cd2d0e07..6f080f4b8f 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -1661,7 +1661,7 @@ bool CWallet::DummySignTx(CMutableTransaction &txNew, const std::vector<CTxOut>
return true;
}
-bool CWallet::ImportScripts(const std::set<CScript> scripts)
+bool CWallet::ImportScripts(const std::set<CScript> scripts, int64_t timestamp)
{
WalletBatch batch(*database);
for (const auto& entry : scripts) {
@@ -1673,7 +1673,15 @@ bool CWallet::ImportScripts(const std::set<CScript> scripts)
if (!AddCScriptWithDB(batch, entry)) {
return false;
}
+
+ if (timestamp > 0) {
+ m_script_metadata[CScriptID(entry)].nCreateTime = timestamp;
+ }
}
+ if (timestamp > 0) {
+ UpdateTimeFirstKey(timestamp);
+ }
+
return true;
}
diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h
index b2810246dc..1b6a2c99f4 100644
--- a/src/wallet/wallet.h
+++ b/src/wallet/wallet.h
@@ -1092,7 +1092,7 @@ public:
bool DummySignTx(CMutableTransaction &txNew, const std::vector<CTxOut> &txouts, bool use_max_sig = false) const;
bool DummySignInput(CTxIn &tx_in, const CTxOut &txout, bool use_max_sig = false) const;
- bool ImportScripts(const std::set<CScript> scripts) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
+ bool ImportScripts(const std::set<CScript> scripts, int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
bool ImportPrivKeys(const std::map<CKeyID, CKey>& privkey_map, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
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);
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);