Automatically add empty label for pubkey pair addresses.
authorCryptoManiac <balthazar@yandex.ru>
Fri, 11 Mar 2016 20:27:03 +0000 (23:27 +0300)
committerCryptoManiac <balthazar@yandex.ru>
Fri, 11 Mar 2016 20:27:03 +0000 (23:27 +0300)
src/init.cpp
src/rpcwallet.cpp

index 417b342..8fec3c6 100644 (file)
@@ -902,6 +902,15 @@ bool AppInit2()
         pwalletMain->SetDefaultKey(newDefaultKey);
         if (!pwalletMain->SetAddressBookName(pwalletMain->vchDefaultKey.GetID(), ""))
             strErrors << _("Cannot write default address") << "\n";
+
+        if (fTestNet || GetTime() < SMALLDATA_SWITCH_TIME) {
+            CMalleableKeyView keyView = pwalletMain->GenerateNewMalleableKey();
+            CMalleableKey mKey;
+            if (!pwalletMain->GetMalleableKey(keyView, mKey))
+                strErrors << _("Unable to generate new malleable key");
+            if (!pwalletMain->SetAddressBookName(CBitcoinAddress(keyView.GetMalleablePubKey()), ""))
+                strErrors << _("Cannot write default address") << "\n";
+        }
     }
 
     printf("%s", strErrors.str().c_str());
index 0d0946e..8c36836 100644 (file)
@@ -1893,7 +1893,7 @@ Value makekeypair(const Array& params, bool fHelp)
 
 Value newmalleablekey(const Array& params, bool fHelp)
 {
-    if (fHelp || params.size() > 0)
+    if (fHelp || params.size() > 1)
         throw runtime_error(
             "newmalleablekey\n"
             "Make a malleable public/private key pair.\n");
@@ -1901,6 +1901,11 @@ Value newmalleablekey(const Array& params, bool fHelp)
     if (!(fDebug || fTestNet) && GetTime() < SMALLDATA_SWITCH_TIME)
         throw runtime_error("This feature has been disabled for mainNet clients");
 
+    // Parse the account first so we don't generate a key if there's an error
+    string strAccount;
+    if (params.size() > 0)
+        strAccount = AccountFromValue(params[0]);
+
     CMalleableKeyView keyView = pwalletMain->GenerateNewMalleableKey();
 
     CMalleableKey mKey;
@@ -1908,11 +1913,14 @@ Value newmalleablekey(const Array& params, bool fHelp)
         throw runtime_error("Unable to generate new malleable key");
 
     CMalleablePubKey mPubKey = mKey.GetMalleablePubKey();
+    CBitcoinAddress address(mPubKey);
+
+    pwalletMain->SetAddressBookName(address, strAccount);
 
     Object result;
     result.push_back(Pair("PublicPair", mPubKey.ToString()));
     result.push_back(Pair("PublicBytes", HexStr(mPubKey.Raw())));
-    result.push_back(Pair("Address", CBitcoinAddress(mPubKey).ToString()));
+    result.push_back(Pair("Address", address.ToString()));
     result.push_back(Pair("KeyView", keyView.ToString()));
 
     return result;