scripted-diff: Rename master key to seed

-BEGIN VERIFY SCRIPT-

ren() { git grep -l "\<$1\>" 'src/*.cpp' 'src/*.h' test | xargs sed -i "s:\<$1\>:$2:g"; }
ren GenerateNewHDMasterKey  GenerateNewSeed
ren DeriveNewMasterHDKey    DeriveNewSeed
ren SetHDMasterKey          SetHDSeed
ren hdMasterKeyID           hd_seed_id
ren masterKeyID             seed_id
ren SetMaster               SetSeed
ren hdmasterkeyid           hdseedid
ren hdmaster                hdseed

-END VERIFY SCRIPT-
This commit is contained in:
John Newbery 2018-04-04 11:43:45 -04:00
parent d792e47421
commit 131d4450b9
11 changed files with 57 additions and 57 deletions

View file

@ -273,7 +273,7 @@ bool CExtKey::Derive(CExtKey &out, unsigned int _nChild) const {
return key.Derive(out.key, out.chaincode, _nChild, chaincode); return key.Derive(out.key, out.chaincode, _nChild, chaincode);
} }
void CExtKey::SetMaster(const unsigned char *seed, unsigned int nSeedLen) { void CExtKey::SetSeed(const unsigned char *seed, unsigned int nSeedLen) {
static const unsigned char hashkey[] = {'B','i','t','c','o','i','n',' ','s','e','e','d'}; static const unsigned char hashkey[] = {'B','i','t','c','o','i','n',' ','s','e','e','d'};
std::vector<unsigned char, secure_allocator<unsigned char>> vout(64); std::vector<unsigned char, secure_allocator<unsigned char>> vout(64);
CHMAC_SHA512(hashkey, sizeof(hashkey)).Write(seed, nSeedLen).Finalize(vout.data()); CHMAC_SHA512(hashkey, sizeof(hashkey)).Write(seed, nSeedLen).Finalize(vout.data());

View file

@ -158,7 +158,7 @@ struct CExtKey {
void Decode(const unsigned char code[BIP32_EXTKEY_SIZE]); void Decode(const unsigned char code[BIP32_EXTKEY_SIZE]);
bool Derive(CExtKey& out, unsigned int nChild) const; bool Derive(CExtKey& out, unsigned int nChild) const;
CExtPubKey Neuter() const; CExtPubKey Neuter() const;
void SetMaster(const unsigned char* seed, unsigned int nSeedLen); void SetSeed(const unsigned char* seed, unsigned int nSeedLen);
template <typename Stream> template <typename Stream>
void Serialize(Stream& s) const void Serialize(Stream& s) const
{ {

View file

@ -91,7 +91,7 @@ static void RunTest(const TestVector &test) {
std::vector<unsigned char> seed = ParseHex(test.strHexMaster); std::vector<unsigned char> seed = ParseHex(test.strHexMaster);
CExtKey key; CExtKey key;
CExtPubKey pubkey; CExtPubKey pubkey;
key.SetMaster(seed.data(), seed.size()); key.SetSeed(seed.data(), seed.size());
pubkey = key.Neuter(); pubkey = key.Neuter();
for (const TestDerivation &derive : test.vDerive) { for (const TestDerivation &derive : test.vDerive) {
unsigned char data[74]; unsigned char data[74];

View file

@ -752,13 +752,13 @@ UniValue dumpwallet(const JSONRPCRequest& request)
file << "\n"; file << "\n";
// add the base58check encoded extended master if the wallet uses HD // add the base58check encoded extended master if the wallet uses HD
CKeyID masterKeyID = pwallet->GetHDChain().masterKeyID; CKeyID seed_id = pwallet->GetHDChain().seed_id;
if (!masterKeyID.IsNull()) if (!seed_id.IsNull())
{ {
CKey key; CKey key;
if (pwallet->GetKey(masterKeyID, key)) { if (pwallet->GetKey(seed_id, key)) {
CExtKey masterKey; CExtKey masterKey;
masterKey.SetMaster(key.begin(), key.size()); masterKey.SetSeed(key.begin(), key.size());
file << "# extended private masterkey: " << EncodeExtKey(masterKey) << "\n\n"; file << "# extended private masterkey: " << EncodeExtKey(masterKey) << "\n\n";
} }
@ -773,8 +773,8 @@ UniValue dumpwallet(const JSONRPCRequest& request)
file << strprintf("%s %s ", EncodeSecret(key), strTime); file << strprintf("%s %s ", EncodeSecret(key), strTime);
if (GetWalletAddressesForKey(pwallet, keyid, strAddr, strLabel)) { if (GetWalletAddressesForKey(pwallet, keyid, strAddr, strLabel)) {
file << strprintf("label=%s", strLabel); file << strprintf("label=%s", strLabel);
} else if (keyid == masterKeyID) { } else if (keyid == seed_id) {
file << "hdmaster=1"; file << "hdseed=1";
} else if (mapKeyPool.count(keyid)) { } else if (mapKeyPool.count(keyid)) {
file << "reserve=1"; file << "reserve=1";
} else if (pwallet->mapKeyMetadata[keyid].hdKeypath == "m") { } else if (pwallet->mapKeyMetadata[keyid].hdKeypath == "m") {

View file

@ -2925,7 +2925,7 @@ static UniValue getwalletinfo(const JSONRPCRequest& request)
" \"keypoolsize_hd_internal\": xxxx, (numeric) how many new keys are pre-generated for internal use (used for change outputs, only appears if the wallet is using this feature, otherwise external keys are used)\n" " \"keypoolsize_hd_internal\": xxxx, (numeric) how many new keys are pre-generated for internal use (used for change outputs, only appears if the wallet is using this feature, otherwise external keys are used)\n"
" \"unlocked_until\": ttt, (numeric) the timestamp in seconds since epoch (midnight Jan 1 1970 GMT) that the wallet is unlocked for transfers, or 0 if the wallet is locked\n" " \"unlocked_until\": ttt, (numeric) the timestamp in seconds since epoch (midnight Jan 1 1970 GMT) that the wallet is unlocked for transfers, or 0 if the wallet is locked\n"
" \"paytxfee\": x.xxxx, (numeric) the transaction fee configuration, set in " + CURRENCY_UNIT + "/kB\n" " \"paytxfee\": x.xxxx, (numeric) the transaction fee configuration, set in " + CURRENCY_UNIT + "/kB\n"
" \"hdmasterkeyid\": \"<hash160>\" (string, optional) the Hash160 of the HD master pubkey (only present when HD is enabled)\n" " \"hdseedid\": \"<hash160>\" (string, optional) the Hash160 of the HD master pubkey (only present when HD is enabled)\n"
"}\n" "}\n"
"\nExamples:\n" "\nExamples:\n"
+ HelpExampleCli("getwalletinfo", "") + HelpExampleCli("getwalletinfo", "")
@ -2949,16 +2949,16 @@ static UniValue getwalletinfo(const JSONRPCRequest& request)
obj.pushKV("txcount", (int)pwallet->mapWallet.size()); obj.pushKV("txcount", (int)pwallet->mapWallet.size());
obj.pushKV("keypoololdest", pwallet->GetOldestKeyPoolTime()); obj.pushKV("keypoololdest", pwallet->GetOldestKeyPoolTime());
obj.pushKV("keypoolsize", (int64_t)kpExternalSize); obj.pushKV("keypoolsize", (int64_t)kpExternalSize);
CKeyID masterKeyID = pwallet->GetHDChain().masterKeyID; CKeyID seed_id = pwallet->GetHDChain().seed_id;
if (!masterKeyID.IsNull() && pwallet->CanSupportFeature(FEATURE_HD_SPLIT)) { if (!seed_id.IsNull() && pwallet->CanSupportFeature(FEATURE_HD_SPLIT)) {
obj.pushKV("keypoolsize_hd_internal", (int64_t)(pwallet->GetKeyPoolSize() - kpExternalSize)); obj.pushKV("keypoolsize_hd_internal", (int64_t)(pwallet->GetKeyPoolSize() - kpExternalSize));
} }
if (pwallet->IsCrypted()) { if (pwallet->IsCrypted()) {
obj.pushKV("unlocked_until", pwallet->nRelockTime); obj.pushKV("unlocked_until", pwallet->nRelockTime);
} }
obj.pushKV("paytxfee", ValueFromAmount(pwallet->m_pay_tx_fee.GetFeePerK())); obj.pushKV("paytxfee", ValueFromAmount(pwallet->m_pay_tx_fee.GetFeePerK()));
if (!masterKeyID.IsNull()) if (!seed_id.IsNull())
obj.pushKV("hdmasterkeyid", masterKeyID.GetHex()); obj.pushKV("hdseedid", seed_id.GetHex());
return obj; return obj;
} }
@ -3948,13 +3948,13 @@ UniValue getaddressinfo(const JSONRPCRequest& request)
" ]\n" " ]\n"
" \"sigsrequired\" : xxxxx (numeric, optional) Number of signatures required to spend multisig output (only if \"script\" is \"multisig\")\n" " \"sigsrequired\" : xxxxx (numeric, optional) Number of signatures required to spend multisig output (only if \"script\" is \"multisig\")\n"
" \"pubkey\" : \"publickeyhex\", (string, optional) The hex value of the raw public key, for single-key addresses (possibly embedded in P2SH or P2WSH)\n" " \"pubkey\" : \"publickeyhex\", (string, optional) The hex value of the raw public key, for single-key addresses (possibly embedded in P2SH or P2WSH)\n"
" \"embedded\" : {...}, (object, optional) Information about the address embedded in P2SH or P2WSH, if relevant and known. It includes all getaddressinfo output fields for the embedded address, excluding metadata (\"timestamp\", \"hdkeypath\", \"hdmasterkeyid\") and relation to the wallet (\"ismine\", \"iswatchonly\", \"account\").\n" " \"embedded\" : {...}, (object, optional) Information about the address embedded in P2SH or P2WSH, if relevant and known. It includes all getaddressinfo output fields for the embedded address, excluding metadata (\"timestamp\", \"hdkeypath\", \"hdseedid\") and relation to the wallet (\"ismine\", \"iswatchonly\", \"account\").\n"
" \"iscompressed\" : true|false, (boolean) If the address is compressed\n" " \"iscompressed\" : true|false, (boolean) If the address is compressed\n"
" \"label\" : \"label\" (string) The label associated with the address, \"\" is the default account\n" " \"label\" : \"label\" (string) The label associated with the address, \"\" is the default account\n"
" \"account\" : \"account\" (string) DEPRECATED. This field will be removed in V0.18. To see this deprecated field, start bitcoind with -deprecatedrpc=accounts. The account associated with the address, \"\" is the default account\n" " \"account\" : \"account\" (string) DEPRECATED. This field will be removed in V0.18. To see this deprecated field, start bitcoind with -deprecatedrpc=accounts. The account associated with the address, \"\" is the default account\n"
" \"timestamp\" : timestamp, (number, optional) The creation time of the key if available in seconds since epoch (Jan 1 1970 GMT)\n" " \"timestamp\" : timestamp, (number, optional) The creation time of the key if available in seconds since epoch (Jan 1 1970 GMT)\n"
" \"hdkeypath\" : \"keypath\" (string, optional) The HD keypath if the key is HD and available\n" " \"hdkeypath\" : \"keypath\" (string, optional) The HD keypath if the key is HD and available\n"
" \"hdmasterkeyid\" : \"<hash160>\" (string, optional) The Hash160 of the HD master pubkey\n" " \"hdseedid\" : \"<hash160>\" (string, optional) The Hash160 of the HD master pubkey\n"
" \"labels\" (object) Array of labels associated with the address.\n" " \"labels\" (object) Array of labels associated with the address.\n"
" [\n" " [\n"
" { (json object of label data)\n" " { (json object of label data)\n"
@ -4014,7 +4014,7 @@ UniValue getaddressinfo(const JSONRPCRequest& request)
ret.pushKV("timestamp", meta->nCreateTime); ret.pushKV("timestamp", meta->nCreateTime);
if (!meta->hdKeypath.empty()) { if (!meta->hdKeypath.empty()) {
ret.pushKV("hdkeypath", meta->hdKeypath); ret.pushKV("hdkeypath", meta->hdKeypath);
ret.pushKV("hdmasterkeyid", meta->hdMasterKeyID.GetHex()); ret.pushKV("hdseedid", meta->hd_seed_id.GetHex());
} }
} }
@ -4147,7 +4147,7 @@ UniValue sethdseed(const JSONRPCRequest& request)
" If false, addresses (including change addresses if the wallet already had HD Chain Split enabled) from the existing\n" " If false, addresses (including change addresses if the wallet already had HD Chain Split enabled) from the existing\n"
" keypool will be used until it has been depleted.\n" " keypool will be used until it has been depleted.\n"
"2. \"seed\" (string, optional) The WIF private key to use as the new HD seed; if not provided a random seed will be used.\n" "2. \"seed\" (string, optional) The WIF private key to use as the new HD seed; if not provided a random seed will be used.\n"
" The seed value can be retrieved using the dumpwallet command. It is the private key marked hdmaster=1\n" " The seed value can be retrieved using the dumpwallet command. It is the private key marked hdseed=1\n"
"\nExamples:\n" "\nExamples:\n"
+ HelpExampleCli("sethdseed", "") + HelpExampleCli("sethdseed", "")
+ HelpExampleCli("sethdseed", "false") + HelpExampleCli("sethdseed", "false")
@ -4176,7 +4176,7 @@ UniValue sethdseed(const JSONRPCRequest& request)
CPubKey master_pub_key; CPubKey master_pub_key;
if (request.params[1].isNull()) { if (request.params[1].isNull()) {
master_pub_key = pwallet->GenerateNewHDMasterKey(); master_pub_key = pwallet->GenerateNewSeed();
} else { } else {
CKey key = DecodeSecret(request.params[1].get_str()); CKey key = DecodeSecret(request.params[1].get_str());
if (!key.IsValid()) { if (!key.IsValid()) {
@ -4187,10 +4187,10 @@ UniValue sethdseed(const JSONRPCRequest& request)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Already have this key (either as an HD seed or as a loose private key)"); throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Already have this key (either as an HD seed or as a loose private key)");
} }
master_pub_key = pwallet->DeriveNewMasterHDKey(key); master_pub_key = pwallet->DeriveNewSeed(key);
} }
pwallet->SetHDMasterKey(master_pub_key); pwallet->SetHDSeed(master_pub_key);
if (flush_key_pool) pwallet->NewKeyPool(); if (flush_key_pool) pwallet->NewKeyPool();
return NullUniValue; return NullUniValue;

View file

@ -198,10 +198,10 @@ void CWallet::DeriveNewChildKey(WalletBatch &batch, CKeyMetadata& metadata, CKey
CExtKey childKey; //key at m/0'/0'/<n>' CExtKey childKey; //key at m/0'/0'/<n>'
// try to get the master key // try to get the master key
if (!GetKey(hdChain.masterKeyID, key)) if (!GetKey(hdChain.seed_id, key))
throw std::runtime_error(std::string(__func__) + ": Master key not found"); throw std::runtime_error(std::string(__func__) + ": Master key not found");
masterKey.SetMaster(key.begin(), key.size()); masterKey.SetSeed(key.begin(), key.size());
// derive m/0' // derive m/0'
// use hardened derivation (child keys >= 0x80000000 are hardened after bip32) // use hardened derivation (child keys >= 0x80000000 are hardened after bip32)
@ -228,7 +228,7 @@ void CWallet::DeriveNewChildKey(WalletBatch &batch, CKeyMetadata& metadata, CKey
} }
} while (HaveKey(childKey.key.GetPubKey().GetID())); } while (HaveKey(childKey.key.GetPubKey().GetID()));
secret = childKey.key; secret = childKey.key;
metadata.hdMasterKeyID = hdChain.masterKeyID; metadata.hd_seed_id = hdChain.seed_id;
// update the chain model in the database // update the chain model in the database
if (!batch.WriteHDChain(hdChain)) if (!batch.WriteHDChain(hdChain))
throw std::runtime_error(std::string(__func__) + ": Writing HD chain model failed"); throw std::runtime_error(std::string(__func__) + ": Writing HD chain model failed");
@ -691,7 +691,7 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
// if we are using HD, replace the HD master key (seed) with a new one // if we are using HD, replace the HD master key (seed) with a new one
if (IsHDEnabled()) { if (IsHDEnabled()) {
if (!SetHDMasterKey(GenerateNewHDMasterKey())) { if (!SetHDSeed(GenerateNewSeed())) {
return false; return false;
} }
} }
@ -1450,14 +1450,14 @@ CAmount CWallet::GetChange(const CTransaction& tx) const
return nChange; return nChange;
} }
CPubKey CWallet::GenerateNewHDMasterKey() CPubKey CWallet::GenerateNewSeed()
{ {
CKey key; CKey key;
key.MakeNewKey(true); key.MakeNewKey(true);
return DeriveNewMasterHDKey(key); return DeriveNewSeed(key);
} }
CPubKey CWallet::DeriveNewMasterHDKey(const CKey& key) CPubKey CWallet::DeriveNewSeed(const CKey& key)
{ {
int64_t nCreationTime = GetTime(); int64_t nCreationTime = GetTime();
CKeyMetadata metadata(nCreationTime); CKeyMetadata metadata(nCreationTime);
@ -1468,7 +1468,7 @@ CPubKey CWallet::DeriveNewMasterHDKey(const CKey& key)
// set the hd keypath to "m" -> Master, refers the masterkeyid to itself // set the hd keypath to "m" -> Master, refers the masterkeyid to itself
metadata.hdKeypath = "m"; metadata.hdKeypath = "m";
metadata.hdMasterKeyID = pubkey.GetID(); metadata.hd_seed_id = pubkey.GetID();
{ {
LOCK(cs_wallet); LOCK(cs_wallet);
@ -1484,7 +1484,7 @@ CPubKey CWallet::DeriveNewMasterHDKey(const CKey& key)
return pubkey; return pubkey;
} }
bool CWallet::SetHDMasterKey(const CPubKey& pubkey) bool CWallet::SetHDSeed(const CPubKey& pubkey)
{ {
LOCK(cs_wallet); LOCK(cs_wallet);
// store the keyid (hash160) together with // store the keyid (hash160) together with
@ -1492,7 +1492,7 @@ bool CWallet::SetHDMasterKey(const CPubKey& pubkey)
// as a hdchain object // as a hdchain object
CHDChain newHdChain; CHDChain newHdChain;
newHdChain.nVersion = CanSupportFeature(FEATURE_HD_SPLIT) ? CHDChain::VERSION_HD_CHAIN_SPLIT : CHDChain::VERSION_HD_BASE; newHdChain.nVersion = CanSupportFeature(FEATURE_HD_SPLIT) ? CHDChain::VERSION_HD_CHAIN_SPLIT : CHDChain::VERSION_HD_BASE;
newHdChain.masterKeyID = pubkey.GetID(); newHdChain.seed_id = pubkey.GetID();
SetHDChain(newHdChain, false); SetHDChain(newHdChain, false);
return true; return true;
@ -1510,7 +1510,7 @@ bool CWallet::SetHDChain(const CHDChain& chain, bool memonly)
bool CWallet::IsHDEnabled() const bool CWallet::IsHDEnabled() const
{ {
return !hdChain.masterKeyID.IsNull(); return !hdChain.seed_id.IsNull();
} }
int64_t CWalletTx::GetTxTime() const int64_t CWalletTx::GetTxTime() const
@ -4130,8 +4130,8 @@ CWallet* CWallet::CreateWalletFromFile(const std::string& name, const fs::path&
walletInstance->SetMinVersion(FEATURE_HD); walletInstance->SetMinVersion(FEATURE_HD);
// generate a new master key // generate a new master key
CPubKey masterPubKey = walletInstance->GenerateNewHDMasterKey(); CPubKey masterPubKey = walletInstance->GenerateNewSeed();
if (!walletInstance->SetHDMasterKey(masterPubKey)) { if (!walletInstance->SetHDSeed(masterPubKey)) {
throw std::runtime_error(std::string(__func__) + ": Storing master key failed"); throw std::runtime_error(std::string(__func__) + ": Storing master key failed");
} }
hd_upgrade = true; hd_upgrade = true;
@ -4165,8 +4165,8 @@ CWallet* CWallet::CreateWalletFromFile(const std::string& name, const fs::path&
walletInstance->SetMinVersion(FEATURE_LATEST); walletInstance->SetMinVersion(FEATURE_LATEST);
// generate a new master key // generate a new master key
CPubKey masterPubKey = walletInstance->GenerateNewHDMasterKey(); CPubKey masterPubKey = walletInstance->GenerateNewSeed();
if (!walletInstance->SetHDMasterKey(masterPubKey)) if (!walletInstance->SetHDSeed(masterPubKey))
throw std::runtime_error(std::string(__func__) + ": Storing master key failed"); throw std::runtime_error(std::string(__func__) + ": Storing master key failed");
// Top up the keypool // Top up the keypool

View file

@ -1140,16 +1140,16 @@ public:
bool IsHDEnabled() const; bool IsHDEnabled() const;
/* Generates a new HD master key (will not be activated) */ /* Generates a new HD master key (will not be activated) */
CPubKey GenerateNewHDMasterKey(); CPubKey GenerateNewSeed();
/* Derives a new HD master key (will not be activated) */ /* Derives a new HD master key (will not be activated) */
CPubKey DeriveNewMasterHDKey(const CKey& key); CPubKey DeriveNewSeed(const CKey& key);
/* Set the current HD master key (will reset the chain child index counters) /* Set the current HD master key (will reset the chain child index counters)
Sets the master key's version based on the current wallet version (so the Sets the master key's version based on the current wallet version (so the
caller must ensure the current wallet version is correct before calling caller must ensure the current wallet version is correct before calling
this function). */ this function). */
bool SetHDMasterKey(const CPubKey& key); bool SetHDSeed(const CPubKey& key);
/** /**
* Blocks until the wallet state is up-to-date to /at least/ the current * Blocks until the wallet state is up-to-date to /at least/ the current

View file

@ -62,7 +62,7 @@ class CHDChain
public: public:
uint32_t nExternalChainCounter; uint32_t nExternalChainCounter;
uint32_t nInternalChainCounter; uint32_t nInternalChainCounter;
CKeyID masterKeyID; //!< master key hash160 CKeyID seed_id; //!< master key hash160
static const int VERSION_HD_BASE = 1; static const int VERSION_HD_BASE = 1;
static const int VERSION_HD_CHAIN_SPLIT = 2; static const int VERSION_HD_CHAIN_SPLIT = 2;
@ -76,7 +76,7 @@ public:
{ {
READWRITE(this->nVersion); READWRITE(this->nVersion);
READWRITE(nExternalChainCounter); READWRITE(nExternalChainCounter);
READWRITE(masterKeyID); READWRITE(seed_id);
if (this->nVersion >= VERSION_HD_CHAIN_SPLIT) if (this->nVersion >= VERSION_HD_CHAIN_SPLIT)
READWRITE(nInternalChainCounter); READWRITE(nInternalChainCounter);
} }
@ -86,7 +86,7 @@ public:
nVersion = CHDChain::CURRENT_VERSION; nVersion = CHDChain::CURRENT_VERSION;
nExternalChainCounter = 0; nExternalChainCounter = 0;
nInternalChainCounter = 0; nInternalChainCounter = 0;
masterKeyID.SetNull(); seed_id.SetNull();
} }
}; };
@ -99,7 +99,7 @@ public:
int nVersion; int nVersion;
int64_t nCreateTime; // 0 means unknown int64_t nCreateTime; // 0 means unknown
std::string hdKeypath; //optional HD/bip32 keypath std::string hdKeypath; //optional HD/bip32 keypath
CKeyID hdMasterKeyID; //id of the HD masterkey used to derive this key CKeyID hd_seed_id; //id of the HD masterkey used to derive this key
CKeyMetadata() CKeyMetadata()
{ {
@ -120,7 +120,7 @@ public:
if (this->nVersion >= VERSION_WITH_HDDATA) if (this->nVersion >= VERSION_WITH_HDDATA)
{ {
READWRITE(hdKeypath); READWRITE(hdKeypath);
READWRITE(hdMasterKeyID); READWRITE(hd_seed_id);
} }
} }
@ -129,7 +129,7 @@ public:
nVersion = CKeyMetadata::CURRENT_VERSION; nVersion = CKeyMetadata::CURRENT_VERSION;
nCreateTime = 0; nCreateTime = 0;
hdKeypath.clear(); hdKeypath.clear();
hdMasterKeyID.SetNull(); hd_seed_id.SetNull();
} }
}; };

View file

@ -39,7 +39,7 @@ def read_dump(file_name, addrs, script_addrs, hd_master_addr_old):
if keytype == "inactivehdmaster=1": if keytype == "inactivehdmaster=1":
# ensure the old master is still available # ensure the old master is still available
assert(hd_master_addr_old == addr) assert(hd_master_addr_old == addr)
elif keytype == "hdmaster=1": elif keytype == "hdseed=1":
# ensure we have generated a new hd master key # ensure we have generated a new hd master key
assert(hd_master_addr_old != addr) assert(hd_master_addr_old != addr)
hd_master_addr_ret = addr hd_master_addr_ret = addr

View file

@ -29,7 +29,7 @@ class WalletHDTest(BitcoinTestFramework):
connect_nodes_bi(self.nodes, 0, 1) connect_nodes_bi(self.nodes, 0, 1)
# Make sure we use hd, keep masterkeyid # Make sure we use hd, keep masterkeyid
masterkeyid = self.nodes[1].getwalletinfo()['hdmasterkeyid'] masterkeyid = self.nodes[1].getwalletinfo()['hdseedid']
assert_equal(len(masterkeyid), 40) assert_equal(len(masterkeyid), 40)
# create an internal key # create an internal key
@ -54,7 +54,7 @@ class WalletHDTest(BitcoinTestFramework):
hd_add = self.nodes[1].getnewaddress() hd_add = self.nodes[1].getnewaddress()
hd_info = self.nodes[1].getaddressinfo(hd_add) hd_info = self.nodes[1].getaddressinfo(hd_add)
assert_equal(hd_info["hdkeypath"], "m/0'/0'/"+str(i)+"'") assert_equal(hd_info["hdkeypath"], "m/0'/0'/"+str(i)+"'")
assert_equal(hd_info["hdmasterkeyid"], masterkeyid) assert_equal(hd_info["hdseedid"], masterkeyid)
self.nodes[0].sendtoaddress(hd_add, 1) self.nodes[0].sendtoaddress(hd_add, 1)
self.nodes[0].generate(1) self.nodes[0].generate(1)
self.nodes[0].sendtoaddress(non_hd_add, 1) self.nodes[0].sendtoaddress(non_hd_add, 1)
@ -83,7 +83,7 @@ class WalletHDTest(BitcoinTestFramework):
hd_add_2 = self.nodes[1].getnewaddress() hd_add_2 = self.nodes[1].getnewaddress()
hd_info_2 = self.nodes[1].getaddressinfo(hd_add_2) hd_info_2 = self.nodes[1].getaddressinfo(hd_add_2)
assert_equal(hd_info_2["hdkeypath"], "m/0'/0'/"+str(i)+"'") assert_equal(hd_info_2["hdkeypath"], "m/0'/0'/"+str(i)+"'")
assert_equal(hd_info_2["hdmasterkeyid"], masterkeyid) assert_equal(hd_info_2["hdseedid"], masterkeyid)
assert_equal(hd_add, hd_add_2) assert_equal(hd_add, hd_add_2)
connect_nodes_bi(self.nodes, 0, 1) connect_nodes_bi(self.nodes, 0, 1)
self.sync_all() self.sync_all()
@ -122,9 +122,9 @@ class WalletHDTest(BitcoinTestFramework):
assert_equal(keypath[0:7], "m/0'/1'") assert_equal(keypath[0:7], "m/0'/1'")
# Generate a new HD seed on node 1 and make sure it is set # Generate a new HD seed on node 1 and make sure it is set
orig_masterkeyid = self.nodes[1].getwalletinfo()['hdmasterkeyid'] orig_masterkeyid = self.nodes[1].getwalletinfo()['hdseedid']
self.nodes[1].sethdseed() self.nodes[1].sethdseed()
new_masterkeyid = self.nodes[1].getwalletinfo()['hdmasterkeyid'] new_masterkeyid = self.nodes[1].getwalletinfo()['hdseedid']
assert orig_masterkeyid != new_masterkeyid assert orig_masterkeyid != new_masterkeyid
addr = self.nodes[1].getnewaddress() addr = self.nodes[1].getnewaddress()
assert_equal(self.nodes[1].getaddressinfo(addr)['hdkeypath'], 'm/0\'/0\'/0\'') # Make sure the new address is the first from the keypool assert_equal(self.nodes[1].getaddressinfo(addr)['hdkeypath'], 'm/0\'/0\'/0\'') # Make sure the new address is the first from the keypool
@ -134,16 +134,16 @@ class WalletHDTest(BitcoinTestFramework):
new_seed = self.nodes[0].dumpprivkey(self.nodes[0].getnewaddress()) new_seed = self.nodes[0].dumpprivkey(self.nodes[0].getnewaddress())
orig_masterkeyid = new_masterkeyid orig_masterkeyid = new_masterkeyid
self.nodes[1].sethdseed(False, new_seed) self.nodes[1].sethdseed(False, new_seed)
new_masterkeyid = self.nodes[1].getwalletinfo()['hdmasterkeyid'] new_masterkeyid = self.nodes[1].getwalletinfo()['hdseedid']
assert orig_masterkeyid != new_masterkeyid assert orig_masterkeyid != new_masterkeyid
addr = self.nodes[1].getnewaddress() addr = self.nodes[1].getnewaddress()
assert_equal(orig_masterkeyid, self.nodes[1].getaddressinfo(addr)['hdmasterkeyid']) assert_equal(orig_masterkeyid, self.nodes[1].getaddressinfo(addr)['hdseedid'])
assert_equal(self.nodes[1].getaddressinfo(addr)['hdkeypath'], 'm/0\'/0\'/1\'') # Make sure the new address continues previous keypool assert_equal(self.nodes[1].getaddressinfo(addr)['hdkeypath'], 'm/0\'/0\'/1\'') # Make sure the new address continues previous keypool
# Check that the next address is from the new seed # Check that the next address is from the new seed
self.nodes[1].keypoolrefill(1) self.nodes[1].keypoolrefill(1)
next_addr = self.nodes[1].getnewaddress() next_addr = self.nodes[1].getnewaddress()
assert_equal(new_masterkeyid, self.nodes[1].getaddressinfo(next_addr)['hdmasterkeyid']) assert_equal(new_masterkeyid, self.nodes[1].getaddressinfo(next_addr)['hdseedid'])
assert_equal(self.nodes[1].getaddressinfo(next_addr)['hdkeypath'], 'm/0\'/0\'/0\'') # Make sure the new address is not from previous keypool assert_equal(self.nodes[1].getaddressinfo(next_addr)['hdkeypath'], 'm/0\'/0\'/0\'') # Make sure the new address is not from previous keypool
assert next_addr != addr assert next_addr != addr

View file

@ -16,7 +16,7 @@ class KeyPoolTest(BitcoinTestFramework):
addr_before_encrypting = nodes[0].getnewaddress() addr_before_encrypting = nodes[0].getnewaddress()
addr_before_encrypting_data = nodes[0].getaddressinfo(addr_before_encrypting) addr_before_encrypting_data = nodes[0].getaddressinfo(addr_before_encrypting)
wallet_info_old = nodes[0].getwalletinfo() wallet_info_old = nodes[0].getwalletinfo()
assert(addr_before_encrypting_data['hdmasterkeyid'] == wallet_info_old['hdmasterkeyid']) assert(addr_before_encrypting_data['hdseedid'] == wallet_info_old['hdseedid'])
# Encrypt wallet and wait to terminate # Encrypt wallet and wait to terminate
nodes[0].node_encrypt_wallet('test') nodes[0].node_encrypt_wallet('test')
@ -26,8 +26,8 @@ class KeyPoolTest(BitcoinTestFramework):
addr = nodes[0].getnewaddress() addr = nodes[0].getnewaddress()
addr_data = nodes[0].getaddressinfo(addr) addr_data = nodes[0].getaddressinfo(addr)
wallet_info = nodes[0].getwalletinfo() wallet_info = nodes[0].getwalletinfo()
assert(addr_before_encrypting_data['hdmasterkeyid'] != wallet_info['hdmasterkeyid']) assert(addr_before_encrypting_data['hdseedid'] != wallet_info['hdseedid'])
assert(addr_data['hdmasterkeyid'] == wallet_info['hdmasterkeyid']) assert(addr_data['hdseedid'] == wallet_info['hdseedid'])
assert_raises_rpc_error(-12, "Error: Keypool ran out, please call keypoolrefill first", nodes[0].getnewaddress) assert_raises_rpc_error(-12, "Error: Keypool ran out, please call keypoolrefill first", nodes[0].getnewaddress)
# put six (plus 2) new keys in the keypool (100% external-, +100% internal-keys, 1 in min) # put six (plus 2) new keys in the keypool (100% external-, +100% internal-keys, 1 in min)