Code style fix (no "tab" symbol).
[novacoin.git] / src / rpcwallet.cpp
index 0c27a90..bab881d 100644 (file)
@@ -329,17 +329,9 @@ Value sendtoaddress(const Array& params, bool fHelp)
 
     CBitcoinAddress address(strAddress);
     if (address.IsValid())
-        scriptPubKey.SetDestination(address.Get());
+        scriptPubKey.SetAddress(address);
     else
-    {
-        CMalleablePubKey mpk(strAddress);
-        if (!mpk.IsValid())
-            throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid NovaCoin address");
-
-        CPubKey R, pubKeyVariant;
-        mpk.GetVariant(R, pubKeyVariant);
-        scriptPubKey.SetDestination(R, pubKeyVariant);
-    }
+        throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid NovaCoin address");
 
     // Amount
     int64_t nAmount = AmountFromValue(params[1]);
@@ -471,16 +463,14 @@ Value getreceivedbyaddress(const Array& params, bool fHelp)
 {
     if (fHelp || params.size() < 1 || params.size() > 2)
         throw runtime_error(
-            "getreceivedbyaddress <novacoinaddress> [minconf=1]\n"
-            "Returns the total amount received by <novacoinaddress> in transactions with at least [minconf] confirmations.");
+                "getreceivedbyaddress <novacoinaddress> [minconf=1]\n"
+                "Returns the total amount received by <novacoinaddress> in transactions with at least [minconf] confirmations.");
 
     // Bitcoin address
     CBitcoinAddress address = CBitcoinAddress(params[0].get_str());
-    CScript scriptPubKey;
     if (!address.IsValid())
         throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid NovaCoin address");
-    scriptPubKey.SetDestination(address.Get());
-    if (!IsMine(*pwalletMain,scriptPubKey))
+    if (!IsMine(*pwalletMain,address))
         return 0.0;
 
     // Minimum confirmations
@@ -488,24 +478,26 @@ Value getreceivedbyaddress(const Array& params, bool fHelp)
     if (params.size() > 1)
         nMinDepth = params[1].get_int();
 
-    // Tally
     int64_t nAmount = 0;
     for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
     {
         const CWalletTx& wtx = (*it).second;
         if (wtx.IsCoinBase() || wtx.IsCoinStake() || !wtx.IsFinal())
             continue;
-
         BOOST_FOREACH(const CTxOut& txout, wtx.vout)
-            if (txout.scriptPubKey == scriptPubKey)
+        {
+            CBitcoinAddress addressRet;
+            if (!pwalletMain->ExtractAddress(txout.scriptPubKey, addressRet))
+                continue;
+            if (addressRet == address)
                 if (wtx.GetDepthInMainChain() >= nMinDepth)
                     nAmount += txout.nValue;
+        }
     }
 
     return  ValueFromAmount(nAmount);
 }
 
-
 void GetAccountAddresses(string strAccount, set<CTxDestination>& setAddress)
 {
     BOOST_FOREACH(const PAIRTYPE(CTxDestination, string)& item, pwalletMain->mapAddressBook)
@@ -716,17 +708,10 @@ Value sendfrom(const Array& params, bool fHelp)
 
     CBitcoinAddress address(strAddress);
     if (address.IsValid())
-        scriptPubKey.SetDestination(address.Get());
+        scriptPubKey.SetAddress(address);
     else
-    {
-        CMalleablePubKey mpk(strAddress);
-        if (!mpk.IsValid())
-            throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid NovaCoin address");
+        throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid NovaCoin address");
 
-        CPubKey R, pubKeyVariant;
-        mpk.GetVariant(R, pubKeyVariant);
-        scriptPubKey.SetDestination(R, pubKeyVariant);
-    }
 
     int64_t nAmount = AmountFromValue(params[2]);
 
@@ -789,12 +774,15 @@ Value sendmany(const Array& params, bool fHelp)
         if (!address.IsValid())
             throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("Invalid NovaCoin address: ")+s.name_);
 
-        if (setAddress.count(address))
-            throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ")+s.name_);
-        setAddress.insert(address);
+        if (!address.IsPair())
+        {
+            if (setAddress.count(address))
+                throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ")+s.name_);
+            setAddress.insert(address);
+        }
 
         CScript scriptPubKey;
-        scriptPubKey.SetDestination(address.Get());
+        scriptPubKey.SetAddress(address);
         int64_t nAmount = AmountFromValue(s.value_);
 
         if (nAmount < nMinimumInputValue)
@@ -1747,18 +1735,34 @@ Value validateaddress(const Array& params, bool fHelp)
     ret.push_back(Pair("isvalid", isValid));
     if (isValid)
     {
-        CTxDestination dest = address.Get();
-        string currentAddress = address.ToString();
-        ret.push_back(Pair("address", currentAddress));
-        isminetype mine = pwalletMain ? IsMine(*pwalletMain, dest) : MINE_NO;
-        ret.push_back(Pair("ismine", mine != MINE_NO));
-        if (mine != MINE_NO) {
-            ret.push_back(Pair("watchonly", mine == MINE_WATCH_ONLY));
-            Object detail = boost::apply_visitor(DescribeAddressVisitor(mine), dest);
-            ret.insert(ret.end(), detail.begin(), detail.end());
+        if (address.IsPair())
+        {
+            CMalleablePubKey mpk;
+            mpk.setvch(address.GetData());
+            ret.push_back(Pair("ispair", true));
+
+            CMalleableKeyView view;
+            bool isMine = pwalletMain->GetMalleableView(mpk, view);
+            ret.push_back(Pair("ismine", isMine));
+
+            if (isMine)
+                ret.push_back(Pair("KeyView", view.ToString()));
+        }
+        else
+        {
+            CTxDestination dest = address.Get();
+            string currentAddress = address.ToString();
+            ret.push_back(Pair("address", currentAddress));
+            isminetype mine = pwalletMain ? IsMine(*pwalletMain, dest) : MINE_NO;
+            ret.push_back(Pair("ismine", mine != MINE_NO));
+            if (mine != MINE_NO) {
+                ret.push_back(Pair("watchonly", mine == MINE_WATCH_ONLY));
+                Object detail = boost::apply_visitor(DescribeAddressVisitor(mine), dest);
+                ret.insert(ret.end(), detail.begin(), detail.end());
+            }
+            if (pwalletMain->mapAddressBook.count(dest))
+                ret.push_back(Pair("account", pwalletMain->mapAddressBook[dest]));
         }
-        if (pwalletMain->mapAddressBook.count(dest))
-            ret.push_back(Pair("account", pwalletMain->mapAddressBook[dest]));
     }
     return ret;
 }
@@ -1858,7 +1862,7 @@ Value resendtx(const Array& params, bool fHelp)
             "Re-send unconfirmed transactions.\n"
         );
 
-    ResendWalletTransactions();
+    ResendWalletTransactions(true);
 
     return Value::null;
 }
@@ -1896,7 +1900,7 @@ Value newmalleablekey(const Array& params, bool fHelp)
             "newmalleablekey\n"
             "Make a malleable public/private key pair.\n");
 
-    if (!fTestNet && GetTime() < SMALLDATA_SWITCH_TIME)
+    if (!(fDebug || fTestNet) && GetTime() < SMALLDATA_SWITCH_TIME)
         throw runtime_error("This feature has been disabled for mainNet clients");
 
     CMalleableKeyView keyView = pwalletMain->GenerateNewMalleableKey();
@@ -1905,30 +1909,13 @@ Value newmalleablekey(const Array& params, bool fHelp)
     if (!pwalletMain->GetMalleableKey(keyView, mKey))
         throw runtime_error("Unable to generate new malleable key");
 
-    Object result;
-    result.push_back(Pair("PublicPair", mKey.GetMalleablePubKey().ToString()));
-    result.push_back(Pair("KeyView", keyView.ToString()));
-
-    return result;
-}
-
-Value dumpmalleablekey(const Array& params, bool fHelp)
-{
-    if (fHelp || params.size() != 1)
-        throw runtime_error (
-            "dumpmalleablekey <Key view>\n"
-            "Dump the private and public key pairs, which correspond to provided key view.\n");
-
-    CMalleableKey mKey;
-    CMalleableKeyView keyView;
-    keyView.SetString(params[0].get_str());
-
-    if (!pwalletMain->GetMalleableKey(keyView, mKey))
-        throw runtime_error("There is no such item in the wallet");
+    CMalleablePubKey mPubKey = mKey.GetMalleablePubKey();
 
     Object result;
-    result.push_back(Pair("PrivatePair", mKey.ToString()));
-    result.push_back(Pair("PublicPair", mKey.GetMalleablePubKey().ToString()));
+    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("KeyView", keyView.ToString()));
 
     return result;
 }
@@ -1971,9 +1958,8 @@ Value adjustmalleablepubkey(const Array& params, bool fHelp)
     string pubKeyPair = params[0].get_str();
     CMalleablePubKey malleablePubKey;
 
-    if (pubKeyPair.size() == 138) {
-        CDataStream ssPublicBytes(ParseHex(pubKeyPair), SER_NETWORK, PROTOCOL_VERSION);
-        ssPublicBytes >> malleablePubKey;
+    if (pubKeyPair.size() == 136) {
+        malleablePubKey.setvch(ParseHex(pubKeyPair));
     } else
         malleablePubKey.SetString(pubKeyPair);