Create method for getting HD seed in RPCs

This commit is contained in:
Eirik0 2019-04-24 16:20:08 -06:00
parent f283f2460e
commit 52cfa9c1ee
7 changed files with 16 additions and 27 deletions

View File

@ -348,12 +348,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl()
// generate a common one from the HD seed. This ensures the data is
// recoverable, while keeping it logically separate from the ZIP 32
// Sapling key hierarchy, which the user might not be using.
HDSeed seed;
if (!pwalletMain->GetHDSeed(seed)) {
throw JSONRPCError(
RPC_WALLET_ERROR,
"AsyncRPCOperation_sendmany: HD seed not found");
}
HDSeed seed = pwalletMain->GetHDSeedForRPC();
ovk = ovkForShieldingFromTaddr(seed);
}
if (!ovk) {

View File

@ -85,13 +85,7 @@ bool AsyncRPCOperation_saplingmigration::main_impl() {
return true;
}
HDSeed seed;
if (!pwalletMain->GetHDSeed(seed)) {
throw JSONRPCError(
RPC_WALLET_ERROR,
"AsyncRPCOperation_AsyncRPCOperation_saplingmigration: HD seed not found");
}
HDSeed seed = pwalletMain->GetHDSeedForRPC();
libzcash::SaplingPaymentAddress migrationDestAddress = getMigrationDestAddress(seed);
auto consensusParams = Params().GetConsensus();

View File

@ -381,12 +381,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
// generate a common one from the HD seed. This ensures the data is
// recoverable, while keeping it logically separate from the ZIP 32
// Sapling key hierarchy, which the user might not be using.
HDSeed seed;
if (!pwalletMain->GetHDSeed(seed)) {
throw JSONRPCError(
RPC_WALLET_ERROR,
"AsyncRPCOperation_sendmany::main_impl(): HD seed not found");
}
HDSeed seed = pwalletMain->GetHDSeedForRPC();
ovk = ovkForShieldingFromTaddr(seed);
}

View File

@ -247,12 +247,7 @@ bool ShieldToAddress::operator()(const libzcash::SaplingPaymentAddress &zaddr) c
// generate a common one from the HD seed. This ensures the data is
// recoverable, while keeping it logically separate from the ZIP 32
// Sapling key hierarchy, which the user might not be using.
HDSeed seed;
if (!pwalletMain->GetHDSeed(seed)) {
throw JSONRPCError(
RPC_WALLET_ERROR,
"CWallet::GenerateNewSaplingZKey(): HD seed not found");
}
HDSeed seed = pwalletMain->GetHDSeedForRPC();
uint256 ovk = ovkForShieldingFromTaddr(seed);
// Add transparent inputs

View File

@ -506,8 +506,7 @@ UniValue dumpwallet_impl(const UniValue& params, bool fHelp, bool fDumpZKeys)
file << strprintf("# * Best block at time of backup was %i (%s),\n", chainActive.Height(), chainActive.Tip()->GetBlockHash().ToString());
file << strprintf("# mined on %s\n", EncodeDumpTime(chainActive.Tip()->GetBlockTime()));
{
HDSeed hdSeed;
pwalletMain->GetHDSeed(hdSeed);
HDSeed hdSeed = pwalletMain->GetHDSeedForRPC();
auto rawSeed = hdSeed.RawSeed();
file << strprintf("# HDSeed=%s fingerprint=%s", HexStr(rawSeed.begin(), rawSeed.end()), hdSeed.Fingerprint().GetHex());
file << "\n";

View File

@ -2156,6 +2156,14 @@ bool CWallet::SetCryptedHDSeed(const uint256& seedFp, const std::vector<unsigned
return false;
}
HDSeed CWallet::GetHDSeedForRPC() const {
HDSeed seed;
if (!pwalletMain->GetHDSeed(seed)) {
throw JSONRPCError(RPC_WALLET_ERROR, "HD seed not found");
}
return seed;
}
void CWallet::SetHDChain(const CHDChain& chain, bool memonly)
{
LOCK(cs_wallet);

View File

@ -1288,6 +1288,9 @@ public:
bool SetHDSeed(const HDSeed& seed);
bool SetCryptedHDSeed(const uint256& seedFp, const std::vector<unsigned char> &vchCryptedSecret);
/* Returns the wallet's HD seed or throw JSONRPCError(...) */
HDSeed GetHDSeedForRPC() const;
/* Set the HD chain model (chain child index counters) */
void SetHDChain(const CHDChain& chain, bool memonly);
const CHDChain& GetHDChain() const { return hdChain; }