Skip to content

Commit d5d7035

Browse files
authored
Merge pull request #2468 from iFoggz/scanforunspent
Improve upon scanforunspent rpc
2 parents 6378956 + b246012 commit d5d7035

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

src/rpc/rawtransaction.cpp

+17-14
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,8 @@ UniValue scanforunspent(const UniValue& params, bool fHelp)
12721272
if (!Address.IsValid())
12731273
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Gridcoin Address");
12741274

1275-
std::unordered_multimap<int64_t, std::pair<uint256, unsigned int>> uMultisig;
1275+
// Store as: TXID, VOUT, nValue, nHeight
1276+
std::vector<std::pair<std::pair<uint256, unsigned int>, std::pair<int64_t, int>>> Multisig;
12761277

12771278
{
12781279
LOCK(cs_main);
@@ -1325,8 +1326,8 @@ UniValue scanforunspent(const UniValue& params, bool fHelp)
13251326
if (!txindex.vSpent[dummy.n].IsNull())
13261327
continue;
13271328

1328-
// Add to multimap
1329-
uMultisig.insert(std::make_pair(txout.nValue, std::make_pair(tx.GetHash(), j)));
1329+
// Add to vector
1330+
Multisig.push_back(std::make_pair(std::make_pair(tx.GetHash(), j), std::make_pair(txout.nValue, pblkindex->nHeight)));
13301331
}
13311332
}
13321333
}
@@ -1340,7 +1341,7 @@ UniValue scanforunspent(const UniValue& params, bool fHelp)
13401341
res.pushKV("Block Start", nBlockStart);
13411342
res.pushKV("Block End", nBlockEnd);
13421343
// Check the end results
1343-
if (uMultisig.empty())
1344+
if (Multisig.empty())
13441345
res.pushKV("Result", "No utxos found in specified range");
13451346

13461347
else
@@ -1354,25 +1355,26 @@ UniValue scanforunspent(const UniValue& params, bool fHelp)
13541355
exportoutput << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<id>\n";
13551356

13561357
else if (nType == 1)
1357-
exportoutput << "TXID / VOUT / Value\n";
1358+
exportoutput << "TXID / VOUT / Value / HEIGHT\n";
13581359

13591360
}
13601361

13611362
int nCount = 0;
13621363
int64_t nValue = 0;
13631364

13641365
// Process the map
1365-
for (const auto& data : uMultisig)
1366+
for (const auto& data : Multisig)
13661367
{
13671368
nCount++;
13681369

1369-
nValue += data.first;
1370+
nValue += data.second.first;
13701371

13711372
UniValue txdata(UniValue::VOBJ);
13721373

1373-
txdata.pushKV("txid", data.second.first.ToString());
1374-
txdata.pushKV("vout", (int)data.second.second);
1375-
txdata.pushKV("value", ValueFromAmount(data.first));
1374+
txdata.pushKV("txid", data.first.first.ToString());
1375+
txdata.pushKV("vout", (int)data.first.second);
1376+
txdata.pushKV("value", ValueFromAmount(data.second.first));
1377+
txdata.pushKV("height", data.second.second);
13761378

13771379
txres.push_back(txdata);
13781380
// Parse into type file here
@@ -1382,14 +1384,15 @@ UniValue scanforunspent(const UniValue& params, bool fHelp)
13821384
if (nType == 0)
13831385
{
13841386
exportoutput << spacing << "<tx id=\"" << nCount << "\">\n";
1385-
exportoutput << spacing << spacing << "<txid>" << data.second.first.ToString() << "</txid>\n";
1386-
exportoutput << spacing << spacing << "<vout>" << data.second.second << "</vout>\n";
1387-
exportoutput << spacing << spacing << "<value>" << std::fixed << setprecision(8) << data.first / (double)COIN << "</value>\n";
1387+
exportoutput << spacing << spacing << "<txid>" << data.first.first.ToString() << "</txid>\n";
1388+
exportoutput << spacing << spacing << "<vout>" << data.first.second << "</vout>\n";
1389+
exportoutput << spacing << spacing << "<value>" << std::fixed << setprecision(8) << data.second.first / (double)COIN << "</value>\n";
1390+
exportoutput << spacing << spacing << "<height>" << data.second.second << "</height>\n";
13881391
exportoutput << spacing << "</tx>\n";
13891392
}
13901393

13911394
else if (nType == 1)
1392-
exportoutput << data.second.first.ToString() << " / " << data.second.second << " / " << std::fixed << setprecision(8) << data.first / (double)COIN << "\n";
1395+
exportoutput << data.first.first.ToString() << " / " << data.first.second << " / " << std::fixed << setprecision(8) << data.second.first / (double)COIN << " / " << data.second.second << "\n";
13931396
}
13941397
}
13951398

0 commit comments

Comments
 (0)