Merge pull request #361 from svost/master
[novacoin.git] / src / rpcwallet.cpp
index 09bacfc..757e7f4 100644 (file)
@@ -350,7 +350,7 @@ Value sendtoaddress(const Array& params, bool fHelp)
         throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first.");
 
     string strError = pwalletMain->SendMoney(scriptPubKey, nAmount, wtx);
-    if (strError != "")
+    if (!strError.empty())
         throw JSONRPCError(RPC_WALLET_ERROR, strError);
 
     return wtx.GetHash().GetHex();
@@ -738,7 +738,7 @@ Value sendfrom(const Array& params, bool fHelp)
 
     // Send
     string strError = pwalletMain->SendMoney(scriptPubKey, nAmount, wtx);
-    if (strError != "")
+    if (!strError.empty())
         throw JSONRPCError(RPC_WALLET_ERROR, strError);
 
     return wtx.GetHash().GetHex();
@@ -1069,7 +1069,7 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe
     bool involvesWatchonly = wtx.IsFromMe(MINE_WATCH_ONLY);
 
     // Generated blocks assigned to account ""
-    if ((nGeneratedMature+nGeneratedImmature) != 0 && (fAllAccounts || strAccount == ""))
+    if ((nGeneratedMature+nGeneratedImmature) != 0 && (fAllAccounts || strAccount.empty()))
     {
         Object entry;
         entry.push_back(Pair("account", string("")));
@@ -1744,6 +1744,7 @@ Value validateaddress(const Array& params, bool fHelp)
             CMalleableKeyView view;
             bool isMine = pwalletMain->GetMalleableView(mpk, view);
             ret.push_back(Pair("ismine", isMine));
+            ret.push_back(Pair("PubkeyPair", mpk.ToString()));
 
             if (isMine)
                 ret.push_back(Pair("KeyView", view.ToString()));
@@ -1867,6 +1868,29 @@ Value resendtx(const Array& params, bool fHelp)
     return Value::null;
 }
 
+Value resendwallettransactions(const Array& params, bool fHelp)
+{
+    if (fHelp || params.size() != 0)
+        throw runtime_error(
+            "resendwallettransactions\n"
+            "Immediately re-broadcast unconfirmed wallet transactions to all peers.\n"
+            "Intended only for testing; the wallet code periodically re-broadcasts\n"
+            "automatically.\n"
+            "Returns array of transaction ids that were re-broadcast.\n"
+            );
+
+    LOCK2(cs_main, pwalletMain->cs_wallet);
+
+    std::vector<uint256> txids = pwalletMain->ResendWalletTransactionsBefore(GetTime());
+    Array result;
+    BOOST_FOREACH(const uint256& txid, txids)
+    {
+        result.push_back(txid.ToString());
+    }
+    return result;
+}
+
+
 // Make a public-private key pair
 Value makekeypair(const Array& params, bool fHelp)
 {
@@ -1958,16 +1982,34 @@ Value adjustmalleablepubkey(const Array& params, bool fHelp)
 {
     if (fHelp || params.size() > 2 || params.size() == 0)
         throw runtime_error(
-            "adjustmalleablepubkey <Malleable public key data>\n"
-            "Calculate new public key using provided malleable public key data.\n");
+            "adjustmalleablepubkey <Malleable address, key view or public key pair>\n"
+            "Calculate new public key using provided data.\n");
 
-    string pubKeyPair = params[0].get_str();
+    string strData = params[0].get_str();
     CMalleablePubKey malleablePubKey;
 
-    if (pubKeyPair.size() == 136) {
-        malleablePubKey.setvch(ParseHex(pubKeyPair));
-    } else
-        malleablePubKey.SetString(pubKeyPair);
+    do
+    {
+        CBitcoinAddress addr(strData);
+        if (addr.IsValid() && addr.IsPair())
+        {
+            // Initialize malleable pubkey with address data
+            malleablePubKey = CMalleablePubKey(addr.GetData());
+            break;
+        }
+        CMalleableKeyView viewTmp(strData);
+        if (viewTmp.IsValid())
+        {
+            // Shazaam, we have a valid key view here.
+            malleablePubKey = viewTmp.GetMalleablePubKey();
+            break;
+        }
+        if (malleablePubKey.SetString(strData))
+            break; // A valid public key pair
+
+        throw runtime_error("Though your data seems a valid Base58 string, we were unable to recognize it.");
+    }
+    while(false);
 
     CPubKey R, vchPubKeyVariant;
     malleablePubKey.GetVariant(R, vchPubKeyVariant);