X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Frpcwallet.cpp;h=ff627c11adfdb21b1ed611a87dca8b9a2d7567c1;hb=0a18ce8f4cd1a723f50333945d94c84b45c8d56b;hp=22beb606d513390a38a90e9f752d675c93733692;hpb=a4bd78df61a14ec83f4a2f71edb0e18b434a8779;p=novacoin.git diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index 22beb60..ff627c1 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -323,9 +323,23 @@ Value sendtoaddress(const Array& params, bool fHelp) " is a real and is rounded to the nearest " + FormatMoney(nMinimumInputValue) + HelpRequiringPassphrase()); - CBitcoinAddress address(params[0].get_str()); - if (!address.IsValid()) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid NovaCoin address"); + // Parse address + CScript scriptPubKey; + string strAddress = params[0].get_str(); + + CBitcoinAddress address(strAddress); + if (address.IsValid()) + scriptPubKey.SetDestination(address.Get()); + 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); + } // Amount int64_t nAmount = AmountFromValue(params[1]); @@ -343,7 +357,7 @@ Value sendtoaddress(const Array& params, bool fHelp) if (pwalletMain->IsLocked()) throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first."); - string strError = pwalletMain->SendMoneyToDestination(address.Get(), nAmount, wtx); + string strError = pwalletMain->SendMoney(scriptPubKey, nAmount, wtx); if (strError != "") throw JSONRPCError(RPC_WALLET_ERROR, strError); @@ -695,9 +709,25 @@ Value sendfrom(const Array& params, bool fHelp) + HelpRequiringPassphrase()); string strAccount = AccountFromValue(params[0]); - CBitcoinAddress address(params[1].get_str()); - if (!address.IsValid()) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid NovaCoin address"); + + // Parse address + CScript scriptPubKey; + string strAddress = params[0].get_str(); + + CBitcoinAddress address(strAddress); + if (address.IsValid()) + scriptPubKey.SetDestination(address.Get()); + 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); + } + int64_t nAmount = AmountFromValue(params[2]); if (nAmount < nMinimumInputValue) @@ -722,7 +752,7 @@ Value sendfrom(const Array& params, bool fHelp) throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds"); // Send - string strError = pwalletMain->SendMoneyToDestination(address.Get(), nAmount, wtx); + string strError = pwalletMain->SendMoney(scriptPubKey, nAmount, wtx); if (strError != "") throw JSONRPCError(RPC_WALLET_ERROR, strError); @@ -1755,7 +1785,7 @@ Value reservebalance(const Array& params, bool fHelp) nAmount = (nAmount / CENT) * CENT; // round to cent if (nAmount < 0) throw runtime_error("amount cannot be negative.\n"); - mapArgs["-reservebalance"] = FormatMoney(nAmount).c_str(); + mapArgs["-reservebalance"] = FormatMoney(nAmount); } else { @@ -1866,17 +1896,44 @@ Value newmalleablekey(const Array& params, bool fHelp) "newmalleablekey\n" "Make a malleable public/private key pair.\n"); - CMalleableKey malleableKey; - malleableKey.MakeNewKeys(); - CMalleablePubKey malleablePubKey = malleableKey.GetMalleablePubKey(); + if (!fTestNet && GetTime() < SMALLDATA_SWITCH_TIME) + throw runtime_error("This feature has been disabled for mainNet clients"); - CDataStream ssPublicBytes(SER_NETWORK, PROTOCOL_VERSION); - ssPublicBytes << malleablePubKey; + CMalleableKeyView keyView = pwalletMain->GenerateNewMalleableKey(); + + CMalleableKey mKey; + if (!pwalletMain->GetMalleableKey(keyView, mKey)) + throw runtime_error("Unable to generate new malleable key"); 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()))); + result.push_back(Pair("PublicPair", mKey.GetMalleablePubKey().ToString())); + result.push_back(Pair("KeyView", keyView.ToString())); + + return result; +} + +Value validatemalleablepubkey(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 1) + throw runtime_error( + "validatemalleablekey \n" + "Check the validity and ownership for priovided malleable public key.\n"); + + CMalleablePubKey mpk; + bool isValid = mpk.SetString(params[0].get_str()); + + Object result; + result.push_back(Pair("isvalid", isValid)); + + if (isValid) + { + CMalleableKeyView view; + bool isMine = pwalletMain->GetMalleableView(mpk, view); + result.push_back(Pair("ismine", isMine)); + + if (isMine) + result.push_back(Pair("KeyView", view.ToString())); + } return result; } @@ -1893,9 +1950,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"); } @@ -1934,3 +1992,23 @@ Value adjustmalleablepubkey(const Array& params, bool fHelp) return result; } + +Value listmalleableviews(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "listmalleableviews\n" + "Get list of views for generated malleable keys.\n"); + + std::list keyViewList; + pwalletMain->ListMalleableViews(keyViewList); + + Array result; + BOOST_FOREACH(const CMalleableKeyView &keyView, keyViewList) + { + result.push_back(keyView.ToString()); + } + + return result; +} +