MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / AddToWallet

Method AddToWallet

src/wallet/wallet.cpp:931–1013  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

929}
930
931bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose)
932{
933 LOCK(cs_wallet);
934
935 WalletBatch batch(*database, "r+", fFlushOnClose);
936
937 uint256 hash = wtxIn.GetHash();
938
939 // Inserts only if not already there, returns tx inserted or tx found
940 std::pair<std::map<uint256, CWalletTx>::iterator, bool> ret = mapWallet.insert(std::make_pair(hash, wtxIn));
941 CWalletTx& wtx = (*ret.first).second;
942 wtx.BindWallet(this);
943 bool fInsertedNew = ret.second;
944 if (fInsertedNew) {
945 wtx.nTimeReceived = GetAdjustedTime();
946 wtx.nOrderPos = IncOrderPosNext(&batch);
947 wtx.m_it_wtxOrdered = wtxOrdered.insert(std::make_pair(wtx.nOrderPos, TxPair(&wtx, nullptr)));
948 wtx.nTimeSmart = ComputeTimeSmart(wtx);
949 AddToSpends(hash);
950 }
951
952 bool fUpdated = false;
953 if (!fInsertedNew)
954 {
955 // Merge
956 if (!wtxIn.hashUnset() && wtxIn.hashBlock != wtx.hashBlock)
957 {
958 wtx.hashBlock = wtxIn.hashBlock;
959 fUpdated = true;
960 }
961 // If no longer abandoned, update
962 if (wtxIn.hashBlock.IsNull() && wtx.isAbandoned())
963 {
964 wtx.hashBlock = wtxIn.hashBlock;
965 fUpdated = true;
966 }
967 if (wtxIn.nIndex != -1 && (wtxIn.nIndex != wtx.nIndex))
968 {
969 wtx.nIndex = wtxIn.nIndex;
970 fUpdated = true;
971 }
972 if (wtxIn.fFromMe && wtxIn.fFromMe != wtx.fFromMe)
973 {
974 wtx.fFromMe = wtxIn.fFromMe;
975 fUpdated = true;
976 }
977 // If we have a witness-stripped version of this transaction, and we
978 // see a new version with a witness, then we must be upgrading a pre-segwit
979 // wallet. Store the new version of the transaction with the witness,
980 // as the stripped-version must be invalid.
981 // TODO: Store all versions of the transaction, instead of just one.
982 if (wtxIn.tx->HasWitness() && !wtx.tx->HasWitness()) {
983 wtx.SetTx(wtxIn.tx);
984 fUpdated = true;
985 }
986 }
987
988 //// debug print

Callers 4

importprunedfundsFunction · 0.80
AddTxFunction · 0.80
add_coinFunction · 0.80
BOOST_AUTO_TEST_CASEFunction · 0.80

Calls 15

GetAdjustedTimeFunction · 0.85
BindWalletMethod · 0.80
hashUnsetMethod · 0.80
isAbandonedMethod · 0.80
SetTxMethod · 0.80
WriteTxMethod · 0.80
NotifyTransactionChangedFunction · 0.50
GetHashMethod · 0.45
insertMethod · 0.45
IsNullMethod · 0.45
HasWitnessMethod · 0.45
ToStringMethod · 0.45

Tested by 3

AddTxFunction · 0.64
add_coinFunction · 0.64
BOOST_AUTO_TEST_CASEFunction · 0.64