|
|
@@ -73,12 +73,22 @@ class CKeyMetadata |
|
|
{
|
|
|
public:
|
|
|
static const int VERSION_BASIC=1;
|
|
|
+ static const int VERSION_WITH_FLAGS=2;
|
|
|
static const int VERSION_WITH_HDDATA=10;
|
|
|
- static const int CURRENT_VERSION=VERSION_WITH_HDDATA;
|
|
|
+ static const int VERSION_WITH_META=11;
|
|
|
+ static const int CURRENT_VERSION=VERSION_WITH_META;
|
|
|
+
|
|
|
+ static const uint8_t KEY_ORIGIN_UNSET = 0x0000;
|
|
|
+ static const uint8_t KEY_ORIGIN_UNKNOWN = 0x0001;
|
|
|
+ static const uint8_t KEY_ORIGIN_IMPORTED = 0x0002;
|
|
|
+ static const uint8_t KEY_ORIGIN_UNENC_WALLET = 0x0004;
|
|
|
+ static const uint8_t KEY_ORIGIN_ENC_WALLET = 0x0008;
|
|
|
+
|
|
|
int nVersion;
|
|
|
int64_t nCreateTime; // 0 means unknown
|
|
|
std::string hdKeypath; //optional HD/bip32 keypath
|
|
|
CKeyID hdMasterKeyID; //id of the HD masterkey used to derive this key
|
|
|
+ std::map<std::string, std::string> mapMeta;
|
|
|
|
|
|
CKeyMetadata()
|
|
|
{
|
|
|
@@ -94,12 +104,30 @@ class CKeyMetadata |
|
|
|
|
|
template <typename Stream, typename Operation>
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action) {
|
|
|
+ if (ser_action.ForRead()) {
|
|
|
+ SetNull();
|
|
|
+ }
|
|
|
READWRITE(this->nVersion);
|
|
|
READWRITE(nCreateTime);
|
|
|
if (this->nVersion >= VERSION_WITH_HDDATA)
|
|
|
{
|
|
|
READWRITE(hdKeypath);
|
|
|
READWRITE(hdMasterKeyID);
|
|
|
+ if (nVersion >= VERSION_WITH_META) {
|
|
|
+ READWRITE(mapMeta);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ if (nVersion >= VERSION_WITH_FLAGS)
|
|
|
+ {
|
|
|
+ uint8_t keyFlags;
|
|
|
+ if (!ser_action.ForRead()) {
|
|
|
+ keyFlags = GetKeyOrigin();
|
|
|
+ }
|
|
|
+ READWRITE(keyFlags);
|
|
|
+ if (ser_action.ForRead()) {
|
|
|
+ SetKeyOrigin(keyFlags);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -109,6 +137,30 @@ class CKeyMetadata |
|
|
nCreateTime = 0;
|
|
|
hdKeypath.clear();
|
|
|
hdMasterKeyID.SetNull();
|
|
|
+ mapMeta.clear();
|
|
|
+ }
|
|
|
+
|
|
|
+ void SetKeyOrigin(const uint8_t n) {
|
|
|
+ const char * const p = (const char *)&n;
|
|
|
+ const auto it = mapMeta.find("origin");
|
|
|
+ if (it == mapMeta.end()) {
|
|
|
+ std::string s(p, 1);
|
|
|
+ mapMeta["origin"] = s;
|
|
|
+ } else {
|
|
|
+ // Avoid losing additional bytes, which might be future extension
|
|
|
+ if (it->second.size() < 1) {
|
|
|
+ it->second.resize(1);
|
|
|
+ }
|
|
|
+ it->second[0] = *p;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ uint8_t GetKeyOrigin() const {
|
|
|
+ const auto it = mapMeta.find("origin");
|
|
|
+ if (it == mapMeta.end() || it->second.size() < 1) {
|
|
|
+ return KEY_ORIGIN_UNSET;
|
|
|
+ }
|
|
|
+ return it->second[0];
|
|
|
}
|
|
|
};
|
|
|
|
|
|
|