Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/scriptpubkeyman.cpp
// Copyright (c) 2019 The Bitcoin Core developers | // Copyright (c) 2019 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 <chainparams.h> | #include <chainparams.h> | ||||
#include <config.h> | #include <config.h> | ||||
#include <key_io.h> | #include <key_io.h> | ||||
#include <outputtype.h> | #include <outputtype.h> | ||||
#include <script/descriptor.h> | #include <script/descriptor.h> | ||||
#include <script/sign.h> | #include <script/sign.h> | ||||
#include <util/bip32.h> | #include <util/bip32.h> | ||||
#include <util/strencodings.h> | #include <util/strencodings.h> | ||||
#include <util/string.h> | |||||
#include <util/translation.h> | #include <util/translation.h> | ||||
#include <wallet/scriptpubkeyman.h> | #include <wallet/scriptpubkeyman.h> | ||||
bool LegacyScriptPubKeyMan::GetNewDestination(const OutputType type, | bool LegacyScriptPubKeyMan::GetNewDestination(const OutputType type, | ||||
CTxDestination &dest, | CTxDestination &dest, | ||||
std::string &error) { | std::string &error) { | ||||
LOCK(cs_KeyStore); | LOCK(cs_KeyStore); | ||||
error.clear(); | error.clear(); | ||||
▲ Show 20 Lines • Show All 937 Lines • ▼ Show 20 Lines | void LegacyScriptPubKeyMan::DeriveNewChildKey(WalletBatch &batch, | ||||
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, hdChain.nInternalChainCounter | | chainChildKey.Derive(childKey, hdChain.nInternalChainCounter | | ||||
BIP32_HARDENED_KEY_LIMIT); | BIP32_HARDENED_KEY_LIMIT); | ||||
metadata.hdKeypath = "m/0'/1'/" + | metadata.hdKeypath = | ||||
std::to_string(hdChain.nInternalChainCounter) + | "m/0'/1'/" + ToString(hdChain.nInternalChainCounter) + "'"; | ||||
"'"; | |||||
metadata.key_origin.path.push_back(0 | BIP32_HARDENED_KEY_LIMIT); | metadata.key_origin.path.push_back(0 | BIP32_HARDENED_KEY_LIMIT); | ||||
metadata.key_origin.path.push_back(1 | BIP32_HARDENED_KEY_LIMIT); | metadata.key_origin.path.push_back(1 | BIP32_HARDENED_KEY_LIMIT); | ||||
metadata.key_origin.path.push_back(hdChain.nInternalChainCounter | | metadata.key_origin.path.push_back(hdChain.nInternalChainCounter | | ||||
BIP32_HARDENED_KEY_LIMIT); | BIP32_HARDENED_KEY_LIMIT); | ||||
hdChain.nInternalChainCounter++; | hdChain.nInternalChainCounter++; | ||||
} else { | } else { | ||||
chainChildKey.Derive(childKey, hdChain.nExternalChainCounter | | chainChildKey.Derive(childKey, hdChain.nExternalChainCounter | | ||||
BIP32_HARDENED_KEY_LIMIT); | BIP32_HARDENED_KEY_LIMIT); | ||||
metadata.hdKeypath = "m/0'/0'/" + | metadata.hdKeypath = | ||||
std::to_string(hdChain.nExternalChainCounter) + | "m/0'/0'/" + ToString(hdChain.nExternalChainCounter) + "'"; | ||||
"'"; | |||||
metadata.key_origin.path.push_back(0 | BIP32_HARDENED_KEY_LIMIT); | metadata.key_origin.path.push_back(0 | BIP32_HARDENED_KEY_LIMIT); | ||||
metadata.key_origin.path.push_back(0 | BIP32_HARDENED_KEY_LIMIT); | metadata.key_origin.path.push_back(0 | BIP32_HARDENED_KEY_LIMIT); | ||||
metadata.key_origin.path.push_back(hdChain.nExternalChainCounter | | metadata.key_origin.path.push_back(hdChain.nExternalChainCounter | | ||||
BIP32_HARDENED_KEY_LIMIT); | BIP32_HARDENED_KEY_LIMIT); | ||||
hdChain.nExternalChainCounter++; | hdChain.nExternalChainCounter++; | ||||
} | } | ||||
} while (HaveKey(childKey.key.GetPubKey().GetID())); | } while (HaveKey(childKey.key.GetPubKey().GetID())); | ||||
secret = childKey.key; | secret = childKey.key; | ||||
▲ Show 20 Lines • Show All 1,271 Lines • Show Last 20 Lines |