Skip to content

Commit 976b9ba

Browse files
authored
Merge pull request #1825 from jamescowens/implement_sidestake_send_display
rpc, wallet: Corrections to GetAmounts
2 parents 4cbf18c + 6f92294 commit 976b9ba

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -790,16 +790,18 @@ UniValue getbalancedetail(const UniValue& params, bool fHelp)
790790
{
791791
for (auto const& r : listReceived)
792792
{
793+
std::string address;
794+
793795
CBitcoinAddress addr;
794-
addr.Set(r.destination);
796+
address = addr.Set(r.destination) ? addr.ToString() : std::string {};
795797

796798
nBalance += r.amount;
797799

798800
UniValue item(UniValue::VOBJ);
799801

800802
item.pushKV("timestamp", (int64_t) wtx.nTime);
801803
item.pushKV("txid", txid.ToString());
802-
item.pushKV("address", addr.ToString());
804+
item.pushKV("address", address);
803805
item.pushKV("amount", ValueFromAmount(r.amount));
804806

805807
items.push_back(item);
@@ -808,16 +810,19 @@ UniValue getbalancedetail(const UniValue& params, bool fHelp)
808810

809811
for (auto const& s : listSent)
810812
{
813+
std::string address;
814+
811815
CBitcoinAddress addr;
812816
addr.Set(s.destination);
817+
address = addr.Set(s.destination) ? addr.ToString() : std::string {};
813818

814819
nBalance -= s.amount;
815820

816821
UniValue item(UniValue::VOBJ);
817822

818823
item.pushKV("timestamp", (int64_t) wtx.nTime);
819824
item.pushKV("txid", txid.ToString());
820-
item.pushKV("address", addr.ToString());
825+
item.pushKV("address", address);
821826
item.pushKV("amount", ValueFromAmount(-s.amount));
822827

823828
items.push_back(item);

src/wallet/wallet.cpp

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,8 @@ void CWalletTx::GetAmounts(list<COutputEntry>& listReceived, list<COutputEntry>&
778778

779779
strSentAccount = strFromAccount;
780780

781+
bool fIsFromMe = IsFromMe();
782+
781783
// Used for coinstake rollup.
782784
int64_t amount = 0;
783785

@@ -808,8 +810,10 @@ void CWalletTx::GetAmounts(list<COutputEntry>& listReceived, list<COutputEntry>&
808810
// 2) the output is to us (received)
809811
if (nDebit > 0)
810812
{
811-
// Don't report 'change' txouts
812-
if (pwallet->IsChange(txout)) continue;
813+
// If not a coinstake, don't report 'change' txouts. Txouts on change addresses for coinstakes
814+
// must be reported because a change address itself can stake, and there is no "change" on a
815+
// coinstake.
816+
if (!fIsCoinStake && pwallet->IsChange(txout)) continue;
813817
}
814818
else
815819
{
@@ -821,20 +825,21 @@ void CWalletTx::GetAmounts(list<COutputEntry>& listReceived, list<COutputEntry>&
821825

822826
// Send...
823827

824-
// If the output is either (output > 1 and a coinstake and the coinstake input, i.e. output 1, is mine, and
825-
// the selected output is not mine) OR (not a coinstake and nDebit > 0, i.e. a normal send transaction),
826-
// add the output as a "sent" entry. We exclude coinstake outputs 0 and 1 from sends, because output 0 is
827-
// empty and output 1 MUST go back to the staker (i.e. is not a send by definition).
828-
// Notice that a normal self-transaction, an entry will be created as a send and below as a receive for the
829-
// same output. The fee will be reported on the send but not on the receive because of the fee condition
830-
// above.
831-
if ((i > 1 && fIsCoinStakeMine && fIsMine == ISMINE_NO)
832-
|| (!fIsCoinStake && nDebit > 0))
828+
// If the output is not mine and ((output > 1 and a coinstake and the coinstake input, i.e. output 1, is mine)
829+
// OR (not a coinstake and nDebit > 0, i.e. a normal send transaction)), add the output as a "sent" entry.
830+
// We exclude coinstake outputs 0 and 1 from sends, because output 0 is empty and output 1 MUST go back to
831+
// the staker (i.e. is not a send by definition). Notice that for a normal self-transaction, the send and
832+
// receive details will be suppressed; however, the fee will be reported in the nFee parameter.
833+
if (fIsMine == ISMINE_NO && ((i > 1 && fIsCoinStakeMine) || (!fIsCoinStake && nDebit > 0)))
833834
{
834-
if (!ExtractDestination(txout.scriptPubKey, address) && txout.scriptPubKey[0] != OP_RETURN)
835+
if (!ExtractDestination(txout.scriptPubKey, address))
835836
{
836-
LogPrintf("CWalletTx::GetAmounts: Unknown transaction type found, txid %s",
837-
this->GetHash().ToString().c_str());
837+
if (txout.scriptPubKey[0] != OP_RETURN)
838+
{
839+
LogPrintf("CWalletTx::GetAmounts: Unknown transaction type found, txid %s",
840+
this->GetHash().ToString().c_str());
841+
}
842+
838843
address = CNoDestination();
839844
}
840845

@@ -870,9 +875,8 @@ void CWalletTx::GetAmounts(list<COutputEntry>& listReceived, list<COutputEntry>&
870875
}
871876
}
872877

873-
// If this is my output AND (it is not a coinstake OR the coinstake is not mine), add it as a
874-
// received entry.
875-
if (fIsMine != ISMINE_NO && (!fIsCoinStake || !fIsCoinStakeMine))
878+
// If this is my output AND the transaction is not from me, then record the output as received.
879+
if (fIsMine != ISMINE_NO && !fIsFromMe)
876880
{
877881
if (!ExtractDestination(txout.scriptPubKey, address) && txout.scriptPubKey[0] != OP_RETURN)
878882
{

0 commit comments

Comments
 (0)