Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
Fix bugs caused by not using 7 digit block counts
Browse files Browse the repository at this point in the history
  • Loading branch information
zathras-crypto committed Mar 17, 2017
1 parent e89100e commit 917a63f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/omnicore/fetchwallettx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ std::map<std::string, uint256> FetchWalletOmniTransactions(unsigned int count, i
int blockHeight = pBlockIndex->nHeight;
if (blockHeight < startBlock || blockHeight > endBlock) continue;
int blockPosition = GetTransactionByteOffset(txHash);
std::string sortKey = strprintf("%06d%010d", blockHeight, blockPosition);
std::string sortKey = strprintf("%07d%010d", blockHeight, blockPosition);
mapResponse.insert(std::make_pair(sortKey, txHash));
seenHashes.insert(txHash);
if (mapResponse.size() >= count) break;
Expand All @@ -94,7 +94,7 @@ std::map<std::string, uint256> FetchWalletOmniTransactions(unsigned int count, i
// LOCK(cs_pending);
for (PendingMap::const_iterator it = my_pending.begin(); it != my_pending.end(); ++it) {
const uint256& txHash = it->first;
int blockHeight = 999999;
int blockHeight = 9999999;
if (blockHeight < startBlock || blockHeight > endBlock) continue;
int blockPosition = 0;
{
Expand All @@ -105,7 +105,7 @@ std::map<std::string, uint256> FetchWalletOmniTransactions(unsigned int count, i
blockPosition = wtx.nOrderPos;
}
}
std::string sortKey = strprintf("%06d%010d", blockHeight, blockPosition);
std::string sortKey = strprintf("%07d%010d", blockHeight, blockPosition);
mapResponse.insert(std::make_pair(sortKey, txHash));
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/omnicore/omnicore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ static int msc_initial_scan(int nFirstBlock)
int64_t nNow = GetTime();
unsigned int nTxsTotal = 0;
unsigned int nTxsFoundTotal = 0;
int nBlock = 999999;
int nBlock = 9999999;
const int nLastBlock = GetHeight();

// this function is useless if there are not enough blocks in the blockchain yet!
Expand Down
4 changes: 2 additions & 2 deletions src/omnicore/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ UniValue omni_listtransactions(const UniValue& params, bool fHelp)
"2. count (number, optional) show at most n transactions (default: 10)\n"
"3. skip (number, optional) skip the first n transactions (default: 0)\n"
"4. startblock (number, optional) first block to begin the search (default: 0)\n"
"5. endblock (number, optional) last block to include in the search (default: 999999)\n"
"5. endblock (number, optional) last block to include in the search (default: 9999999)\n"
"\nResult:\n"
"[ (array of JSON objects)\n"
" {\n"
Expand Down Expand Up @@ -1034,7 +1034,7 @@ UniValue omni_listtransactions(const UniValue& params, bool fHelp)
int64_t nStartBlock = 0;
if (params.size() > 3) nStartBlock = params[3].get_int64();
if (nStartBlock < 0) throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative start block");
int64_t nEndBlock = 999999;
int64_t nEndBlock = 9999999;
if (params.size() > 4) nEndBlock = params[4].get_int64();
if (nEndBlock < 0) throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative end block");

Expand Down
14 changes: 8 additions & 6 deletions src/qt/txhistorydialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,9 @@ int TXHistoryDialog::PopulateHistoryMap()
const CMPPending& pending = pending_it->second;
HistoryTXObject htxo;
htxo.blockHeight = 0;
if (it->first.length() == 16) htxo.blockByteOffset = atoi(it->first.substr(6)); // use wallet position from key in lieu of block position
if (it->first.length() == 17) {
htxo.blockByteOffset = atoi(it->first.substr(7)); // use wallet position from key in lieu of block position
}
htxo.valid = true; // all pending transactions are assumed to be valid prior to confirmation (wallet would not send them otherwise)
htxo.address = pending.src;
htxo.amount = "-" + FormatShortMP(pending.prop, pending.amount) + getTokenLabel(pending.prop);
Expand All @@ -248,9 +250,9 @@ int TXHistoryDialog::PopulateHistoryMap()
CMPTransaction mp_obj;
int parseRC = ParseTransaction(wtx, blockHeight, 0, mp_obj);
HistoryTXObject htxo;
if (it->first.length() == 16) {
htxo.blockHeight = atoi(it->first.substr(0,6));
htxo.blockByteOffset = atoi(it->first.substr(6));
if (it->first.length() == 17) {
htxo.blockHeight = atoi(it->first.substr(0,7));
htxo.blockByteOffset = atoi(it->first.substr(7));
}

// handle Omni transaction
Expand Down Expand Up @@ -365,8 +367,8 @@ void TXHistoryDialog::UpdateHistory()
QTableWidgetItem *amountCell = new QTableWidgetItem(QString::fromStdString(htxo.amount));
QTableWidgetItem *iconCell = new QTableWidgetItem;
QTableWidgetItem *txidCell = new QTableWidgetItem(QString::fromStdString(txid.GetHex()));
std::string sortKey = strprintf("%06d%010d",htxo.blockHeight,htxo.blockByteOffset);
if(htxo.blockHeight == 0) sortKey = strprintf("%06d%010D",999999,htxo.blockByteOffset); // spoof the hidden value to ensure pending txs are sorted top
std::string sortKey = strprintf("%07d%010d",htxo.blockHeight,htxo.blockByteOffset);
if(htxo.blockHeight == 0) sortKey = strprintf("%07d%010D",9999999,htxo.blockByteOffset); // spoof the hidden value to ensure pending txs are sorted top
QTableWidgetItem *sortKeyCell = new QTableWidgetItem(QString::fromStdString(sortKey));
addressCell->setTextAlignment(Qt::AlignLeft + Qt::AlignVCenter);
addressCell->setForeground(QColor("#707070"));
Expand Down

0 comments on commit 917a63f

Please sign in to comment.