Skip to content

Commit 89275eb

Browse files
luke-jrinstagibbs
authored andcommitted
GUI: TransactionRecord: Special-case the common scenario where assets are simply issued to myself
1 parent 906cc4c commit 89275eb

File tree

1 file changed

+63
-4
lines changed

1 file changed

+63
-4
lines changed

src/qt/transactionrecord.cpp

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,67 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const interface
8080
{
8181
bool involvesWatchAddress = false;
8282
isminetype fAllFromMe = ISMINE_SPENDABLE;
83+
std::set<CAsset> assets_issued_to_me_only;
84+
CAmountMap assets_received_by_me_only;
85+
for (unsigned int i = 0; i < wtx.tx->vout.size(); i++)
86+
{
87+
const CAsset& asset = wtx.txout_assets[i];
88+
if (assets_received_by_me_only.count(asset) && assets_received_by_me_only.at(asset) < 0) {
89+
// Already known to be received by not-me
90+
continue;
91+
}
92+
isminetype mine = wtx.txout_address_is_mine[i];
93+
if (!mine) {
94+
assets_received_by_me_only[asset] = -1;
95+
} else {
96+
assets_received_by_me_only[asset] += wtx.txout_amounts[i];
97+
}
98+
}
99+
83100
for (size_t i = 0; i < wtx.tx->vin.size(); ++i)
84101
{
85102
isminetype mine = wtx.txin_is_mine[i];
86103
if(mine & ISMINE_WATCH_ONLY) involvesWatchAddress = true;
87104
if(fAllFromMe > mine) fAllFromMe = mine;
88-
if (!wtx.txin_issuance_asset[i].IsNull()) {
105+
const CAsset& asset = wtx.txin_issuance_asset[i];
106+
const CAmount& asset_amount = wtx.txin_issuance_asset_amount[i];
107+
const CAsset& token = wtx.txin_issuance_token[i];
108+
const CAmount& token_amount = wtx.txin_issuance_token_amount[i];
109+
if (!asset.IsNull()) {
110+
if (assets_received_by_me_only.count(asset) == 0) {
111+
continue;
112+
}
113+
if (asset_amount == assets_received_by_me_only.at(asset)) {
114+
// Special case: collapse the chain of issue, send, receive to just an issue
115+
assets_issued_to_me_only.insert(asset);
116+
continue;
117+
}
118+
119+
TransactionRecord sub(hash, nTime);
120+
sub.involvesWatchAddress = involvesWatchAddress;
121+
sub.asset = asset;
122+
sub.amount = asset_amount;
123+
sub.type = TransactionRecord::IssuedAsset;
124+
parts.append(sub);
125+
}
126+
if (!token.IsNull()) {
127+
if (assets_received_by_me_only.count(token) == 0) {
128+
continue;
129+
}
130+
if (token_amount == assets_received_by_me_only.at(asset)) {
131+
// Special case: collapse the chain of issue, send, receive to just an issue
132+
assets_issued_to_me_only.insert(asset);
133+
continue;
134+
}
135+
89136
TransactionRecord sub(hash, nTime);
90137
sub.involvesWatchAddress = involvesWatchAddress;
91-
sub.asset = wtx.txin_issuance_asset[i];
92-
sub.amount = wtx.txin_issuance_asset_amount[i];
138+
sub.asset = token;
139+
sub.amount = token_amount;
93140
sub.type = TransactionRecord::IssuedAsset;
94141
parts.append(sub);
95142
}
143+
96144
if (!wtx.txin_issuance_token[i].IsNull()) {
97145
TransactionRecord sub(hash, nTime);
98146
sub.involvesWatchAddress = involvesWatchAddress;
@@ -126,13 +174,16 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const interface
126174
}
127175
else if (fAllFromMe)
128176
{
177+
129178
//
130179
// Debit
131180
//
132181

133182
for (unsigned int nOut = 0; nOut < wtx.tx->vout.size(); nOut++)
134183
{
184+
135185
const CTxOut& txout = wtx.tx->vout[nOut];
186+
const CAsset& asset = wtx.txout_assets[nOut];
136187

137188
if(wtx.txout_is_mine[nOut] || txout.IsFee())
138189
{
@@ -141,11 +192,16 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const interface
141192
continue;
142193
}
143194

195+
// Short-circuit when it's an issuance to self
196+
if (assets_issued_to_me_only.count(asset) == 0) {
197+
continue;
198+
}
199+
144200
TransactionRecord sub(hash, nTime);
145201
sub.idx = nOut;
146202
sub.involvesWatchAddress = involvesWatchAddress;
147203
sub.amount = -wtx.txout_amounts[nOut];
148-
sub.asset = wtx.txout_assets[nOut];
204+
sub.asset = asset;
149205

150206
if (!boost::get<CNoDestination>(&wtx.txout_address[nOut]))
151207
{
@@ -159,6 +215,9 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const interface
159215
sub.type = TransactionRecord::SendToOther;
160216
sub.address = mapValue["to"];
161217
}
218+
if (assets_issued_to_me_only.count(asset)) {
219+
sub.type = TransactionRecord::IssuedAsset;
220+
}
162221
parts.append(sub);
163222
}
164223

0 commit comments

Comments
 (0)