mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-22 23:07:59 +01:00
Convert wallet to new serialization
This commit is contained in:
parent
65c589e45e
commit
ef17c03e07
4 changed files with 61 additions and 77 deletions
|
@ -43,15 +43,9 @@ public:
|
||||||
//! such as the various parameters to scrypt
|
//! such as the various parameters to scrypt
|
||||||
std::vector<unsigned char> vchOtherDerivationParameters;
|
std::vector<unsigned char> vchOtherDerivationParameters;
|
||||||
|
|
||||||
ADD_SERIALIZE_METHODS;
|
SERIALIZE_METHODS(CMasterKey, obj)
|
||||||
|
{
|
||||||
template <typename Stream, typename Operation>
|
READWRITE(obj.vchCryptedKey, obj.vchSalt, obj.nDerivationMethod, obj.nDeriveIterations, obj.vchOtherDerivationParameters);
|
||||||
inline void SerializationOp(Stream& s, Operation ser_action) {
|
|
||||||
READWRITE(vchCryptedKey);
|
|
||||||
READWRITE(vchSalt);
|
|
||||||
READWRITE(nDerivationMethod);
|
|
||||||
READWRITE(nDeriveIterations);
|
|
||||||
READWRITE(vchOtherDerivationParameters);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CMasterKey()
|
CMasterKey()
|
||||||
|
|
|
@ -110,38 +110,39 @@ public:
|
||||||
CKeyPool();
|
CKeyPool();
|
||||||
CKeyPool(const CPubKey& vchPubKeyIn, bool internalIn);
|
CKeyPool(const CPubKey& vchPubKeyIn, bool internalIn);
|
||||||
|
|
||||||
ADD_SERIALIZE_METHODS;
|
template<typename Stream>
|
||||||
|
void Serialize(Stream& s) const
|
||||||
template <typename Stream, typename Operation>
|
{
|
||||||
inline void SerializationOp(Stream& s, Operation ser_action) {
|
|
||||||
int nVersion = s.GetVersion();
|
int nVersion = s.GetVersion();
|
||||||
if (!(s.GetType() & SER_GETHASH))
|
if (!(s.GetType() & SER_GETHASH)) {
|
||||||
READWRITE(nVersion);
|
s << nVersion;
|
||||||
READWRITE(nTime);
|
|
||||||
READWRITE(vchPubKey);
|
|
||||||
if (ser_action.ForRead()) {
|
|
||||||
try {
|
|
||||||
READWRITE(fInternal);
|
|
||||||
}
|
}
|
||||||
catch (std::ios_base::failure&) {
|
s << nTime << vchPubKey << fInternal << m_pre_split;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Stream>
|
||||||
|
void Unserialize(Stream& s)
|
||||||
|
{
|
||||||
|
int nVersion = s.GetVersion();
|
||||||
|
if (!(s.GetType() & SER_GETHASH)) {
|
||||||
|
s >> nVersion;
|
||||||
|
}
|
||||||
|
s >> nTime >> vchPubKey;
|
||||||
|
try {
|
||||||
|
s >> fInternal;
|
||||||
|
} catch (std::ios_base::failure&) {
|
||||||
/* flag as external address if we can't read the internal boolean
|
/* flag as external address if we can't read the internal boolean
|
||||||
(this will be the case for any wallet before the HD chain split version) */
|
(this will be the case for any wallet before the HD chain split version) */
|
||||||
fInternal = false;
|
fInternal = false;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
READWRITE(m_pre_split);
|
s >> m_pre_split;
|
||||||
}
|
} catch (std::ios_base::failure&) {
|
||||||
catch (std::ios_base::failure&) {
|
|
||||||
/* flag as postsplit address if we can't read the m_pre_split boolean
|
/* flag as postsplit address if we can't read the m_pre_split boolean
|
||||||
(this will be the case for any wallet that upgrades to HD chain split) */
|
(this will be the case for any wallet that upgrades to HD chain split) */
|
||||||
m_pre_split = false;
|
m_pre_split = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
READWRITE(fInternal);
|
|
||||||
READWRITE(m_pre_split);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -98,15 +98,13 @@ public:
|
||||||
int nVersion;
|
int nVersion;
|
||||||
|
|
||||||
CHDChain() { SetNull(); }
|
CHDChain() { SetNull(); }
|
||||||
ADD_SERIALIZE_METHODS;
|
|
||||||
template <typename Stream, typename Operation>
|
SERIALIZE_METHODS(CHDChain, obj)
|
||||||
inline void SerializationOp(Stream& s, Operation ser_action)
|
|
||||||
{
|
{
|
||||||
READWRITE(this->nVersion);
|
READWRITE(obj.nVersion, obj.nExternalChainCounter, obj.seed_id);
|
||||||
READWRITE(nExternalChainCounter);
|
if (obj.nVersion >= VERSION_HD_CHAIN_SPLIT) {
|
||||||
READWRITE(seed_id);
|
READWRITE(obj.nInternalChainCounter);
|
||||||
if (this->nVersion >= VERSION_HD_CHAIN_SPLIT)
|
}
|
||||||
READWRITE(nInternalChainCounter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetNull()
|
void SetNull()
|
||||||
|
@ -142,21 +140,16 @@ public:
|
||||||
nCreateTime = nCreateTime_;
|
nCreateTime = nCreateTime_;
|
||||||
}
|
}
|
||||||
|
|
||||||
ADD_SERIALIZE_METHODS;
|
SERIALIZE_METHODS(CKeyMetadata, obj)
|
||||||
|
|
||||||
template <typename Stream, typename Operation>
|
|
||||||
inline void SerializationOp(Stream& s, Operation ser_action) {
|
|
||||||
READWRITE(this->nVersion);
|
|
||||||
READWRITE(nCreateTime);
|
|
||||||
if (this->nVersion >= VERSION_WITH_HDDATA)
|
|
||||||
{
|
{
|
||||||
READWRITE(hdKeypath);
|
READWRITE(obj.nVersion, obj.nCreateTime);
|
||||||
READWRITE(hd_seed_id);
|
if (obj.nVersion >= VERSION_WITH_HDDATA) {
|
||||||
|
READWRITE(obj.hdKeypath, obj.hd_seed_id);
|
||||||
}
|
}
|
||||||
if (this->nVersion >= VERSION_WITH_KEY_ORIGIN)
|
if (obj.nVersion >= VERSION_WITH_KEY_ORIGIN)
|
||||||
{
|
{
|
||||||
READWRITE(key_origin);
|
READWRITE(obj.key_origin);
|
||||||
READWRITE(has_key_origin);
|
READWRITE(obj.has_key_origin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -98,26 +98,22 @@ public:
|
||||||
int32_t next_index = 0; // Position of the next item to generate
|
int32_t next_index = 0; // Position of the next item to generate
|
||||||
DescriptorCache cache;
|
DescriptorCache cache;
|
||||||
|
|
||||||
ADD_SERIALIZE_METHODS;
|
void DeserializeDescriptor(const std::string& str)
|
||||||
|
{
|
||||||
template <typename Stream, typename Operation>
|
|
||||||
inline void SerializationOp(Stream& s, Operation ser_action) {
|
|
||||||
if (ser_action.ForRead()) {
|
|
||||||
std::string desc;
|
|
||||||
std::string error;
|
std::string error;
|
||||||
READWRITE(desc);
|
|
||||||
FlatSigningProvider keys;
|
FlatSigningProvider keys;
|
||||||
descriptor = Parse(desc, keys, error, true);
|
descriptor = Parse(str, keys, error, true);
|
||||||
if (!descriptor) {
|
if (!descriptor) {
|
||||||
throw std::ios_base::failure("Invalid descriptor: " + error);
|
throw std::ios_base::failure("Invalid descriptor: " + error);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
READWRITE(descriptor->ToString());
|
|
||||||
}
|
}
|
||||||
READWRITE(creation_time);
|
|
||||||
READWRITE(next_index);
|
SERIALIZE_METHODS(WalletDescriptor, obj)
|
||||||
READWRITE(range_start);
|
{
|
||||||
READWRITE(range_end);
|
std::string descriptor_str;
|
||||||
|
SER_WRITE(obj, descriptor_str = obj.descriptor->ToString());
|
||||||
|
READWRITE(descriptor_str, obj.creation_time, obj.next_index, obj.range_start, obj.range_end);
|
||||||
|
SER_READ(obj, obj.DeserializeDescriptor(descriptor_str));
|
||||||
}
|
}
|
||||||
|
|
||||||
WalletDescriptor() {}
|
WalletDescriptor() {}
|
||||||
|
|
Loading…
Add table
Reference in a new issue