Add HD keypath to CKeyMetadata, report metadata in validateaddress
https://github.com/bitcoin/bitcoin/pull/8323
This commit is contained in:
@@ -174,6 +174,8 @@ UniValue validateaddress(const UniValue& params, bool fHelp)
|
||||
" \"pubkey\" : \"publickeyhex\", (string) The hex value of the raw public key\n"
|
||||
" \"iscompressed\" : true|false, (boolean) If the address is compressed\n"
|
||||
" \"account\" : \"account\" (string) DEPRECATED. The account associated with the address, \"\" is the default account\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"
|
||||
"}\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("validateaddress", "\"1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc\"")
|
||||
@@ -208,6 +210,12 @@ UniValue validateaddress(const UniValue& params, bool fHelp)
|
||||
ret.pushKVs(detail);
|
||||
if (pwalletMain && pwalletMain->mapAddressBook.count(dest))
|
||||
ret.push_back(Pair("account", pwalletMain->mapAddressBook[dest].name));
|
||||
CKeyID keyID;
|
||||
if (pwalletMain && address.GetKeyID(keyID) && pwalletMain->mapKeyMetadata.count(keyID) && !pwalletMain->mapKeyMetadata[keyID].hdKeypath.empty())
|
||||
{
|
||||
ret.push_back(Pair("hdkeypath", pwalletMain->mapKeyMetadata[keyID].hdKeypath));
|
||||
ret.push_back(Pair("hdmasterkeyid", pwalletMain->mapKeyMetadata[keyID].hdMasterKeyID.GetHex()));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return ret;
|
||||
|
||||
@@ -2310,7 +2310,7 @@ UniValue getwalletinfo(const UniValue& params, bool fHelp)
|
||||
" \"keypoolsize\": xxxx, (numeric) how many new keys are pre-generated\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"
|
||||
" \"hdmasterkeyid\": \"<hash160>\", (string) the Hash160 of the hd master pubkey\n"
|
||||
" \"hdmasterkeyid\": \"<hash160>\", (string) the Hash160 of the HD master pubkey\n"
|
||||
"}\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("getwalletinfo", "")
|
||||
@@ -2332,7 +2332,7 @@ UniValue getwalletinfo(const UniValue& params, bool fHelp)
|
||||
obj.push_back(Pair("paytxfee", ValueFromAmount(payTxFee.GetFeePerK())));
|
||||
CKeyID masterKeyID = pwalletMain->GetHDChain().masterKeyID;
|
||||
if (!masterKeyID.IsNull())
|
||||
obj.push_back(Pair("hdmasterkeyid",masterKeyID.GetHex()));
|
||||
obj.push_back(Pair("hdmasterkeyid", masterKeyID.GetHex()));
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
@@ -130,6 +130,8 @@ CPubKey CWallet::GenerateNewKey()
|
||||
// childIndex | BIP32_HARDENED_KEY_LIMIT = derive childIndex in hardened child-index-range
|
||||
// example: 1 | BIP32_HARDENED_KEY_LIMIT == 0x80000001 == 2147483649
|
||||
externalChainChildKey.Derive(childKey, hdChain.nExternalChainCounter | BIP32_HARDENED_KEY_LIMIT);
|
||||
metadata.hdKeypath = "m/0'/0'/"+std::to_string(hdChain.nExternalChainCounter)+"'";
|
||||
metadata.hdMasterKeyID = hdChain.masterKeyID;
|
||||
// increment childkey index
|
||||
hdChain.nExternalChainCounter++;
|
||||
} while(HaveKey(childKey.key.GetPubKey().GetID()));
|
||||
|
||||
@@ -509,7 +509,7 @@ private:
|
||||
|
||||
void SyncMetaData(std::pair<TxSpends::iterator, TxSpends::iterator>);
|
||||
|
||||
/* the hd chain data model (external chain counters) */
|
||||
/* the HD chain data model (external chain counters) */
|
||||
CHDChain hdChain;
|
||||
|
||||
public:
|
||||
@@ -817,14 +817,14 @@ public:
|
||||
bool SelectCoinsForStaking(CAmount& nTargetValue, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, CAmount& nValueRet) const;
|
||||
void AvailableCoinsForStaking(std::vector<COutput>& vCoins) const;
|
||||
uint64_t GetStakeWeight() const;
|
||||
/* Set the hd chain model (chain child index counters) */
|
||||
/* Set the HD chain model (chain child index counters) */
|
||||
bool SetHDChain(const CHDChain& chain, bool memonly);
|
||||
const CHDChain& GetHDChain() { return hdChain; }
|
||||
|
||||
/* Generates a new HD master key (will not be activated) */
|
||||
CPubKey GenerateNewHDMasterKey();
|
||||
|
||||
/* 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) */
|
||||
bool SetHDMasterKey(const CPubKey& key);
|
||||
};
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ enum DBErrors
|
||||
DB_NEED_REWRITE
|
||||
};
|
||||
|
||||
/* simple hd chain data model */
|
||||
/* simple HD chain data model */
|
||||
class CHDChain
|
||||
{
|
||||
public:
|
||||
@@ -72,7 +72,9 @@ public:
|
||||
class CKeyMetadata
|
||||
{
|
||||
public:
|
||||
static const int CURRENT_VERSION=1;
|
||||
static const int VERSION_BASIC=1;
|
||||
static const int VERSION_WITH_HDDATA=10;
|
||||
static const int CURRENT_VERSION=VERSION_WITH_HDDATA;
|
||||
int nVersion;
|
||||
int64_t nCreateTime; // 0 means unknown
|
||||
std::string hdKeypath; //optional HD/bip32 keypath
|
||||
@@ -95,12 +97,18 @@ public:
|
||||
READWRITE(this->nVersion);
|
||||
nVersion = this->nVersion;
|
||||
READWRITE(nCreateTime);
|
||||
if (this->nVersion >= VERSION_WITH_HDDATA)
|
||||
{
|
||||
READWRITE(hdKeypath);
|
||||
READWRITE(hdMasterKeyID);
|
||||
}
|
||||
}
|
||||
|
||||
void SetNull()
|
||||
{
|
||||
nVersion = CKeyMetadata::CURRENT_VERSION;
|
||||
nCreateTime = 0;
|
||||
hdKeypath.clear();
|
||||
hdMasterKeyID.SetNull();
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user