Skip to content

Commit

Permalink
add coinlock RPC
Browse files Browse the repository at this point in the history
  • Loading branch information
presstab committed Sep 29, 2015
1 parent 10bb078 commit f8ad0ac
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/bitcoinrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ static const CRPCCommand vRPCCommands[] =
{ "sendalert", &sendalert, false, false},
{ "setstakesplitthreshold", &setstakesplitthreshold, false, false},
{ "getstakesplitthreshold", &getstakesplitthreshold, false, false},
{ "coinlock", &coinlock, false, false},
};

CRPCTable::CRPCTable()
Expand Down
1 change: 1 addition & 0 deletions src/bitcoinrpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ extern json_spirit::Value validatepubkey(const json_spirit::Array& params, bool
extern json_spirit::Value getnewpubkey(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value setstakesplitthreshold(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getstakesplitthreshold(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value coinlock(const json_spirit::Array& params, bool fHelp);

extern json_spirit::Value getrawtransaction(const json_spirit::Array& params, bool fHelp); // in rcprawtransaction.cpp
extern json_spirit::Value listunspent(const json_spirit::Array& params, bool fHelp);
Expand Down
44 changes: 44 additions & 0 deletions src/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1827,4 +1827,48 @@ Value getstakesplitthreshold(const Array& params, bool fHelp)
result.push_back(Pair("split stake threshold set to ", int(pwalletMain->nStakeSplitThreshold)));
return result;

}

// presstab RateCoin
Value coinlock(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 1)
throw runtime_error(
"coinlock <command>\n"
"Commands: \n"
"display - shows any locked coins you have. A locked coin will not attempt to stake.\n"
"unlockall - unlocks all locked coins\n"
"lockall - locks all coins from staking\n");
std::string strCommand = params[0].get_str();
Object result;
if(strCommand == "display")
{
std::vector<COutPoint> vLockedCoins;
vLockedCoins = pwalletMain->lockedcoins.vLockedCoins;
for(unsigned int i = 0; i < vLockedCoins.size(); i++)
{
result.push_back(Pair("Locked Outpoint:", vLockedCoins[i].ToString()));
}
}
else if(strCommand == "unlockall")
{
pwalletMain->lockedcoins.vLockedCoins.clear();
CWalletDB walletdb(pwalletMain->strWalletFile);
result.push_back(Pair("Unlocked All and Wrote to DB?", walletdb.WriteLockedCoins(pwalletMain->lockedcoins)));
}
else if(strCommand == "lockall")
{
pwalletMain->lockedcoins.vLockedCoins.clear();
vector<COutput> vCoins;
pwalletMain->AvailableCoinsMinConf(vCoins, 0); //since we are locking 'all coins' we will even lock 0 conf coins
for (unsigned int i = 0; i < vCoins.size(); i++)
pwalletMain->lockedcoins.vLockedCoins.push_back(COutPoint(vCoins[i].tx->GetHash(), vCoins[i].i));

CWalletDB walletdb(pwalletMain->strWalletFile);
result.push_back(Pair("Locked All and Wrote to DB?", walletdb.WriteLockedCoins(pwalletMain->lockedcoins)));
}
else
return "Did not recognize command";

return result;
}

0 comments on commit f8ad0ac

Please sign in to comment.