Skip to content

Commit

Permalink
Merge pull request #15 from bze-alphateam/develop
Browse files Browse the repository at this point in the history
3.0.1
  • Loading branch information
faneaatiku authored Feb 10, 2020
2 parents a4ad65c + b3ff544 commit 41a0b16
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 2,075 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,5 @@ wallet-utility

contrib/debian/files
contrib/debian/substvars

binaries
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ dnl require autoconf 2.60 (AS_ECHO/AS_ECHO_N)
AC_PREREQ([2.60])
define(_CLIENT_VERSION_MAJOR, 3)
define(_CLIENT_VERSION_MINOR, 0)
define(_CLIENT_VERSION_REVISION, 0)
define(_CLIENT_VERSION_REVISION, 1)
define(_CLIENT_VERSION_BUILD, 50)
define(_ZC_BUILD_VAL, m4_if(m4_eval(_CLIENT_VERSION_BUILD < 25), 1, m4_incr(_CLIENT_VERSION_BUILD), m4_eval(_CLIENT_VERSION_BUILD < 50), 1, m4_eval(_CLIENT_VERSION_BUILD - 24), m4_eval(_CLIENT_VERSION_BUILD == 50), 1, , m4_eval(_CLIENT_VERSION_BUILD - 50)))
define(_CLIENT_VERSION_SUFFIX, m4_if(m4_eval(_CLIENT_VERSION_BUILD < 25), 1, _CLIENT_VERSION_REVISION-beta$1, m4_eval(_CLIENT_VERSION_BUILD < 50), 1, _CLIENT_VERSION_REVISION-rc$1, m4_eval(_CLIENT_VERSION_BUILD == 50), 1, _CLIENT_VERSION_REVISION, _CLIENT_VERSION_REVISION-$1)))
Expand Down
2 changes: 1 addition & 1 deletion src/clientversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//! These need to be macros, as clientversion.cpp's and bitcoin*-res.rc's voodoo requires it
#define CLIENT_VERSION_MAJOR 3
#define CLIENT_VERSION_MINOR 0
#define CLIENT_VERSION_REVISION 0
#define CLIENT_VERSION_REVISION 1
#define CLIENT_VERSION_BUILD 00

//! Set to true for release, false for prerelease or test build
Expand Down
4 changes: 2 additions & 2 deletions src/deprecation.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
// Deprecation policy:
// * Shut down 16 weeks' worth of blocks after the estimated release block height.
// * A warning is shown during the 2 weeks' worth of blocks prior to shut down.
static const int APPROX_RELEASE_HEIGHT = 440000;
static const int WEEKS_UNTIL_DEPRECATION = 52;
static const int APPROX_RELEASE_HEIGHT = 964000;
static const int WEEKS_UNTIL_DEPRECATION = 26;
static const int DEPRECATION_HEIGHT = APPROX_RELEASE_HEIGHT + (WEEKS_UNTIL_DEPRECATION * 7 * 24 * 60);

// Number of blocks before deprecation to warn users
Expand Down
2 changes: 1 addition & 1 deletion src/masternodeconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ bool CMasternodeConfig::read(std::string& strErr)
return true;
}

bool CMasternodeEntry::castOutputIndex(int n) const
bool CMasternodeEntry::castOutputIndex(int &n) const
{
try {
n = std::stoi(outputIndex);
Expand Down
2 changes: 1 addition & 1 deletion src/masternodeconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class CMasternodeEntry

const std::string getOutputIndex() const;

bool castOutputIndex(int n) const;
bool castOutputIndex(int &n) const;

void setOutputIndex(std::string outputIndex) const;

Expand Down
151 changes: 137 additions & 14 deletions src/rpc/masternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,25 +263,18 @@ UniValue startalias(const UniValue& params, bool fHelp)

for (auto mne: mnEntries) {
if (mne->getAlias() == strAlias) {
std::string strError;
CMasternodeBroadcast mnb;

fSuccess = CMasternodeBroadcast::Create(mne->getIp(), mne->getPrivKey(), mne->getTxHash(), mne->getOutputIndex(), strError, mnb);

if (fSuccess) {
mnodeman.UpdateMasternodeList(mnb);
mnb.Relay();
}
fSuccess = activeMasternode.Register(mne->ip, mne->privKey, mne->txHash, mne->outputIndex, strErr);
break;
}
}

UniValue obj(UniValue::VOBJ);
if (fSuccess) {
UniValue obj(UniValue::VOBJ);
obj.push_back(Pair("result", "Successfully started alias"));
return obj;
} else {
throw runtime_error("Failed to start alias\n");
obj.push_back(Pair("error", strErr));
}
return obj;
}

UniValue getmasternodecount (const UniValue& params, bool fHelp)
Expand Down Expand Up @@ -676,7 +669,7 @@ UniValue listmasternodeconf (const UniValue& params, bool fHelp)

LogPrintf("entries size : %d \n", mnEntries.size());

for (auto mne: mnEntries){
for (auto mne: mnEntries) {
int nIndex;

if(!mne->castOutputIndex(nIndex))
Expand All @@ -692,7 +685,7 @@ UniValue listmasternodeconf (const UniValue& params, bool fHelp)
mne->getTxHash().find(strFilter) == string::npos &&
strStatus.find(strFilter) == string::npos) continue;

UniValue mnObj(UniValue::VARR);
UniValue mnObj(UniValue::VOBJ);
mnObj.push_back(Pair("alias", mne->getAlias()));
mnObj.push_back(Pair("address", mne->getIp()));
mnObj.push_back(Pair("privateKey", mne->getPrivKey()));
Expand Down Expand Up @@ -1030,13 +1023,143 @@ UniValue masternode(const UniValue& params, bool fHelp)
return NullUniValue;
}

UniValue rewardactivemns(const UniValue& params, bool fHelp)
{
std::string strFilter = "";

if (params.size() == 1) strFilter = params[0].get_str();

if (fHelp || (params.size() > 1))
throw runtime_error(
"rewardactivemns amount ( subtractfeefromamount \"comment\" \"comment-to\" ) \n"
"Send an amount to a given address. The amount is a real and is rounded to the nearest 0.00000001\n"
"Be aware that the list of active MNs is stored locally and might not contain all the MNs in the network.\n"
"\nArguments:\n"
"1. \"amount\" (numeric, required) A json object with addresses and amounts\n"
"2. subtractfeefromamount (boolean, optional, default=false) The fee will be deducted from the amount being sent.\n"
" Masternodes will receive less Zcash than you enter in the amount field.\n"
"3. \"comment\" (string, optional) A comment used to store what the transaction is for. \n"
" This is not part of the transaction, just kept in your wallet.\n"
"4. \"comment-to\" (string, optional) A comment to store the name of the person or organization \n"
" to which you're sending the transaction. This is not part of the \n"
" transaction, just kept in your wallet.\n"
"\nResult:\n"
"{\n"
" \"total_amount\": amount, (numeric) Total sent\n"
" \"recipient_amount\": recipient_amount, (numeric) Amount for each masternode in list.\n"
" \"recipients_count\": count (numeric) Total number of recipients.\n"
" \"txids\": [\n"
" \"txid1\", (string) Transaction id \n"
" \"txid2\", (string) Transaction id \n"
" ...\n"
" ]\n"
"},\n"
"\nExamples:\n"
+ HelpExampleCli("rewardactivemns", "100")
+ HelpExampleCli("rewardactivemns", "100 true \"Christmas presents\"")
+ HelpExampleRpc("rewardactivemns", "100")
+ HelpExampleRpc("rewardactivemns", "100 true \"Christmas presents\""));

UniValue ret(UniValue::VOBJ);

LOCK2(cs_main, pwalletMain->cs_wallet);
int nHeight;
{
CBlockIndex* pindex = chainActive.Tip();
if(!pindex) return 0;
nHeight = pindex->nHeight;
}

if (!masternodeSync.IsSynced())
{
std::string error = "Masternode is not synced, please wait. Current status: " + masternodeSync.GetSyncStatus();
ret.push_back(Pair("result", error));
return ret;
}

CAmount totalAmount = AmountFromValue(params[0]);

if (totalAmount <= 0) {
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send");
}

if (totalAmount > pwalletMain->GetBalance()) {
throw JSONRPCError(RPC_TYPE_ERROR, "Insufficient funds.");
}

bool substractFeeFromAmount = false;
if (params.size() > 1)
substractFeeFromAmount = params[1].get_bool();

CWalletTx wtx;
if (params.size() > 2 && !params[2].isNull() && !params[2].get_str().empty())
wtx.mapValue["comment"] = params[2].get_str();
if (params.size() > 3 && !params[3].isNull() && !params[3].get_str().empty())
wtx.mapValue["to"] = params[3].get_str();

std::vector<pair<int, CMasternode> > vMasternodeRanks = mnodeman.GetMasternodeRanks(nHeight);
std::set<CTxDestination> destinations;
//build destinations
BOOST_FOREACH (PAIRTYPE(int, CMasternode) & s, vMasternodeRanks) {
CMasternode* mn = mnodeman.Find(s.second.vin);
if (mn == NULL) {
continue;
}
//reward only enabled MNs and only once
if (mn->Status() != "ENABLED" || destinations.count(mn->pubKeyCollateralAddress.GetID())) {
continue;
}

destinations.insert(mn->pubKeyCollateralAddress.GetID());
}

//make sure there are enough destinations to continue
if (destinations.size() == 0) {
throw JSONRPCError(RPC_TYPE_ERROR, "No masternode available to reward");
}

//reward for each MN
CAmount recipientAmount = totalAmount/destinations.size();
std::vector<CRecipient> vecSend;
CAmount spentAmount = 0;
int recipientsCounter = 0;
for (auto dest : destinations) {
CScript scriptPubKey = GetScriptForDestination(dest);
CRecipient recipient = {scriptPubKey, recipientAmount, substractFeeFromAmount};
vecSend.push_back(recipient);
recipientsCounter++;
spentAmount += recipientAmount;
}

// Send
CReserveKey keyChange(pwalletMain);
CAmount nFeeRequired = 0;
int nChangePosRet = -1;
string strFailReason;
UniValue txes(UniValue::VARR);
bool fCreated = pwalletMain->CreateTransaction(vecSend, wtx, keyChange, nFeeRequired, nChangePosRet, strFailReason);
if (!fCreated)
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, strFailReason);
if (!pwalletMain->CommitTransaction(wtx, keyChange))
throw JSONRPCError(RPC_WALLET_ERROR, "Transaction commit failed");
txes.push_back(wtx.GetHash().GetHex());

ret.push_back(Pair("total_amount", FormatMoney(spentAmount)));
ret.push_back(Pair("recipient_amount", FormatMoney(recipientAmount)));
ret.push_back(Pair("recipients_count", recipientsCounter));
ret.push_back(Pair("txids", txes));

return ret;
}

static const CRPCCommand commands[] =
{ // category name actor (function) okSafeMode
// --------------------- ------------------------ ----------------------- ----------
{ "masternode", "obfuscation", &obfuscation, true },
{ "masternode", "getpoolinfo", &getpoolinfo, true },
{ "masternode", "masternode", &masternode, true },
{ "masternode", "listmasternodes", &listmasternodes, true },
{ "masternode", "rewardactivemns", &rewardactivemns, true },
{ "masternode", "getmasternodecount", &getmasternodecount, true },
{ "masternode", "masternodeconnect", &masternodeconnect, true },
{ "masternode", "masternodecurrent", &masternodecurrent, true },
Expand Down
Loading

0 comments on commit 41a0b16

Please sign in to comment.