From b0bf9eb77c777c42dcdb59f43609ad07117be8ad Mon Sep 17 00:00:00 2001 From: Pavel Vasin Date: Tue, 14 Mar 2017 04:41:29 +0300 Subject: [PATCH] add rpc command burn --- src/rpcclient.cpp | 1 + src/rpcserver.cpp | 1 + src/rpcserver.h | 1 + src/rpcwallet.cpp | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+) diff --git a/src/rpcclient.cpp b/src/rpcclient.cpp index 4d1384ee64da7..d60e73243dec9 100644 --- a/src/rpcclient.cpp +++ b/src/rpcclient.cpp @@ -106,6 +106,7 @@ static const CRPCConvertParam vRPCConvertParams[] = { "stop", 0 }, { "getaddednodeinfo", 0 }, { "sendtoaddress", 1 }, + { "burn", 1 }, { "settxfee", 0 }, { "getreceivedbyaddress", 1 }, { "getreceivedbyaccount", 1 }, diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index b630a1b25ec42..a5564b69c9e07 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -256,6 +256,7 @@ static const CRPCCommand vRPCCommands[] = { "getaccount", &getaccount, false, false, true }, { "getaddressesbyaccount", &getaddressesbyaccount, true, false, true }, { "sendtoaddress", &sendtoaddress, false, false, true }, + { "burn", &burn, false, false, true }, { "getreceivedbyaddress", &getreceivedbyaddress, false, false, true }, { "getreceivedbyaccount", &getreceivedbyaccount, false, false, true }, { "listreceivedbyaddress", &listreceivedbyaddress, false, false, true }, diff --git a/src/rpcserver.h b/src/rpcserver.h index 5a9b0bddf3944..e7487ff1e31cd 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -126,6 +126,7 @@ extern json_spirit::Value setaccount(const json_spirit::Array& params, bool fHel extern json_spirit::Value getaccount(const json_spirit::Array& params, bool fHelp); 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 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); diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index a5f1cc9067f68..4b986c12e1bde 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -291,6 +291,42 @@ Value sendtoaddress(const Array& params, bool fHelp) return wtx.GetHash().GetHex(); } +Value burn(const Array& params, bool fHelp) +{ + if (fHelp || params.size() < 1 || params.size() > 2) + throw runtime_error( + "burn [hex string]\n" + " is a real and is rounded to the nearest 0.00000001" + + HelpRequiringPassphrase()); + + CScript scriptPubKey; + + if (params.size() > 1) { + vector data; + if (params[1].get_str().size() > 0){ + data = ParseHexV(params[1], "data"); + } else { + // Empty data is valid + } + scriptPubKey = CScript() << OP_RETURN << data; + } else { + scriptPubKey = CScript() << OP_RETURN; + } + + // Amount + int64_t nAmount = AmountFromValue(params[0]); + + if (pwalletMain->IsLocked()) + throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first."); + + CWalletTx wtx; + string strError = pwalletMain->SendMoney(scriptPubKey, nAmount, wtx); + if (strError != "") + throw JSONRPCError(RPC_WALLET_ERROR, strError); + + return wtx.GetHash().GetHex(); +} + Value listaddressgroupings(const Array& params, bool fHelp) { if (fHelp)