Skip to content

Commit fe40f3e

Browse files
authored
Merge pull request #73 from IamLupo/master
fix: Block Explorer
2 parents 97d6a5b + aca5c68 commit fe40f3e

1 file changed

Lines changed: 89 additions & 95 deletions

File tree

src/qt/blockbrowser.cpp

Lines changed: 89 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -239,105 +239,99 @@ std::string getOutputs(const std::string &txid)
239239

240240
std::string getInputs(const std::string &txid)
241241
{
242-
uint256 hash;
243-
hash.SetHex(txid);
244-
245-
CTransaction tx;
246-
uint256 hashBlock = 0;
247-
if (!GetTransaction(hash, tx, hashBlock))
248-
return "fail";
249-
250-
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
251-
ssTx << tx;
252-
253-
std::string str = "";
254-
for (unsigned int i = 0; i < tx.vin.size(); i++)
255-
{
256-
uint256 hash;
257-
const CTxIn& vin = tx.vin[i];
258-
hash.SetHex(vin.prevout.hash.ToString());
259-
CTransaction wtxPrev;
260-
uint256 hashBlock = 0;
261-
if (!GetTransaction(hash, wtxPrev, hashBlock))
262-
return "fail";
263-
264-
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
265-
ssTx << wtxPrev;
266-
267-
CTxDestination source;
268-
ExtractDestination(wtxPrev.vout[vin.prevout.n].scriptPubKey, source);
269-
CDigitalNoteAddress addressSource(source);
270-
std::string lol6 = addressSource.ToString();
271-
const CScript target = wtxPrev.vout[vin.prevout.n].scriptPubKey;
272-
double buffer = convertCoins(getInputValue(wtxPrev, target));
273-
std::ostringstream ss;
274-
ss << std::fixed << std::setprecision(4) << buffer;
275-
std::string amount = ss.str();
276-
str.append(lol6);
277-
str.append(": ");
278-
str.append(amount);
279-
str.append(" XDN");
280-
str.append("\n");
281-
}
282-
283-
return str;
284-
}
285-
286-
int64_t getInputValue(CTransaction tx, CScript target)
287-
{
288-
for (unsigned int i = 0; i < tx.vin.size(); i++)
289-
{
290-
const CTxOut& txout = tx.vout[i];
291-
if(txout.scriptPubKey == target)
292-
{
293-
return txout.nValue;
294-
}
295-
}
296-
return 0;
242+
uint256 hash;
243+
hash.SetHex(txid);
244+
245+
CTransaction tx;
246+
uint256 hashBlock = 0;
247+
if (!GetTransaction(hash, tx, hashBlock))
248+
return "fail";
249+
250+
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
251+
ssTx << tx;
252+
253+
std::string str = "";
254+
for (unsigned int i = 0; i < tx.vin.size(); i++)
255+
{
256+
uint256 hash;
257+
const CTxIn& vin = tx.vin[i];
258+
259+
hash.SetHex(vin.prevout.hash.ToString());
260+
CTransaction wtxPrev;
261+
uint256 hashBlock = 0;
262+
263+
if (!GetTransaction(hash, wtxPrev, hashBlock))
264+
{
265+
return "fail";
266+
}
267+
268+
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
269+
ssTx << wtxPrev;
270+
271+
CTxDestination source;
272+
ExtractDestination(wtxPrev.vout[vin.prevout.n].scriptPubKey, source);
273+
CDigitalNoteAddress addressSource(source);
274+
275+
double amount = convertCoins(wtxPrev.vout[vin.prevout.n].nValue);
276+
277+
std::ostringstream ss_amount;
278+
ss << std::fixed << std::setprecision(4) << amount;
279+
280+
str.append(addressSource.ToString());
281+
str.append(": ");
282+
str.append(ss_amount.str());
283+
str.append(" XDN");
284+
str.append("\n");
285+
}
286+
287+
return str;
297288
}
298289

299290
double getTxFees(const std::string &txid)
300291
{
301-
uint256 hash;
302-
hash.SetHex(txid);
303-
304-
CTransaction tx;
305-
uint256 hashBlock = 0;
306-
if (!GetTransaction(hash, tx, hashBlock))
307-
return 51;
308-
309-
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
310-
ssTx << tx;
311-
312-
double value = 0;
313-
double buffer = 0;
314-
for (unsigned int i = 0; i < tx.vout.size(); i++)
315-
{
316-
const CTxOut& txout = tx.vout[i];
317-
318-
buffer = value + convertCoins(txout.nValue);
319-
value = buffer;
320-
}
321-
322-
double value0 = 0;
323-
double buffer0 = 0;
324-
for (unsigned int i = 0; i < tx.vin.size(); i++)
325-
{
326-
uint256 hash0;
327-
const CTxIn& vin = tx.vin[i];
328-
hash0.SetHex(vin.prevout.hash.ToString());
329-
CTransaction wtxPrev;
330-
uint256 hashBlock0 = 0;
331-
if (!GetTransaction(hash0, wtxPrev, hashBlock0))
332-
return 0;
333-
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
334-
ssTx << wtxPrev;
335-
const CScript target = wtxPrev.vout[vin.prevout.n].scriptPubKey;
336-
buffer0 = value0 + convertCoins(getInputValue(wtxPrev, target));
337-
value0 = buffer0;
338-
}
339-
340-
return value0 - value;
292+
uint256 hash;
293+
hash.SetHex(txid);
294+
295+
CTransaction tx;
296+
uint256 hashBlock = 0;
297+
if (!GetTransaction(hash, tx, hashBlock))
298+
{
299+
return 51;
300+
}
301+
302+
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
303+
ssTx << tx;
304+
305+
double out_value = 0;
306+
for (unsigned int i = 0; i < tx.vout.size(); i++)
307+
{
308+
const CTxOut& txout = tx.vout[i];
309+
310+
out_value += convertCoins(txout.nValue);
311+
}
312+
313+
double in_value = 0;
314+
315+
for (unsigned int i = 0; i < tx.vin.size(); i++)
316+
{
317+
uint256 hash0;
318+
const CTxIn& vin = tx.vin[i];
319+
hash0.SetHex(vin.prevout.hash.ToString());
320+
CTransaction wtxPrev;
321+
uint256 hashBlock0 = 0;
322+
323+
if (!GetTransaction(hash0, wtxPrev, hashBlock0))
324+
{
325+
return 0;
326+
}
327+
328+
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
329+
ssTx << wtxPrev;
330+
331+
in_value += convertCoins(wtxPrev.vout[vin.prevout.n].nValue);
332+
}
333+
334+
return in_value - out_value;
341335
}
342336

343337

0 commit comments

Comments
 (0)