add darksend rpc, fixed bug with mass block download

This commit is contained in:
Evan 2014-04-09 04:31:42 -07:00
parent 5d26a2db7f
commit 760dd088e8
11 changed files with 124 additions and 56 deletions

View File

@ -281,6 +281,7 @@ SOURCES += src/qt/bitcoin.cpp \
src/qt/walletstack.cpp \
src/qt/walletframe.cpp \
src/bitcoinrpc.cpp \
src/rpcdarksend.cpp \
src/rpcdump.cpp \
src/rpcnet.cpp \
src/rpcmining.cpp \

View File

@ -206,6 +206,9 @@ static const CRPCCommand vRPCCommands[] =
{ "getpeerinfo", &getpeerinfo, true, false, false },
{ "addnode", &addnode, true, true, false },
{ "darksendsub", &darksendsub, true, true, false },
{ "getpoolinfo", &getpoolinfo, true, false, false },
{ "darksend", &darksend, false, false, true },
{ "masternode", &masternode, false, false, true },
{ "getaddednodeinfo", &getaddednodeinfo, true, true, false },
{ "getdifficulty", &getdifficulty, true, false, false },
{ "getnetworkhashps", &getnetworkhashps, true, false, false },
@ -214,14 +217,12 @@ static const CRPCCommand vRPCCommands[] =
{ "gethashespersec", &gethashespersec, true, false, false },
{ "getinfo", &getinfo, true, false, false },
{ "getmininginfo", &getmininginfo, true, false, false },
{ "getpoolinfo", &getpoolinfo, true, false, false },
{ "getnewaddress", &getnewaddress, true, false, true },
{ "getaccountaddress", &getaccountaddress, true, false, true },
{ "setaccount", &setaccount, true, false, true },
{ "getaccount", &getaccount, false, false, true },
{ "getaddressesbyaccount", &getaddressesbyaccount, true, false, true },
{ "sendtoaddress", &sendtoaddress, false, false, true },
{ "darksend", &darksend, false, false, true },
{ "getreceivedbyaddress", &getreceivedbyaddress, false, false, true },
{ "getreceivedbyaccount", &getreceivedbyaccount, false, false, true },
{ "listreceivedbyaddress", &listreceivedbyaddress, false, false, true },

View File

@ -136,10 +136,14 @@ extern std::string HexBits(unsigned int nBits);
extern std::string HelpRequiringPassphrase();
extern void EnsureWalletIsUnlocked();
extern json_spirit::Value darksendsub(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getpoolinfo(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value darksend(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value masternode(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getconnectioncount(const json_spirit::Array& params, bool fHelp); // in rpcnet.cpp
extern json_spirit::Value getpeerinfo(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value addnode(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value darksendsub(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getaddednodeinfo(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value dumpprivkey(const json_spirit::Array& params, bool fHelp); // in rpcdump.cpp
extern json_spirit::Value importprivkey(const json_spirit::Array& params, bool fHelp);
@ -149,8 +153,6 @@ extern json_spirit::Value setgenerate(const json_spirit::Array& params, bool fHe
extern json_spirit::Value getnetworkhashps(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value gethashespersec(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getmininginfo(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getpoolinfo(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value resetpool(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getworkex(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getwork(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getblocktemplate(const json_spirit::Array& params, bool fHelp);
@ -162,8 +164,6 @@ 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 darksend(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value denominate(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);

View File

@ -6064,6 +6064,8 @@ bool CDarkSendPool::GetLastValidBlockHash(uint256& hash)
void CDarkSendPool::NewBlock()
{
if(myEntries.size() == 0) return;
printf("CDarkSendPool::NewBlock \n");
uint256 n1 = 0;

View File

@ -72,6 +72,7 @@ OBJS= \
obj/net.o \
obj/protocol.o \
obj/bitcoinrpc.o \
obj/rpcdarksend.o \
obj/rpcdump.o \
obj/rpcnet.o \
obj/rpcmining.o \

View File

@ -84,6 +84,7 @@ OBJS= \
obj/net.o \
obj/protocol.o \
obj/bitcoinrpc.o \
obj/rpcdarksend.o \
obj/rpcdump.o \
obj/rpcnet.o \
obj/rpcmining.o \

View File

@ -89,6 +89,7 @@ OBJS= \
obj/net.o \
obj/protocol.o \
obj/bitcoinrpc.o \
obj/rpcdarksend.o \
obj/rpcdump.o \
obj/rpcnet.o \
obj/rpcmining.o \

View File

@ -127,6 +127,7 @@ OBJS= \
obj/net.o \
obj/protocol.o \
obj/bitcoinrpc.o \
obj/rpcdarksend.o \
obj/rpcdump.o \
obj/rpcnet.o \
obj/rpcmining.o \

109
src/rpcdarksend.cpp Normal file
View File

@ -0,0 +1,109 @@
// Copyright (c) 2010 Satoshi Nakamoto
// Copyright (c) 2009-2012 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "main.h"
#include "db.h"
#include "init.h"
#include "bitcoinrpc.h"
using namespace json_spirit;
using namespace std;
Value darksend(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 2)
throw runtime_error(
"darksend <darkcoinaddress> <amount>\n"
"<amount> is a real and is rounded to the nearest 0.00000001"
+ HelpRequiringPassphrase());
CBitcoinAddress address(params[0].get_str());
if (!address.IsValid())
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid DarkCoin address");
// Amount
int64 nAmount = AmountFromValue(params[1]);
if (pwalletMain->IsLocked())
throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first.");
string strError = pwalletMain->DarkSendMoney(address.Get(), nAmount);
if (strError != "")
throw JSONRPCError(RPC_WALLET_ERROR, strError);
return "";
}
Value getpoolinfo(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 0)
throw runtime_error(
"getpoolinfo\n"
"Returns an object containing anonymous pool-related information.");
Object obj;
obj.push_back(Pair("masternode", darkSendPool.GetMasterNodeAddr()));
obj.push_back(Pair("state", darkSendPool.GetState()));
obj.push_back(Pair("entries", darkSendPool.GetEntriesCount()));
obj.push_back(Pair("entries_accepted", darkSendPool.GetCountEntriesAccepted()));
obj.push_back(Pair("signatures", darkSendPool.GetSignatureCount()));
return obj;
}
Value darksendsub(const Array& params, bool fHelp)
{
darkSendPool.SubscribeToMasterNode();
return Value::null;
}
Value masternode(const Array& params, bool fHelp)
{
string strCommand;
if (params.size() == 1)
strCommand = params[0].get_str();
if (fHelp || params.size() != 1 ||
(strCommand != "start" && strCommand != "stop" && strCommand != "list" && strCommand != "count"
&& strCommand != "debug" && strCommand != "create"))
throw runtime_error(
"masternode <start|stop|list|count|debug|create>\n");
if (strCommand == "stop")
{
return "Not implemented yet";
}
if (strCommand == "list")
{
Object obj;
BOOST_FOREACH(CMasterNode mn, darkSendMasterNodes) {
mn.Check();
obj.push_back(Pair(mn.addr.ToString().c_str(), (int)mn.IsEnabled()));
}
return obj;
}
if (strCommand == "count") return (int)darkSendMasterNodes.size();
if (strCommand == "debug")
{
if(darkSendPool.isCapableMasterNode) return "is masternode";
CTxIn vin = CTxIn();
bool found = darkSendPool.GetMasterNodeVin(vin);
if(!found){
return "Missing masternode input, try running masternode create";
} else {
return "No problems were found";
}
}
if (strCommand == "create")
{
return "Not implemented yet";
}
return Value::null;
}

View File

@ -161,28 +161,6 @@ Value getmininginfo(const Array& params, bool fHelp)
return obj;
}
Value getpoolinfo(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 0)
throw runtime_error(
"getpoolinfo\n"
"Returns an object containing anonymous pool-related information.");
Object obj;
obj.push_back(Pair("masternode", darkSendPool.GetMasterNodeAddr()));
obj.push_back(Pair("state", darkSendPool.GetState()));
obj.push_back(Pair("entries", darkSendPool.GetEntriesCount()));
obj.push_back(Pair("entries_accepted", darkSendPool.GetCountEntriesAccepted()));
obj.push_back(Pair("signatures", darkSendPool.GetSignatureCount()));
return obj;
}
Value darksendsub(const Array& params, bool fHelp)
{
darkSendPool.SubscribeToMasterNode();
return Value::null;
}
Value getworkex(const Array& params, bool fHelp)
{
if (fHelp || params.size() > 2)

View File

@ -94,8 +94,6 @@ Value getinfo(const Array& params, bool fHelp)
return obj;
}
Value getnewaddress(const Array& params, bool fHelp)
{
if (fHelp || params.size() > 1)
@ -302,31 +300,6 @@ Value sendtoaddress(const Array& params, bool fHelp)
return wtx.GetHash().GetHex();
}
Value darksend(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 2)
throw runtime_error(
"darksend <darkcoinaddress> <amount>\n"
"<amount> is a real and is rounded to the nearest 0.00000001"
+ HelpRequiringPassphrase());
CBitcoinAddress address(params[0].get_str());
if (!address.IsValid())
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid DarkCoin address");
// Amount
int64 nAmount = AmountFromValue(params[1]);
if (pwalletMain->IsLocked())
throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first.");
string strError = pwalletMain->DarkSendMoney(address.Get(), nAmount);
if (strError != "")
throw JSONRPCError(RPC_WALLET_ERROR, strError);
return "";
}
Value listaddressgroupings(const Array& params, bool fHelp)
{
if (fHelp)