diff --git a/divi/src/TransactionDiskAccessor.cpp b/divi/src/TransactionDiskAccessor.cpp index fcf6d2697..e4608c875 100644 --- a/divi/src/TransactionDiskAccessor.cpp +++ b/divi/src/TransactionDiskAccessor.cpp @@ -24,7 +24,7 @@ bool GetTransaction(const uint256& hash, CTransaction& txOut, uint256& hashBlock { LOCK(cs_main); { - if (mempool.lookup(hash, txOut)) { + if (mempool.lookup(hash, txOut) || mempool.lookupBareTxid(hash, txOut)) { return true; } } @@ -49,8 +49,9 @@ bool GetTransaction(const uint256& hash, CTransaction& txOut, uint256& hashBlock return true; } - // transaction not found in the index, nothing more can be done - return false; + // The index only keys by txid. So even if we did not find the + // transaction here, it could be that the lookup is by bare txid + // and can be found through UTXO lookup. } if (fAllowSlow) { // use coin database to locate block that contains transaction, and scan it @@ -70,7 +71,7 @@ bool GetTransaction(const uint256& hash, CTransaction& txOut, uint256& hashBlock CBlock block; if (ReadBlockFromDisk(block, pindexSlow)) { BOOST_FOREACH (const CTransaction& tx, block.vtx) { - if (tx.GetHash() == hash) { + if (tx.GetHash() == hash || tx.GetBareTxid() == hash) { txOut = tx; hashBlock = pindexSlow->GetBlockHash(); return true; @@ -101,4 +102,4 @@ bool CollateralIsExpectedAmount(const COutPoint &outpoint, int64_t expectedAmoun return true; } assert(false); -} \ No newline at end of file +} diff --git a/divi/src/WalletTransactionRecord.cpp b/divi/src/WalletTransactionRecord.cpp index 14fee3e18..a94324812 100644 --- a/divi/src/WalletTransactionRecord.cpp +++ b/divi/src/WalletTransactionRecord.cpp @@ -30,11 +30,22 @@ WalletTransactionRecord::WalletTransactionRecord( const CWalletTx* WalletTransactionRecord::GetWalletTx(const uint256& hash) const { AssertLockHeld(cs_walletTxRecord); - std::map::const_iterator it = mapWallet.find(hash); - if (it == mapWallet.end()) - return NULL; - return &(it->second); + + { + const auto mit = mapWallet.find(hash); + if (mit != mapWallet.end()) + return &mit->second; + } + + { + const auto mit = mapBareTxid.find(hash); + if (mit != mapBareTxid.end()) + return mit->second; + } + + return nullptr; } + std::vector WalletTransactionRecord::GetWalletTransactionReferences() const { AssertLockHeld(cs_walletTxRecord); @@ -50,7 +61,12 @@ std::vector WalletTransactionRecord::GetWalletTransactionRefer std::pair::iterator, bool> WalletTransactionRecord::AddTransaction(const CWalletTx& newlyAddedTransaction) { AssertLockHeld(cs_walletTxRecord); - return mapWallet.insert(std::make_pair(newlyAddedTransaction.GetHash(), newlyAddedTransaction)); + + auto res = mapWallet.emplace(newlyAddedTransaction.GetHash(), newlyAddedTransaction); + if (res.second) + mapBareTxid.emplace(newlyAddedTransaction.GetBareTxid(), &res.first->second); + + return res; }; void WalletTransactionRecord::UpdateMetadata( diff --git a/divi/src/WalletTransactionRecord.h b/divi/src/WalletTransactionRecord.h index 53e5c7944..30a2d793e 100644 --- a/divi/src/WalletTransactionRecord.h +++ b/divi/src/WalletTransactionRecord.h @@ -10,15 +10,23 @@ struct WalletTransactionRecord CCriticalSection& cs_walletTxRecord; const std::string walletFilename_; const bool databaseWritesAreDisallowed_; + + /** Map from the bare txid of transactions in the wallet to the matching + * transactions themselves. */ + std::map mapBareTxid; + public: std::map mapWallet; WalletTransactionRecord(CCriticalSection& requiredWalletLock,const std::string& walletFilename); WalletTransactionRecord(CCriticalSection& requiredWalletLock); const CWalletTx* GetWalletTx(const uint256& hash) const; + + /** Tries to look up a transaction in the wallet, either by hash (txid) or + * the bare txid that is used after segwit-light to identify outputs. */ std::vector GetWalletTransactionReferences() const; std::pair::iterator, bool> AddTransaction(const CWalletTx& newlyAddedTransaction); void UpdateMetadata(const uint256& hashOfTransactionToUpdate, const CWalletTx& updatedTransaction, bool updateDiskAndTimestamp,bool writeToWalletDb=false); }; -#endif// WALLET_TRANSACTION_RECORD_H \ No newline at end of file +#endif// WALLET_TRANSACTION_RECORD_H diff --git a/divi/src/rpcmasternode.cpp b/divi/src/rpcmasternode.cpp index 759c35f64..ee8ac4fb1 100644 --- a/divi/src/rpcmasternode.cpp +++ b/divi/src/rpcmasternode.cpp @@ -78,7 +78,7 @@ Value allocatefunds(const Array& params, bool fHelp) " (numeric, required) amount of divi funded will also be accepted for partially funding master nodes and other purposes.\n" "\nResult:\n" - "\"vin\" (string) funding transaction id necessary for next step.\n"); + "\"vin\" (string) funding transaction id or bare txid necessary for next step.\n"); if (params[0].get_str() != "masternode") { @@ -114,7 +114,7 @@ Value fundmasternode(const Array& params, bool fHelp) "1. alias (string, required) helpful identifier to recognize this allocation later.\n" "2. amount (diamond, platinum, gold, silver, copper) tier of masternode. \n" " (numeric, required) amount of divi funded will also be accepted for partially funding master nodes and other purposes.\n" - "3. TxID (string, required) funding transaction id .\n" + "3. TxID (string, required) funding transaction id or bare txid.\n" "4. masternode (string, required) ip address of masternode.\n" "(use an empty string for the pay wallet if the same as the funding wallet and you wish to assign a different voting wallet).\n" @@ -229,7 +229,7 @@ Value setupmasternode(const Array& params, bool fHelp) "\nArguments:\n" "1. alias (string, required) Helpful identifier to recognize this masternode later. \n" - "2. txHash (string, required) Funding transaction. \n" + "2. txHash (string, required) Funding transaction hash or bare txid. \n" "3. outputIndex (string, required) Output index transaction. \n" "4. collateralPubkey (string, required) collateral pubkey. \n" "5. ip_address (string, required) Local ip address of this node\n"