Commit 884b05ae authored by Pavel Vasin's avatar Pavel Vasin

rpc: add burnwallet

parent 4897c38a
......@@ -107,6 +107,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "getaddednodeinfo", 0 },
{ "sendtoaddress", 1 },
{ "burn", 0 },
{ "burnwallet", 1 },
{ "settxfee", 0 },
{ "getreceivedbyaddress", 1 },
{ "getreceivedbyaccount", 1 },
......
......@@ -259,6 +259,7 @@ static const CRPCCommand vRPCCommands[] =
{ "getaddressesbyaccount", &getaddressesbyaccount, true, false, true },
{ "sendtoaddress", &sendtoaddress, false, false, true },
{ "burn", &burn, false, false, true },
{ "burnwallet", &burnwallet, false, false, true },
{ "getreceivedbyaddress", &getreceivedbyaddress, false, false, true },
{ "getreceivedbyaccount", &getreceivedbyaccount, false, false, true },
{ "listreceivedbyaddress", &listreceivedbyaddress, false, false, true },
......
......@@ -127,6 +127,7 @@ extern json_spirit::Value getaccount(const json_spirit::Array& params, bool fHel
extern json_spirit::Value getaddressesbyaccount(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value sendtoaddress(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value burn(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value burnwallet(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value signmessage(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value verifymessage(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getreceivedbyaddress(const json_spirit::Array& params, bool fHelp);
......
......@@ -281,8 +281,7 @@ Value sendtoaddress(const Array& params, bool fHelp)
if (params.size() > 3 && params[3].type() != null_type && !params[3].get_str().empty())
wtx.mapValue["to"] = params[3].get_str();
if (pwalletMain->IsLocked())
throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first.");
EnsureWalletIsUnlocked();
string strError = pwalletMain->SendMoneyToDestination(address.Get(), nAmount, wtx);
if (strError != "")
......@@ -316,8 +315,7 @@ Value burn(const Array& params, bool fHelp)
// Amount
int64_t nAmount = AmountFromValue(params[0], true);
if (pwalletMain->IsLocked())
throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first.");
EnsureWalletIsUnlocked();
CWalletTx wtx;
string strError = pwalletMain->SendMoney(scriptPubKey, nAmount, wtx);
......@@ -327,6 +325,62 @@ Value burn(const Array& params, bool fHelp)
return wtx.GetHash().GetHex();
}
Value burnwallet(const Array& params, bool fHelp)
{
if (fHelp || params.size() < 1 || params.size() > 2)
throw runtime_error(
"burnwallet [hex string] [force]"
+ HelpRequiringPassphrase());
CScript scriptPubKey;
if (params.size() > 0) {
vector<unsigned char> data;
if (params[0].get_str().size() > 0){
data = ParseHexV(params[0], "data");
} else {
// Empty data is valid
}
scriptPubKey = CScript() << OP_RETURN << data;
} else {
scriptPubKey = CScript() << OP_RETURN;
}
bool fForce = false;
if (params.size() > 1)
fForce = params[1].get_bool();
EnsureWalletIsUnlocked();
if (!fForce) {
if (scriptPubKey.size() <= 32)
throw JSONRPCError(RPC_WALLET_ERROR, "Warning: small data");
if (pwalletMain->GetUnconfirmedBalance() != 0)
throw JSONRPCError(RPC_WALLET_ERROR, "Warning: Unconfirmed Balance != 0");
if (pwalletMain->GetImmatureBalance() != 0)
throw JSONRPCError(RPC_WALLET_ERROR, "Warning: Immature Balance != 0");
if (pwalletMain->GetStake() != 0)
throw JSONRPCError(RPC_WALLET_ERROR, "Warning: Stake Balance != 0");
}
int64_t nAmount = pwalletMain->GetBalance();
std::vector<std::pair<CScript, int64_t> > vecSend;
vecSend.push_back(make_pair(scriptPubKey, nAmount));
CWalletTx wtx;
CReserveKey keyChange(pwalletMain);
int64_t nFeeRequired = 0;
pwalletMain->CreateTransaction(vecSend, wtx, keyChange, nFeeRequired);
vecSend[0].second -= nFeeRequired;
if (!pwalletMain->CreateTransaction(vecSend, wtx, keyChange, nFeeRequired))
throw JSONRPCError(RPC_WALLET_ERROR, "Transaction creation failed");
if (!pwalletMain->CommitTransaction(wtx, keyChange))
throw JSONRPCError(RPC_WALLET_ERROR, "Transaction commit failed");
return wtx.GetHash().GetHex();
}
Value listaddressgroupings(const Array& params, bool fHelp)
{
if (fHelp)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment