Add CWallet::ExtractAddress method
authoralex <balthazar@yandex.ru>
Tue, 23 Feb 2016 23:27:02 +0000 (02:27 +0300)
committeralex <balthazar@yandex.ru>
Tue, 23 Feb 2016 23:27:02 +0000 (02:27 +0300)
src/qt/coincontroldialog.cpp
src/qt/transactionrecord.cpp
src/qt/walletmodel.cpp
src/wallet.cpp
src/wallet.h

index ae73042..998a992 100644 (file)
@@ -631,6 +631,7 @@ void CoinControlDialog::updateView()
             itemOutput->setCheckState(COLUMN_CHECKBOX,Qt::Unchecked);
 
             // address
+/*
             CTxDestination outputAddress;
             QString sAddress = "";
             if(ExtractDestination(out.tx->vout[out.i].scriptPubKey, outputAddress))
@@ -646,6 +647,52 @@ void CoinControlDialog::updateView()
                 if (keyid && model->getPubKey(*keyid, pubkey) && !pubkey.IsCompressed())
                     nInputSize = 180;
             }
+*/
+            QString sAddress = "";
+            txnouttype whichType;
+            std::vector<valtype> vSolutions;
+            if (Solver(out.tx->vout[out.i].scriptPubKey, whichType, vSolutions))
+            {
+                CTxDestination address;
+                if (whichType == TX_PUBKEY)
+                {
+                    // Pay-to-Pubkey
+                    CPubKey pubKey = CPubKey(vSolutions[0]);
+                    address = pubKey.GetID();
+                    sAddress = CBitcoinAddress(address).ToString().c_str();
+
+                    if (!pubKey.IsCompressed())
+                        nInputSize = 180;
+                }
+                else if (whichType == TX_PUBKEYHASH)
+                {
+                    // Pay-to-PubkeyHash
+                    address = CKeyID(uint160(vSolutions[0]));
+                    sAddress = CBitcoinAddress(address).ToString().c_str();
+
+                    CPubKey pubkey;
+                    CKeyID *keyid = boost::get< CKeyID >(&address);
+                    if (keyid && model->getPubKey(*keyid, pubkey) && !pubkey.IsCompressed())
+                        nInputSize = 180;
+                }
+                else if (whichType == TX_SCRIPTHASH)
+                {
+                    // Pay-to-ScriptHash
+                    address = CScriptID(uint160(vSolutions[0]));
+                    sAddress = CBitcoinAddress(address).ToString().c_str();
+                }
+                else if (whichType == TX_PUBKEY_DROP)
+                {
+                    // Pay-to-Pubkey-R
+                    CMalleableKeyView view;
+                    pwalletMain->CheckOwnership(CPubKey(vSolutions[0]), CPubKey(vSolutions[1]), view);
+                    sAddress = view.GetMalleablePubKey().ToString().c_str();
+                }
+
+                // if listMode or change => show bitcoin address. In tree mode, address is not shown again for direct wallet address outputs
+                if (!treeMode || (!(sAddress == sWalletAddress)))
+                    itemOutput->setText(COLUMN_ADDRESS, sAddress);
+            }
 
             // label
             if (!(sAddress == sWalletAddress)) // change
index 7c50f91..e28a64b 100644 (file)
@@ -46,48 +46,19 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet *
                 sub.idx = parts.size(); // sequence number
                 sub.credit = txout.nValue;
 
-                txnouttype whichType;
-                std::vector<valtype> vSolutions;
-                if (Solver(txout.scriptPubKey, whichType, vSolutions))
+                std::string address;
+                if (pwalletMain->ExtractAddress(txout.scriptPubKey, address))
                 {
-                    CTxDestination address;
-                    if (whichType == TX_PUBKEY)
-                    {
-                        // Pay-to-Pubkey
-                        address = CPubKey(vSolutions[0]).GetID();
-                        sub.type = TransactionRecord::RecvWithAddress;
-                        sub.address = CBitcoinAddress(address).ToString();
-                    }
-                    else if (whichType == TX_PUBKEYHASH)
-                    {
-                        // Pay-to-PubkeyHash
-                        address = CKeyID(uint160(vSolutions[0]));
-                        sub.type = TransactionRecord::RecvWithAddress;
-                        sub.address = CBitcoinAddress(address).ToString();
-                    }
-                    else if (whichType == TX_SCRIPTHASH)
-                    {
-                        // Pay-to-ScriptHash
-                        address = CScriptID(uint160(vSolutions[0]));
-                        sub.type = TransactionRecord::RecvWithAddress;
-                        sub.address = CBitcoinAddress(address).ToString();
-                    }
-                    else if (whichType == TX_PUBKEY_DROP)
-                    {
-                        // Pay-to-Pubkey-R
-                        sub.type = TransactionRecord::RecvWithAddress;
-
-                        CMalleableKeyView view;
-                        pwalletMain->CheckOwnership(CPubKey(vSolutions[0]), CPubKey(vSolutions[1]), view);
-                        sub.address = view.GetMalleablePubKey().ToString();
-                    }
-                    else
-                    {
-                        // Received by IP connection (deprecated features), or a multisignature or other non-simple transaction
-                        sub.type = TransactionRecord::RecvFromOther;
-                        sub.address = mapValue["from"];
-                    }
+                    sub.type = TransactionRecord::RecvWithAddress;
+                    sub.address = address;
                 }
+                else
+                {
+                    // Received by IP connection (deprecated features), or a multisignature or other non-simple transaction
+                    sub.type = TransactionRecord::RecvFromOther;
+                    sub.address = mapValue["from"];
+                }
+
                 if (wtx.IsCoinBase())
                 {
                     // Generated (proof-of-work)
index 4769fda..47b12e9 100644 (file)
@@ -495,10 +495,11 @@ void WalletModel::listCoins(std::map<QString, std::vector<COutput> >& mapCoins)
             cout = COutput(&wallet->mapWallet[cout.tx->vin[0].prevout.hash], cout.tx->vin[0].prevout.n, 0, true);
         }
 
-        CTxDestination address;
-        if(!out.fSpendable || !ExtractDestination(cout.tx->vout[cout.i].scriptPubKey, address))
+        std::string address;
+        if(!out.fSpendable || !wallet->ExtractAddress(cout.tx->vout[cout.i].scriptPubKey, address))
             continue;
-        mapCoins[CBitcoinAddress(address).ToString().c_str()].push_back(out);
+
+        mapCoins[address.c_str()].push_back(out);
     }
 }
 
index d5e3285..780c7f4 100644 (file)
@@ -2780,3 +2780,39 @@ void CWallet::ClearOrphans()
     for(list<uint256>::const_iterator it = orphans.begin(); it != orphans.end(); ++it)
         EraseFromWallet(*it);
 }
+
+bool CWallet::ExtractAddress(const CScript& scriptPubKey, std::string& addressRet)
+{
+    vector<valtype> vSolutions;
+    txnouttype whichType;
+    if (!Solver(scriptPubKey, whichType, vSolutions))
+        return false;
+
+    if (whichType == TX_PUBKEY)
+    {
+        addressRet = CBitcoinAddress(CPubKey(vSolutions[0]).GetID()).ToString();
+        return true;
+    }
+    if (whichType == TX_PUBKEY_DROP)
+    {
+        // Pay-to-Pubkey-R
+        CMalleableKeyView view;
+        if (!CheckOwnership(CPubKey(vSolutions[0]), CPubKey(vSolutions[1]), view))
+            return false;
+
+        addressRet = view.GetMalleablePubKey().ToString();
+        return true;
+    }
+    else if (whichType == TX_PUBKEYHASH)
+    {
+        addressRet = CBitcoinAddress(CKeyID(uint160(vSolutions[0]))).ToString();
+        return true;
+    }
+    else if (whichType == TX_SCRIPTHASH)
+    {
+        addressRet = CBitcoinAddress(CScriptID(uint160(vSolutions[0]))).ToString();
+        return true;
+    }
+    // Multisig txns have more than one address...
+    return false;
+}
index bc8afa8..12d8af5 100644 (file)
@@ -337,6 +337,8 @@ public:
 
     bool GetTransaction(const uint256 &hashTx, CWalletTx& wtx);
 
+    bool ExtractAddress(const CScript& scriptPubKey, std::string& addressRet);
+
     bool SetDefaultKey(const CPubKey &vchPubKey);
 
     // signify that a particular wallet feature is now used. this may change nWalletVersion and nWalletMaxVersion if those are lower