Skip to content

Commit

Permalink
Update AutoSavings
Browse files Browse the repository at this point in the history
Add Change address to gui and rpc
Update ats gui page
Truncate to max if set
Prevent double sending
Save all settings to wallet.dat
  • Loading branch information
Tranz5 committed Nov 21, 2014
1 parent 24130f8 commit c4c84f1
Show file tree
Hide file tree
Showing 14 changed files with 354 additions and 95 deletions.
2 changes: 1 addition & 1 deletion src/bitcoinrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1234,8 +1234,8 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector<std::stri
if (strMethod == "sendalert" && n > 5) ConvertTo<boost::int64_t>(params[5]);
if (strMethod == "sendalert" && n > 6) ConvertTo<boost::int64_t>(params[6]);
if (strMethod == "autosavings" && n > 1) ConvertTo<int>(params[1]);
if (strMethod == "autosavings" && n > 2) ConvertTo<double>(params[2]);
if (strMethod == "autosavings" && n > 3) ConvertTo<double>(params[3]);
if (strMethod == "autosavings" && n > 3) ConvertTo<double>(params[4]);

return params;
}
Expand Down
10 changes: 5 additions & 5 deletions src/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static std::map<int, unsigned int> mapStakeModifierCheckpoints =
( 136822, 0xaafc7a2du )
( 477014, 0xd36de126 )
;

// Get time weight
int64 GetWeight(int64 nIntervalBeginning, int64 nIntervalEnd)
{
Expand Down Expand Up @@ -124,7 +124,7 @@ static bool SelectBlockFromCandidates(
// selected block of a given block group in the past.
// The selection of a block is based on a hash of the block's proof-hash and
// the previous stake modifier.
// Stake modifier is recomputed at a fixed time interval instead of every
// Stake modifier is recomputed at a fixed time interval instead of every
// block. This is to make it difficult for an attacker to gain control of
// additional bits in the stake modifier, even after generating a chain of
// blocks.
Expand Down Expand Up @@ -257,13 +257,13 @@ static bool GetKernelStakeModifier(uint256 hashBlockFrom, uint64& nStakeModifier
// this ensures that the chance of getting a coinstake is proportional to the
// amount of coin age one owns.
// The reason this hash is chosen is the following:
// nStakeModifier:
// nStakeModifier:
// (v0.3) scrambles computation to make it very difficult to precompute
// future proof-of-stake at the time of the coin's confirmation
// (v0.2) nBits (deprecated): encodes all past block timestamps
// txPrev.block.nTime: prevent nodes from guessing a good timestamp to
// generate transaction for future advantage
// txPrev.offset: offset of txPrev inside block, to reduce the chance of
// txPrev.offset: offset of txPrev inside block, to reduce the chance of
// nodes generating coinstake at the same time
// txPrev.nTime: reduce the chance of nodes generating coinstake at the same
// time
Expand Down Expand Up @@ -334,7 +334,7 @@ bool CheckStakeKernelHash(unsigned int nBits, const CBlock& blockFrom, unsigned
if (fDebug && !fPrintProofOfStake)
{
printf("CheckStakeKernelHash() : using modifier 0x%016"PRI64x" at height=%d timestamp=%s for block from height=%d timestamp=%s\n",
nStakeModifier, nStakeModifierHeight,
nStakeModifier, nStakeModifierHeight,
DateTimeStrFormat(nStakeModifierTime).c_str(),
mapBlockIndex[hashBlockFrom]->nHeight,
DateTimeStrFormat(blockFrom.GetBlockTime()).c_str());
Expand Down
13 changes: 11 additions & 2 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "net.h"
#include "savingsdialog.h"
#include "blockbrowser.h"
#include "base58.h"

#ifdef Q_OS_MAC
#include "macdockiconhandler.h"
Expand Down Expand Up @@ -691,6 +692,14 @@ void BitcoinGUI::stakingIconClicked()
uint64 nMinWeight = 0, nMaxWeight = 0, nWeight = 0;
walletModel->getStakeWeight(nMinWeight,nMaxWeight,nWeight);

CBitcoinAddress strAddress;
CBitcoinAddress strChangeAddress;
int nPer;
int64 nMin;
int64 nMax;

walletModel->getAutoSavings(nPer, strAddress, strChangeAddress, nMin, nMax);

int unit = clientModel->getOptionsModel()->getDisplayUnit();

message(tr("Extended Staking Information"),
Expand All @@ -715,8 +724,8 @@ void BitcoinGUI::stakingIconClicked()
.arg(clientModel->getPosKernalPS())
.arg(clientModel->getProofOfStakeReward())
.arg(nWeight)
.arg(walletModel->getAutoSavingsAddress())
.arg(walletModel->getAutoSavingsPercent())
.arg(strAddress.IsValid() ? strAddress.ToString().c_str() : "Not Saving")
.arg(nPer)
.arg(BitcoinUnits::formatWithUnit(unit, clientModel->getMoneySupply(), false))
,CClientUIInterface::MODAL);
}
Expand Down
1 change: 1 addition & 0 deletions src/qt/bitcoingui.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Notificator;
class RPCConsole;
class AutoSavingsDialog;
class BlockBrowser;
class CBitcoinAddress;

QT_BEGIN_NAMESPACE
class QLabel;
Expand Down
160 changes: 142 additions & 18 deletions src/qt/forms/savingsdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<property name="geometry">
<rect>
<x>20</x>
<y>150</y>
<y>110</y>
<width>131</width>
<height>20</height>
</rect>
Expand All @@ -35,17 +35,17 @@
<widget class="QLineEdit" name="savingsAddressEdit">
<property name="geometry">
<rect>
<x>20</x>
<y>190</y>
<width>571</width>
<x>110</x>
<y>150</y>
<width>481</width>
<height>21</height>
</rect>
</property>
<property name="toolTip">
<string/>
</property>
<property name="placeholderText">
<string>Enter Address to Send to</string>
<string>Enter Savings Address</string>
</property>
</widget>
<widget class="QLabel" name="label_2">
Expand All @@ -54,16 +54,15 @@
<x>30</x>
<y>20</y>
<width>591</width>
<height>81</height>
<height>61</height>
</rect>
</property>
<property name="lineWidth">
<number>1</number>
</property>
<property name="text">
<string>Auto Savings allows you to automatically send up to 50% of your stake to another BottleCaps address after it matures.

Please enter percentage to give and BottleCaps address to save to. Min and Max amount are optional.</string>
Please enter percentage to give and BottleCaps address to save to. Min and Max amount and change address are optional.</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
Expand All @@ -75,36 +74,36 @@ Please enter percentage to give and BottleCaps address to save to. Min and Max a
<widget class="QLineEdit" name="savingsMinEdit">
<property name="geometry">
<rect>
<x>250</x>
<y>150</y>
<width>131</width>
<x>230</x>
<y>110</y>
<width>151</width>
<height>20</height>
</rect>
</property>
<property name="toolTip">
<string>Enter whole numbers</string>
<string/>
</property>
<property name="placeholderText">
<string>Enter Min Amount</string>
<string>Enter Min Amount (optional)</string>
</property>
</widget>
<widget class="QLineEdit" name="savingsMaxEdit">
<property name="geometry">
<rect>
<x>490</x>
<y>150</y>
<width>131</width>
<x>460</x>
<y>110</y>
<width>151</width>
<height>20</height>
</rect>
</property>
<property name="toolTip">
<string>Enter whole numbers</string>
<string/>
</property>
<property name="text">
<string/>
</property>
<property name="placeholderText">
<string>Enter Max Amount</string>
<string>Enter Max Amount (optional)</string>
</property>
</widget>
<widget class="QLabel" name="message">
Expand All @@ -129,6 +128,9 @@ Please enter percentage to give and BottleCaps address to save to. Min and Max a
<height>23</height>
</rect>
</property>
<property name="toolTip">
<string/>
</property>
<property name="statusTip">
<string>Check and turn on Auto Savings</string>
</property>
Expand All @@ -153,6 +155,48 @@ Please enter percentage to give and BottleCaps address to save to. Min and Max a
</property>
</widget>
<widget class="QPushButton" name="addressBookButton">
<property name="geometry">
<rect>
<x>590</x>
<y>150</y>
<width>28</width>
<height>21</height>
</rect>
</property>
<property name="toolTip">
<string>Choose an address from the address book</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../bitcoin.qrc">
<normaloff>:/icons/address-book</normaloff>:/icons/address-book</iconset>
</property>
<property name="shortcut">
<string>Alt+A</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
<widget class="QLineEdit" name="savingsChangeAddressEdit">
<property name="geometry">
<rect>
<x>110</x>
<y>190</y>
<width>481</width>
<height>21</height>
</rect>
</property>
<property name="toolTip">
<string>Change address must be owned by you</string>
</property>
<property name="placeholderText">
<string>Enter Change Address (optional)</string>
</property>
</widget>
<widget class="QPushButton" name="changeAddressBookButton">
<property name="geometry">
<rect>
<x>590</x>
Expand All @@ -178,6 +222,86 @@ Please enter percentage to give and BottleCaps address to save to. Min and Max a
<bool>false</bool>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>50</x>
<y>90</y>
<width>61</width>
<height>20</height>
</rect>
</property>
<property name="toolTip">
<string>Percentage of stake to send</string>
</property>
<property name="text">
<string>Percentage:</string>
</property>
</widget>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>270</x>
<y>90</y>
<width>61</width>
<height>16</height>
</rect>
</property>
<property name="toolTip">
<string>Min amount to send</string>
</property>
<property name="text">
<string>Min Amount:</string>
</property>
</widget>
<widget class="QLabel" name="label_4">
<property name="geometry">
<rect>
<x>500</x>
<y>90</y>
<width>71</width>
<height>20</height>
</rect>
</property>
<property name="toolTip">
<string>Max amount to send</string>
</property>
<property name="text">
<string>Max Amount:</string>
</property>
</widget>
<widget class="QLabel" name="label_5">
<property name="geometry">
<rect>
<x>20</x>
<y>150</y>
<width>91</width>
<height>16</height>
</rect>
</property>
<property name="toolTip">
<string>Address to send portion of stake to</string>
</property>
<property name="text">
<string>Savings Address:</string>
</property>
</widget>
<widget class="QLabel" name="label_6">
<property name="geometry">
<rect>
<x>20</x>
<y>190</y>
<width>81</width>
<height>16</height>
</rect>
</property>
<property name="toolTip">
<string>The amount left over returned to you</string>
</property>
<property name="text">
<string>Change Address:</string>
</property>
</widget>
</widget>
<resources>
<include location="../bitcoin.qrc"/>
Expand Down
Loading

0 comments on commit c4c84f1

Please sign in to comment.