Skip to content

Commit

Permalink
reward fix and rpc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
afghany committed Nov 15, 2018
1 parent 3fc4e11 commit b65c8a9
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 59 deletions.
Binary file added castle_mnhack-qt
Binary file not shown.
4 changes: 2 additions & 2 deletions configure.ac
Expand Up @@ -2,8 +2,8 @@ dnl require autoconf 2.60 (AS_ECHO/AS_ECHO_N)
AC_PREREQ([2.60])
define(_CLIENT_VERSION_MAJOR, 2)
define(_CLIENT_VERSION_MINOR, 0)
define(_CLIENT_VERSION_REVISION, 2)
define(_CLIENT_VERSION_BUILD, 1)
define(_CLIENT_VERSION_REVISION, 3)
define(_CLIENT_VERSION_BUILD, 0)
define(_CLIENT_VERSION_IS_RELEASE, true)
define(_COPYRIGHT_YEAR, 2018)
AC_INIT([Castle Core],[_CLIENT_VERSION_MAJOR._CLIENT_VERSION_MINOR._CLIENT_VERSION_REVISION],[www.projectcastle.tech],[castle])
Expand Down
2 changes: 1 addition & 1 deletion doc/Doxyfile
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = "Castle Core"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 2.0.0
PROJECT_NUMBER = 2.0.2

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
5 changes: 3 additions & 2 deletions src/chainparams.cpp
Expand Up @@ -57,11 +57,12 @@ static Checkpoints::MapCheckpoints mapCheckpoints =
( 0, uint256("00000da65c7ea599e637cdfaac58b37b9792da59e4cb2cc41f9ca0465a4387e3"))
( 2550, uint256("b65c8988dc018d10166e7fd55c697c6c42d1afccc0ffdc8d7188b921b6a987bb"))
( 5470, uint256("360d899c16eec21505c58b3e95286d497f9c35e03b7740f178d8aaa7152a68fa"))
( 10100, uint256("3da48d74cfd9953affce95636bd5586c670453cc2662f6f46d638f9c703f7588"))
;
static const Checkpoints::CCheckpointData data = {
&mapCheckpoints,
1541984406, // * UNIX timestamp of last checkpoint block
9951, // * total number of transactions between genesis and last checkpoint
1542323097, // * UNIX timestamp of last checkpoint block
19439, // * total number of transactions between genesis and last checkpoint
// (the tx=... number in the SetBestChain debug.log lines)
2000 // * estimated number of transactions per day after checkpoint
};
Expand Down
12 changes: 6 additions & 6 deletions src/main.cpp
Expand Up @@ -2850,13 +2850,13 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
LogPrint("bench", " - Connect %u transactions: %.2fms (%.3fms/tx, %.3fms/txin) [%.2fs]\n", (unsigned)block.vtx.size(), 0.001 * (nTime1 - nTimeStart), 0.001 * (nTime1 - nTimeStart) / block.vtx.size(), nInputs <= 1 ? 0 : 0.001 * (nTime1 - nTimeStart) / (nInputs - 1), nTimeConnect * 0.000001);

//PoW phase redistributed fees to miner. PoS stage destroys fees.
CAmount nExpectedMint = GetBlockValue(pindex->pprev->nHeight);
CAmount nExpectedMint = GetBlockValue(pindex->nHeight);
if (block.IsProofOfWork())
nExpectedMint += nFees;

//Check that the block does not overmint
if (!IsBlockValueValid(block, nExpectedMint, pindex->nMint)) {
return state.DoS(100, error("ConnectBlock() : reward pays too much (actual=%s vs limit=%s)", FormatMoney(pindex->nMint), FormatMoney(nExpectedMint)),
return state.DoS(100, error("ConnectBlock() : reward pays too much (actual=%s vs limit=%s) Height:%d", FormatMoney(pindex->nMint), FormatMoney(nExpectedMint), pindex->nHeight),
REJECT_INVALID, "bad-cb-amount");
}

Expand Down Expand Up @@ -3899,12 +3899,12 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo
CTransaction tx = block.vtx[1];
if (!tx.vout[1].IsZerocoinMint()) {
int nIndex = tx.vout.size() -1;
CAmount nBlockValue = GetBlockValue(nHeight - 1);
CAmount nMasternodeValue = GetMasternodePayment(nHeight - 1, nBlockValue, 0, false);
CAmount nBlockValue = GetBlockValue(nHeight);
CAmount nMasternodeValue = GetMasternodePayment(nHeight, nBlockValue, 0, false);

if ((tx.vout[nIndex].nValue != nMasternodeValue) && (mnodeman.size() > 0)) {
return state.DoS(100, error("%s : rejected by check masternode lock-in at %d", __func__, nHeight),
REJECT_INVALID, "check devfund mismatch");
return state.DoS(100, error("%s : rejected by check masternode lock-in at %d Height:%d", __func__, nHeight),
REJECT_INVALID, "check masternode mismatch");
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/masternode-payments.cpp
Expand Up @@ -312,9 +312,10 @@ void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew,

bool hasPayment = true;
CScript payee;
const int nTargetHeight = pindexPrev->nHeight + 1;

//spork
if (!masternodePayments.GetBlockPayee(pindexPrev->nHeight + 1, payee)) {
if (!masternodePayments.GetBlockPayee(nTargetHeight, payee)) {
//no masternode detected
CMasternode* winningNode = mnodeman.GetCurrentMasterNode(1);
if (winningNode) {
Expand All @@ -327,9 +328,8 @@ void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew,
}
}

CAmount blockValue = GetBlockValue(pindexPrev->nHeight);
CAmount masternodePayment = GetMasternodePayment(pindexPrev->nHeight,
blockValue, 0, fZCSTLStake);
CAmount blockValue = GetBlockValue(nTargetHeight);
CAmount masternodePayment = GetMasternodePayment(nTargetHeight, blockValue, 0, fZCSTLStake);

if (hasPayment) {
if (fProofOfStake) {
Expand Down Expand Up @@ -357,9 +357,9 @@ void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew,
ExtractDestination(payee, address1);
CBitcoinAddress address2(address1);

LogPrint("masternode", "Masternode payment of %s to %s\n",
LogPrint("masternode", "Masternode payment of %s to %s Height:%d\n",
FormatMoney(masternodePayment).c_str(),
address2.ToString().c_str());
address2.ToString().c_str(), nTargetHeight);
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/rpcmasternode.cpp
Expand Up @@ -208,7 +208,8 @@ UniValue listmasternodes(const UniValue& params, bool fHelp)
" \"txhash\": \"hash\", (string) Collateral transaction hash\n"
" \"outidx\": n, (numeric) Collateral transaction output index\n"
" \"status\": s, (string) Status (ENABLED/EXPIRED/REMOVE/etc)\n"
" \"addr\": \"addr\", (string) Masternode CSTL address\n"
" \"addr\": \"addr\", (string) Masternode CSTL collateral address\n"
" \"ipaddr\": \"ipaddr\", (string) Masternode HUZU IP address\n"
" \"version\": v, (numeric) Masternode protocol version\n"
" \"lastseen\": ttt, (numeric) The time in seconds since epoch (Jan 1 1970 GMT) of the last seen\n"
" \"activetime\": ttt, (numeric) The time in seconds since epoch (Jan 1 1970 GMT) masternode has been active\n"
Expand Down Expand Up @@ -255,6 +256,7 @@ UniValue listmasternodes(const UniValue& params, bool fHelp)
obj.push_back(Pair("outidx", (uint64_t)oIdx));
obj.push_back(Pair("status", strStatus));
obj.push_back(Pair("addr", CBitcoinAddress(mn->pubKeyCollateralAddress.GetID()).ToString()));
obj.push_back(Pair("ipaddr", mn->addr.ToString()));
obj.push_back(Pair("version", mn->protocolVersion));
obj.push_back(Pair("lastseen", (int64_t)mn->lastPing.sigTime));
obj.push_back(Pair("activetime", (int64_t)(mn->lastPing.sigTime - mn->sigTime)));
Expand Down
75 changes: 47 additions & 28 deletions src/rpcwallet.cpp
Expand Up @@ -583,7 +583,7 @@ UniValue getreceivedbyaddress(const UniValue& params, bool fHelp)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid CSTL address");
CScript scriptPubKey = GetScriptForDestination(address.Get());
if (!IsMine(*pwalletMain, scriptPubKey))
return (double)0.0;
throw JSONRPCError(RPC_WALLET_ERROR, "Address not found in wallet");

// Minimum confirmations
int nMinDepth = 1;
Expand All @@ -592,7 +592,7 @@ UniValue getreceivedbyaddress(const UniValue& params, bool fHelp)

// Tally
CAmount nAmount = 0;
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) {
for (std::map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) {
const CWalletTx& wtx = (*it).second;
if (wtx.IsCoinBase() || !IsFinalTx(wtx))
continue;
Expand Down Expand Up @@ -676,6 +676,9 @@ CAmount GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMi

if (nReceived != 0 && wtx.GetDepthInMainChain() >= nMinDepth)
nBalance += nReceived;

nBalance -= wtx.GetLockedCredit();

nBalance -= nSent + nFee;
}

Expand Down Expand Up @@ -757,6 +760,7 @@ UniValue getbalance(const UniValue& params, bool fHelp)
BOOST_FOREACH (const COutputEntry& s, listSent)
nBalance -= s.amount;
nBalance -= allFee;
nBalance -= wtx.GetLockedCredit();
}
return ValueFromAmount(nBalance);
}
Expand Down Expand Up @@ -784,36 +788,37 @@ UniValue getunconfirmedbalance(const UniValue &params, bool fHelp)
UniValue movecmd(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() < 3 || params.size() > 5)
throw runtime_error(
throw std::runtime_error(
"move \"fromaccount\" \"toaccount\" amount ( minconf \"comment\" )\n"
"\nMove a specified amount from one account in your wallet to another.\n"

"\nArguments:\n"
"1. \"fromaccount\" (string, required) The name of the account to move funds from. May be the default account using \"\".\n"
"2. \"toaccount\" (string, required) The name of the account to move funds to. May be the default account using \"\".\n"
"3. minconf (numeric, optional, default=1) Only use funds with at least this many confirmations.\n"
"4. \"comment\" (string, optional) An optional comment, stored in the wallet only.\n"
"3. amount (numeric, required) Quantity of PIV to move between accounts.\n"
"4. minconf (numeric, optional, default=1) Only use funds with at least this many confirmations.\n"
"5. \"comment\" (string, optional) An optional comment, stored in the wallet only.\n"

"\nResult:\n"
"true|false (boolean) true if successfull.\n"
"true|false (boolean) true if successful.\n"

"\nExamples:\n"
"\nMove 0.01 CSTL from the default account to the account named tabby\n" +
"\nMove 0.01 PIV from the default account to the account named tabby\n" +
HelpExampleCli("move", "\"\" \"tabby\" 0.01") +
"\nMove 0.01 CSTL from timotei to akiko with a comment and funds have 6 confirmations\n" +
HelpExampleCli("move", "\"timotei\" \"akiko\" 0.01 6 \"happy birthday!\"") +
"\nMove 0.01 PIV from timotei to akiko with a comment\n" +
HelpExampleCli("move", "\"timotei\" \"akiko\" 0.01 1 \"happy birthday!\"") +
"\nAs a json rpc call\n" +
HelpExampleRpc("move", "\"timotei\", \"akiko\", 0.01, 6, \"happy birthday!\""));
HelpExampleRpc("move", "\"timotei\", \"akiko\", 0.01, 1, \"happy birthday!\""));

LOCK2(cs_main, pwalletMain->cs_wallet);

string strFrom = AccountFromValue(params[0]);
string strTo = AccountFromValue(params[1]);
std::string strFrom = AccountFromValue(params[0]);
std::string strTo = AccountFromValue(params[1]);
CAmount nAmount = AmountFromValue(params[2]);
if (params.size() > 3)
// unused parameter, used to be nMinDepth, keep type-checking it though
(void)params[3].get_int();
string strComment;
std::string strComment;
if (params.size() > 4)
strComment = params[4].get_str();

Expand Down Expand Up @@ -1762,7 +1767,7 @@ UniValue walletpassphrase(const UniValue& params, bool fHelp)
"\nArguments:\n"
"1. \"passphrase\" (string, required) The wallet passphrase\n"
"2. timeout (numeric, required) The time to keep the decryption key in seconds.\n"
"3. anonymizeonly (boolean, optional, default=flase) If is true sending functions are disabled."
"3. anonymizeonly (boolean, optional, default=false) If is true sending functions are disabled."

"\nNote:\n"
"Issuing the walletpassphrase command while the wallet is already unlocked will set a new unlock\n"
Expand Down Expand Up @@ -1799,15 +1804,23 @@ UniValue walletpassphrase(const UniValue& params, bool fHelp)
if (!pwalletMain->IsLocked() && pwalletMain->fWalletUnlockAnonymizeOnly && anonymizeOnly)
throw JSONRPCError(RPC_WALLET_ALREADY_UNLOCKED, "Error: Wallet is already unlocked.");

// Get the timeout
int64_t nSleepTime = params[1].get_int64();
// Timeout cannot be negative, otherwise it will relock immediately
if (nSleepTime < 0) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Timeout cannot be negative.");
}
// Clamp timeout
constexpr int64_t MAX_SLEEP_TIME = 100000000; // larger values trigger a macos/libevent bug?
if (nSleepTime > MAX_SLEEP_TIME) {
nSleepTime = MAX_SLEEP_TIME;
}

if (!pwalletMain->Unlock(strWalletPass, anonymizeOnly))
throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect.");

pwalletMain->TopUpKeyPool();

int64_t nSleepTime = params[1].get_int64();
LOCK(cs_nWalletUnlockTime);
nWalletUnlockTime = GetTime() + nSleepTime;

if (nSleepTime > 0) {
nWalletUnlockTime = GetTime () + nSleepTime;
RPCRunLater ("lockwallet", boost::bind (LockWallet, pwalletMain), nSleepTime);
Expand Down Expand Up @@ -1954,7 +1967,7 @@ UniValue encryptwallet(const UniValue& params, bool fHelp)
UniValue lockunspent(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() < 1 || params.size() > 2)
throw runtime_error(
throw std::runtime_error(
"lockunspent unlock [{\"txid\":\"txid\",\"vout\":n},...]\n"
"\nUpdates list of temporarily unspendable outputs.\n"
"Temporarily lock (unlock=false) or unlock (unlock=true) specified transaction outputs.\n"
Expand Down Expand Up @@ -2120,6 +2133,7 @@ UniValue getwalletinfo(const UniValue& params, bool fHelp)
" \"keypoololdest\": xxxxxx, (numeric) the timestamp (seconds since GMT epoch) of the oldest pre-generated key in the key pool\n"
" \"keypoolsize\": xxxx, (numeric) how many new keys are pre-generated\n"
" \"unlocked_until\": ttt, (numeric) the timestamp in seconds since epoch (midnight Jan 1 1970 GMT) that the wallet is unlocked for transfers, or 0 if the wallet is locked\n"
" \"paytxfee\": x.xxxx, (numeric) the transaction fee configuration, set in CSTL/kB\n"
"}\n"

"\nExamples:\n" +
Expand All @@ -2135,6 +2149,7 @@ UniValue getwalletinfo(const UniValue& params, bool fHelp)
obj.push_back(Pair("keypoolsize", (int)pwalletMain->GetKeyPoolSize()));
if (pwalletMain->IsCrypted())
obj.push_back(Pair("unlocked_until", nWalletUnlockTime));
obj.push_back(Pair("paytxfee", ValueFromAmount(payTxFee.GetFeePerK())));
return obj;
}

Expand Down Expand Up @@ -3048,7 +3063,7 @@ UniValue getarchivedzerocoin(const UniValue& params, bool fHelp)
list<CDeterministicMint> listDMints = walletdb.ListArchivedDeterministicMints();

UniValue arrRet(UniValue::VARR);
for (const CZerocoinMint mint : listMints) {
for (const CZerocoinMint& mint : listMints) {
UniValue objMint(UniValue::VOBJ);
objMint.push_back(Pair("txid", mint.GetTxHash().GetHex()));
objMint.push_back(Pair("denomination", ValueFromAmount(mint.GetDenominationAsAmount())));
Expand All @@ -3058,7 +3073,7 @@ UniValue getarchivedzerocoin(const UniValue& params, bool fHelp)
arrRet.push_back(objMint);
}

for (const CDeterministicMint dMint : listDMints) {
for (const CDeterministicMint& dMint : listDMints) {
UniValue objDMint(UniValue::VOBJ);
objDMint.push_back(Pair("txid", dMint.GetTxHash().GetHex()));
objDMint.push_back(Pair("denomination", ValueFromAmount(libzerocoin::ZerocoinDenominationToAmount(dMint.GetDenomination()))));
Expand Down Expand Up @@ -3136,7 +3151,11 @@ UniValue exportzerocoins(const UniValue& params, bool fHelp)
objMint.push_back(Pair("u", mint.IsUsed()));
objMint.push_back(Pair("v", mint.GetVersion()));
if (mint.GetVersion() >= 2) {
objMint.push_back(Pair("k", HexStr(mint.GetPrivKey())));
CKey key;
key.SetPrivKey(mint.GetPrivKey(), true);
CBitcoinSecret cBitcoinSecret;
cBitcoinSecret.SetKey(key);
objMint.push_back(Pair("k", cBitcoinSecret.ToString()));
}
jsonList.push_back(objMint);
}
Expand Down Expand Up @@ -3214,10 +3233,10 @@ UniValue importzerocoins(const UniValue& params, bool fHelp)
CPrivKey privkey;
if (nVersion >= libzerocoin::PrivateCoin::PUBKEY_VERSION) {
std::string strPrivkey = find_value(o, "k").get_str();
CKey key;
uint256 nPrivKey(strPrivkey);
key.Set(nPrivKey.begin(), nPrivKey.end(), true);
if (!key.IsValid())
CBitcoinSecret vchSecret;
bool fGood = vchSecret.SetString(strPrivkey);
CKey key = vchSecret.GetKey();
if (!key.IsValid() && fGood)
return JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "privkey is not valid");
privkey = key.GetPrivKey();
}
Expand Down Expand Up @@ -3267,15 +3286,15 @@ UniValue reconsiderzerocoins(const UniValue& params, bool fHelp)
pwalletMain->ReconsiderZerocoins(listMints, listDMints);

UniValue arrRet(UniValue::VARR);
for (const CZerocoinMint mint : listMints) {
for (const CZerocoinMint& mint : listMints) {
UniValue objMint(UniValue::VOBJ);
objMint.push_back(Pair("txid", mint.GetTxHash().GetHex()));
objMint.push_back(Pair("denomination", ValueFromAmount(mint.GetDenominationAsAmount())));
objMint.push_back(Pair("pubcoin", mint.GetValue().GetHex()));
objMint.push_back(Pair("height", mint.GetHeight()));
arrRet.push_back(objMint);
}
for (const CDeterministicMint dMint : listDMints) {
for (const CDeterministicMint& dMint : listDMints) {
UniValue objMint(UniValue::VOBJ);
objMint.push_back(Pair("txid", dMint.GetTxHash().GetHex()));
objMint.push_back(Pair("denomination", FormatMoney(libzerocoin::ZerocoinDenominationToAmount(dMint.GetDenomination()))));
Expand Down
16 changes: 3 additions & 13 deletions src/wallet.cpp
Expand Up @@ -254,23 +254,13 @@ bool CWallet::LoadMultiSig(const CScript& dest)

bool CWallet::Unlock(const SecureString& strWalletPassphrase, bool anonymizeOnly)
{
SecureString strWalletPassphraseFinal;

if (!IsLocked()) {
fWalletUnlockAnonymizeOnly = anonymizeOnly;
return true;
}

strWalletPassphraseFinal = strWalletPassphrase;


CCrypter crypter;
CKeyingMaterial vMasterKey;

{
LOCK(cs_wallet);
BOOST_FOREACH (const MasterKeyMap::value_type& pMasterKey, mapMasterKeys) {
if (!crypter.SetKeyFromPassphrase(strWalletPassphraseFinal, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod))
if (!crypter.SetKeyFromPassphrase(strWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod))
return false;
if (!crypter.Decrypt(pMasterKey.second.vchCryptedKey, vMasterKey))
continue; // try another master key
Expand Down Expand Up @@ -1204,7 +1194,7 @@ CAmount CWalletTx::GetLockedCredit() const
}

// Add masternode collaterals which are handled likc locked coins
if (fMasterNode && vout[i].nValue == Params().MasternodeCollateral()) {
else if (fMasterNode && vout[i].nValue == Params().MasternodeCollateral()) {
nCredit += pwallet->GetCredit(txout, ISMINE_SPENDABLE);
}

Expand Down Expand Up @@ -1323,7 +1313,7 @@ CAmount CWalletTx::GetLockedWatchOnlyCredit() const
}

// Add masternode collaterals which are handled likc locked coins
if (fMasterNode && vout[i].nValue == Params().MasternodeCollateral()) {
else if (fMasterNode && vout[i].nValue == Params().MasternodeCollateral()) {
nCredit += pwallet->GetCredit(txout, ISMINE_WATCH_ONLY);
}

Expand Down

0 comments on commit b65c8a9

Please sign in to comment.