From 45099b19daea9b78bf9823fab8d930211f738d7d Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Wed, 28 Dec 2011 11:14:05 +0100 Subject: Fix transaction type in UI: not all tx'es with "from"/"to" field are necessarily IP tx'es - Also, prepare for OP_EVAL by calling all transactions without bitcoin address "SendToOther"/"RecvFromOther", (IP tx'es are so rare they can be put together with funky EV_EVAL scripts) --- src/qt/transactionrecord.cpp | 39 +++++++++++++++++++-------------------- src/qt/transactionrecord.h | 4 ++-- src/qt/transactiontablemodel.cpp | 17 ++++++++--------- src/qt/transactionview.cpp | 4 ++-- 4 files changed, 31 insertions(+), 33 deletions(-) diff --git a/src/qt/transactionrecord.cpp b/src/qt/transactionrecord.cpp index 77c5a01260..52a3080e97 100644 --- a/src/qt/transactionrecord.cpp +++ b/src/qt/transactionrecord.cpp @@ -64,17 +64,10 @@ QList TransactionRecord::decomposeTransaction(const CWallet * sub.credit = nUnmatured; } } - else if (!mapValue["from"].empty() || !mapValue["message"].empty()) - { - // Received by IP connection - sub.type = TransactionRecord::RecvFromIP; - if (!mapValue["from"].empty()) - sub.address = mapValue["from"]; - } else { + bool foundAddress = false; // Received by Bitcoin Address - sub.type = TransactionRecord::RecvWithAddress; BOOST_FOREACH(const CTxOut& txout, wtx.vout) { if(wallet->IsMine(txout)) @@ -82,11 +75,19 @@ QList TransactionRecord::decomposeTransaction(const CWallet * CBitcoinAddress address; if (ExtractAddress(txout.scriptPubKey, wallet, address)) { + sub.type = TransactionRecord::RecvWithAddress; sub.address = address.ToString(); + foundAddress = true; + break; } - break; } } + if(!foundAddress) + { + // Received by IP connection, or other non-address transaction like OP_EVAL + sub.type = TransactionRecord::RecvFromOther; + sub.address = mapValue["from"]; + } } parts.append(sub); } @@ -127,21 +128,19 @@ QList TransactionRecord::decomposeTransaction(const CWallet * // from a transaction sent back to our own address. continue; } - else if(!mapValue["to"].empty()) + + CBitcoinAddress address; + if (ExtractAddress(txout.scriptPubKey, 0, address)) { - // Sent to IP - sub.type = TransactionRecord::SendToIP; - sub.address = mapValue["to"]; + // Sent to Bitcoin Address + sub.type = TransactionRecord::SendToAddress; + sub.address = address.ToString(); } else { - // Sent to Bitcoin Address - sub.type = TransactionRecord::SendToAddress; - CBitcoinAddress address; - if (ExtractAddress(txout.scriptPubKey, 0, address)) - { - sub.address = address.ToString(); - } + // Sent to IP, or other non-address transaction like OP_EVAL + sub.type = TransactionRecord::SendToOther; + sub.address = mapValue["to"]; } int64 nValue = txout.nValue; diff --git a/src/qt/transactionrecord.h b/src/qt/transactionrecord.h index 0050c878ee..84bf959b17 100644 --- a/src/qt/transactionrecord.h +++ b/src/qt/transactionrecord.h @@ -56,9 +56,9 @@ public: Other, Generated, SendToAddress, - SendToIP, + SendToOther, RecvWithAddress, - RecvFromIP, + RecvFromOther, SendToSelf }; diff --git a/src/qt/transactiontablemodel.cpp b/src/qt/transactiontablemodel.cpp index 0e1733f156..b863546691 100644 --- a/src/qt/transactiontablemodel.cpp +++ b/src/qt/transactiontablemodel.cpp @@ -345,12 +345,11 @@ QString TransactionTableModel::formatTxType(const TransactionRecord *wtx) const { case TransactionRecord::RecvWithAddress: return tr("Received with"); - case TransactionRecord::RecvFromIP: - return tr("Received from IP"); + case TransactionRecord::RecvFromOther: + return tr("Received from"); case TransactionRecord::SendToAddress: + case TransactionRecord::SendToOther: return tr("Sent to"); - case TransactionRecord::SendToIP: - return tr("Sent to IP"); case TransactionRecord::SendToSelf: return tr("Payment to yourself"); case TransactionRecord::Generated: @@ -367,10 +366,10 @@ QVariant TransactionTableModel::txAddressDecoration(const TransactionRecord *wtx case TransactionRecord::Generated: return QIcon(":/icons/tx_mined"); case TransactionRecord::RecvWithAddress: - case TransactionRecord::RecvFromIP: + case TransactionRecord::RecvFromOther: return QIcon(":/icons/tx_input"); case TransactionRecord::SendToAddress: - case TransactionRecord::SendToIP: + case TransactionRecord::SendToOther: return QIcon(":/icons/tx_output"); default: return QIcon(":/icons/tx_inout"); @@ -382,12 +381,12 @@ QString TransactionTableModel::formatTxToAddress(const TransactionRecord *wtx, b { switch(wtx->type) { - case TransactionRecord::RecvFromIP: + case TransactionRecord::RecvFromOther: return QString::fromStdString(wtx->address); case TransactionRecord::RecvWithAddress: case TransactionRecord::SendToAddress: return lookupAddress(wtx->address, tooltip); - case TransactionRecord::SendToIP: + case TransactionRecord::SendToOther: return QString::fromStdString(wtx->address); case TransactionRecord::SendToSelf: case TransactionRecord::Generated: @@ -478,7 +477,7 @@ QVariant TransactionTableModel::txStatusDecoration(const TransactionRecord *wtx) QString TransactionTableModel::formatTooltip(const TransactionRecord *rec) const { QString tooltip = formatTxStatus(rec) + QString("\n") + formatTxType(rec); - if(rec->type==TransactionRecord::RecvFromIP || rec->type==TransactionRecord::SendToIP || + if(rec->type==TransactionRecord::RecvFromOther || rec->type==TransactionRecord::SendToOther || rec->type==TransactionRecord::SendToAddress || rec->type==TransactionRecord::RecvWithAddress) { tooltip += QString(" ") + formatTxToAddress(rec, true); diff --git a/src/qt/transactionview.cpp b/src/qt/transactionview.cpp index 2dcbf1ea8a..3ef31854fb 100644 --- a/src/qt/transactionview.cpp +++ b/src/qt/transactionview.cpp @@ -70,9 +70,9 @@ TransactionView::TransactionView(QWidget *parent) : typeWidget->addItem(tr("All"), TransactionFilterProxy::ALL_TYPES); typeWidget->addItem(tr("Received with"), TransactionFilterProxy::TYPE(TransactionRecord::RecvWithAddress) | - TransactionFilterProxy::TYPE(TransactionRecord::RecvFromIP)); + TransactionFilterProxy::TYPE(TransactionRecord::RecvFromOther)); typeWidget->addItem(tr("Sent to"), TransactionFilterProxy::TYPE(TransactionRecord::SendToAddress) | - TransactionFilterProxy::TYPE(TransactionRecord::SendToIP)); + TransactionFilterProxy::TYPE(TransactionRecord::SendToOther)); typeWidget->addItem(tr("To yourself"), TransactionFilterProxy::TYPE(TransactionRecord::SendToSelf)); typeWidget->addItem(tr("Mined"), TransactionFilterProxy::TYPE(TransactionRecord::Generated)); typeWidget->addItem(tr("Other"), TransactionFilterProxy::TYPE(TransactionRecord::Other)); -- cgit v1.2.3 From 99e9601e805c009b301c7cb29d541858507ae095 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Tue, 3 Jan 2012 00:03:07 -0800 Subject: Fix horrific performance found by gmaxwell. --- src/serialize.h | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/serialize.h b/src/serialize.h index 7876990d04..b0ce065297 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -828,6 +828,38 @@ struct secure_allocator : public std::allocator }; +// +// Allocator that clears its contents before deletion. +// +template +struct zero_after_free_allocator : public std::allocator +{ + // MSVC8 default copy constructor is broken + typedef std::allocator base; + typedef typename base::size_type size_type; + typedef typename base::difference_type difference_type; + typedef typename base::pointer pointer; + typedef typename base::const_pointer const_pointer; + typedef typename base::reference reference; + typedef typename base::const_reference const_reference; + typedef typename base::value_type value_type; + zero_after_free_allocator() throw() {} + zero_after_free_allocator(const zero_after_free_allocator& a) throw() : base(a) {} + template + zero_after_free_allocator(const zero_after_free_allocator& a) throw() : base(a) {} + ~zero_after_free_allocator() throw() {} + template struct rebind + { typedef zero_after_free_allocator<_Other> other; }; + + void deallocate(T* p, std::size_t n) + { + if (p != NULL) + memset(p, 0, sizeof(T) * n); + std::allocator::deallocate(p, n); + } +}; + + // // Double ended buffer combining vector and stream-like interfaces. @@ -837,7 +869,7 @@ struct secure_allocator : public std::allocator class CDataStream { protected: - typedef std::vector > vector_type; + typedef std::vector > vector_type; vector_type vch; unsigned int nReadPos; short state; -- cgit v1.2.3