Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
// Copyright (c) 2009-2010 Satoshi Nakamoto | // Copyright (c) 2009-2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include "wallet/wallet.h" | #include "wallet/wallet.h" | ||||
#include "chain.h" | #include "chain.h" | ||||
#include "checkpoints.h" | #include "checkpoints.h" | ||||
#include "config.h" | #include "config.h" | ||||
#include "consensus/consensus.h" | #include "consensus/consensus.h" | ||||
#include "consensus/validation.h" | #include "consensus/validation.h" | ||||
#include "dstencode.h" | #include "dstencode.h" | ||||
#include "fs.h" | #include "fs.h" | ||||
#include "init.h" | #include "init.h" | ||||
▲ Show 20 Lines • Show All 188 Lines • ▼ Show 20 Lines | void CWallet::DeriveNewChildKey(CWalletDB &walletdb, CKeyMetadata &metadata, | ||||
// derive child key at next index, skip keys already known to the wallet | // derive child key at next index, skip keys already known to the wallet | ||||
do { | do { | ||||
// always derive hardened keys | // always derive hardened keys | ||||
// childIndex | BIP32_HARDENED_KEY_LIMIT = derive childIndex in hardened | // childIndex | BIP32_HARDENED_KEY_LIMIT = derive childIndex in hardened | ||||
// child-index-range | // child-index-range | ||||
// example: 1 | BIP32_HARDENED_KEY_LIMIT == 0x80000001 == 2147483649 | // example: 1 | BIP32_HARDENED_KEY_LIMIT == 0x80000001 == 2147483649 | ||||
if (internal) { | if (internal) { | ||||
chainChildKey.Derive(childKey, | chainChildKey.Derive(childKey, hdChain.nInternalChainCounter | | ||||
hdChain.nInternalChainCounter | | |||||
BIP32_HARDENED_KEY_LIMIT); | BIP32_HARDENED_KEY_LIMIT); | ||||
metadata.hdKeypath = "m/0'/1'/" + | metadata.hdKeypath = "m/0'/1'/" + | ||||
std::to_string(hdChain.nInternalChainCounter) + | std::to_string(hdChain.nInternalChainCounter) + | ||||
"'"; | "'"; | ||||
hdChain.nInternalChainCounter++; | hdChain.nInternalChainCounter++; | ||||
} else { | } else { | ||||
chainChildKey.Derive(childKey, | chainChildKey.Derive(childKey, hdChain.nExternalChainCounter | | ||||
hdChain.nExternalChainCounter | | |||||
BIP32_HARDENED_KEY_LIMIT); | BIP32_HARDENED_KEY_LIMIT); | ||||
metadata.hdKeypath = "m/0'/0'/" + | metadata.hdKeypath = "m/0'/0'/" + | ||||
std::to_string(hdChain.nExternalChainCounter) + | std::to_string(hdChain.nExternalChainCounter) + | ||||
"'"; | "'"; | ||||
hdChain.nExternalChainCounter++; | hdChain.nExternalChainCounter++; | ||||
} | } | ||||
} while (HaveKey(childKey.key.GetPubKey().GetID())); | } while (HaveKey(childKey.key.GetPubKey().GetID())); | ||||
secret = childKey.key; | secret = childKey.key; | ||||
metadata.hdMasterKeyID = hdChain.masterKeyID; | metadata.hdMasterKeyID = hdChain.masterKeyID; | ||||
▲ Show 20 Lines • Show All 339 Lines • ▼ Show 20 Lines | bool CWallet::HasWalletSpend(const uint256 &txid) const { | ||||
auto iter = mapTxSpends.lower_bound(COutPoint(txid, 0)); | auto iter = mapTxSpends.lower_bound(COutPoint(txid, 0)); | ||||
return (iter != mapTxSpends.end() && iter->first.hash == txid); | return (iter != mapTxSpends.end() && iter->first.hash == txid); | ||||
} | } | ||||
void CWallet::Flush(bool shutdown) { | void CWallet::Flush(bool shutdown) { | ||||
dbw->Flush(shutdown); | dbw->Flush(shutdown); | ||||
} | } | ||||
static bool allowSymbolicLink() { | |||||
return gArgs.GetBoolArg("-walletallowsymboliclink", | |||||
DEFAULT_WALLET_ALLOW_SYMBOLIC_LINK); | |||||
} | |||||
bool CWallet::Verify(const CChainParams &chainParams) { | bool CWallet::Verify(const CChainParams &chainParams) { | ||||
if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) { | if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) { | ||||
return true; | return true; | ||||
} | } | ||||
uiInterface.InitMessage(_("Verifying wallet(s)...")); | uiInterface.InitMessage(_("Verifying wallet(s)...")); | ||||
// Keep track of each wallet absolute path to detect duplicates. | // Keep track of each wallet absolute path to detect duplicates. | ||||
Show All 9 Lines | for (const std::string &walletFile : gArgs.GetArgs("-wallet")) { | ||||
if (SanitizeString(walletFile, SAFE_CHARS_FILENAME) != walletFile) { | if (SanitizeString(walletFile, SAFE_CHARS_FILENAME) != walletFile) { | ||||
return InitError(strprintf(_("Error loading wallet %s. Invalid " | return InitError(strprintf(_("Error loading wallet %s. Invalid " | ||||
"characters in -wallet filename."), | "characters in -wallet filename."), | ||||
walletFile)); | walletFile)); | ||||
} | } | ||||
fs::path wallet_path = fs::absolute(walletFile, GetDataDir()); | fs::path wallet_path = fs::absolute(walletFile, GetDataDir()); | ||||
if (fs::exists(wallet_path) && | |||||
(!fs::is_regular_file(wallet_path) || | |||||
(fs::is_symlink(wallet_path) && !allowSymbolicLink()))) { | |||||
if (fs::exists(wallet_path) && (!fs::is_regular_file(wallet_path) || | |||||
fs::is_symlink(wallet_path))) { | |||||
return InitError(strprintf(_("Error loading wallet %s. -wallet " | return InitError(strprintf(_("Error loading wallet %s. -wallet " | ||||
"filename must be a regular file."), | "filename must be a regular file."), | ||||
walletFile)); | walletFile)); | ||||
} | } | ||||
if (!wallet_paths.insert(wallet_path).second) { | if (!wallet_paths.insert(wallet_path).second) { | ||||
return InitError(strprintf(_("Error loading wallet %s. Duplicate " | return InitError(strprintf(_("Error loading wallet %s. Duplicate " | ||||
"-wallet filename specified."), | "-wallet filename specified."), | ||||
▲ Show 20 Lines • Show All 3,452 Lines • ▼ Show 20 Lines | strUsage += HelpMessageOpt( | ||||
"Only has effect during wallet creation/first start") + | "Only has effect during wallet creation/first start") + | ||||
" " + strprintf(_("(default: %d)"), DEFAULT_USE_HD_WALLET)); | " " + strprintf(_("(default: %d)"), DEFAULT_USE_HD_WALLET)); | ||||
strUsage += HelpMessageOpt("-upgradewallet", | strUsage += HelpMessageOpt("-upgradewallet", | ||||
_("Upgrade wallet to latest format on startup")); | _("Upgrade wallet to latest format on startup")); | ||||
strUsage += | strUsage += | ||||
HelpMessageOpt("-wallet=<file>", | HelpMessageOpt("-wallet=<file>", | ||||
_("Specify wallet file (within data directory)") + " " + | _("Specify wallet file (within data directory)") + " " + | ||||
strprintf(_("(default: %s)"), DEFAULT_WALLET_DAT)); | strprintf(_("(default: %s)"), DEFAULT_WALLET_DAT)); | ||||
strUsage += HelpMessageOpt( | |||||
"-walletallowsymboliclink", | |||||
strprintf(_("Allow symbolic link for wallet (default: %u)"), | |||||
DEFAULT_WALLET_ALLOW_SYMBOLIC_LINK)); | |||||
strUsage += HelpMessageOpt( | strUsage += HelpMessageOpt( | ||||
"-walletbroadcast", | "-walletbroadcast", | ||||
_("Make the wallet broadcast transactions") + " " + | _("Make the wallet broadcast transactions") + " " + | ||||
strprintf(_("(default: %d)"), DEFAULT_WALLETBROADCAST)); | strprintf(_("(default: %d)"), DEFAULT_WALLETBROADCAST)); | ||||
strUsage += HelpMessageOpt("-walletnotify=<cmd>", | strUsage += HelpMessageOpt("-walletnotify=<cmd>", | ||||
_("Execute command when a wallet transaction " | _("Execute command when a wallet transaction " | ||||
"changes (%s in cmd is replaced by TxID)")); | "changes (%s in cmd is replaced by TxID)")); | ||||
strUsage += HelpMessageOpt( | strUsage += HelpMessageOpt( | ||||
▲ Show 20 Lines • Show All 502 Lines • Show Last 20 Lines |