Skip to content

Commit 656fde5

Browse files
committed
Add script birthtime metadata to dump and import wallet
1 parent 1bab9b2 commit 656fde5

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/wallet/rpcdump.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,11 @@ UniValue importwallet(const JSONRPCRequest& request)
545545
fGood = false;
546546
continue;
547547
}
548+
int64_t birth_time = DecodeDumpTime(vstr[1]);
549+
if (birth_time > 0) {
550+
pwallet->m_script_metadata[CScriptID(script)].nCreateTime = birth_time;
551+
nTimeBegin = std::min(nTimeBegin, birth_time);
552+
}
548553
}
549554
}
550555
file.close();
@@ -653,6 +658,7 @@ UniValue dumpwallet(const JSONRPCRequest& request)
653658
pwallet->GetKeyBirthTimes(mapKeyBirth);
654659

655660
std::set<CScriptID> scripts = pwallet->GetCScripts();
661+
// TODO: include scripts in GetKeyBirthTimes() output instead of separate
656662

657663
// sort time/key pairs
658664
std::vector<std::pair<int64_t, CKeyID> > vKeyBirth;
@@ -710,9 +716,15 @@ UniValue dumpwallet(const JSONRPCRequest& request)
710716
file << "\n";
711717
for (const CScriptID &scriptid : scripts) {
712718
CScript script;
719+
std::string create_time = "0";
713720
std::string address = EncodeDestination(scriptid);
721+
// get birth times for scripts with metadata
722+
auto it = pwallet->m_script_metadata.find(scriptid);
723+
if (it != pwallet->m_script_metadata.end()) {
724+
create_time = EncodeDumpTime(it->second.nCreateTime);
725+
}
714726
if(pwallet->GetCScript(scriptid, script)) {
715-
file << strprintf("%s 0 script=1", HexStr(script.begin(), script.end()));
727+
file << strprintf("%s %s script=1", HexStr(script.begin(), script.end()), create_time);
716728
file << strprintf(" # addr=%s\n", address);
717729
}
718730
}

0 commit comments

Comments
 (0)