ListMalleablePubKeys method
[novacoin.git] / src / rpcwallet.cpp
index ad20062..6a7a3b1 100644 (file)
@@ -1870,9 +1870,13 @@ Value newmalleablekey(const Array& params, bool fHelp)
     malleableKey.MakeNewKeys();
     CMalleablePubKey malleablePubKey = malleableKey.GetMalleablePubKey();
 
+    CDataStream ssPublicBytes(SER_NETWORK, PROTOCOL_VERSION);
+    ssPublicBytes << malleablePubKey;
+
     Object result;
     result.push_back(Pair("PrivatePair", malleableKey.ToString()));
     result.push_back(Pair("PublicPair", malleablePubKey.ToString()));
+    result.push_back(Pair("PublicBytes", HexStr(ssPublicBytes.begin(), ssPublicBytes.end())));
 
     return result;
 }
@@ -1889,9 +1893,10 @@ Value adjustmalleablekey(const Array& params, bool fHelp)
 
     CKey privKeyVariant;
     CPubKey vchPubKeyVariant = CPubKey(ParseHex(params[1].get_str()));
-    CPubKey vchR = CPubKey(ParseHex(params[2].get_str()));
 
-    if (!malleableKey.CheckKeyVariant(vchR,vchPubKeyVariant, privKeyVariant)) {
+    CPubKey R(ParseHex(params[2].get_str()));
+
+    if (!malleableKey.CheckKeyVariant(R,vchPubKeyVariant, privKeyVariant)) {
         throw runtime_error("Unable to calculate the private key");
     }
 
@@ -1911,8 +1916,14 @@ Value adjustmalleablepubkey(const Array& params, bool fHelp)
             "adjustmalleablepubkey <Malleable public key data>\n"
             "Calculate new public key using provided malleable public key data.\n");
 
+    string pubKeyPair = params[0].get_str();
     CMalleablePubKey malleablePubKey;
-    malleablePubKey.SetString(params[0].get_str());
+
+    if (pubKeyPair.size() == 138) {
+        CDataStream ssPublicBytes(ParseHex(pubKeyPair), SER_NETWORK, PROTOCOL_VERSION);
+        ssPublicBytes >> malleablePubKey;
+    } else
+        malleablePubKey.SetString(pubKeyPair);
 
     CPubKey R, vchPubKeyVariant;
     malleablePubKey.GetVariant(R, vchPubKeyVariant);
@@ -1922,5 +1933,25 @@ Value adjustmalleablepubkey(const Array& params, bool fHelp)
     result.push_back(Pair("PubkeyVariant", HexStr(vchPubKeyVariant.Raw())));
     result.push_back(Pair("KeyVariantID", CBitcoinAddress(vchPubKeyVariant.GetID()).ToString()));
 
+
+    return result;
+}
+
+Value listmalleablepubkeys(const Array& params, bool fHelp)
+{
+    if (fHelp || params.size() != 0)
+        throw runtime_error(
+            "listmalleablepubkeys\n"
+            "Get list of malleable public keys.\n");
+
+    std::list<CMalleablePubKey> keyList;
+    pwalletMain->ListMalleablePubKeys(keyList);
+
+    Array result;
+    BOOST_FOREACH(const CMalleablePubKey &key, keyList)
+    {
+        result.push_back(key.ToString());
+    }
+
     return result;
 }