MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / SyncTransaction

Method SyncTransaction

src/wallet/wallet.cpp:113–173  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

111}
112
113void CWallet::SyncTransaction(const uint256 &hash, CBaseTx *pTx, const CBlock *pBlock) {
114 assert(pTx != nullptr || pBlock != nullptr);
115
116 if (hash.IsNull() && pTx == nullptr) { // this is block Sync
117 uint256 blockhash = pBlock->GetHash();
118 auto GenesisBlockProgress = [&]() {};
119
120 auto ConnectBlockProgress = [&]() {
121 CWalletAccountTxDb acctTxDb(this, blockhash, pBlock->GetHeight());
122 for (const auto &sptx : pBlock->vptx) {
123 uint256 txid = sptx->GetHash();
124 // confirm the tx is mine
125 if (IsMine(sptx.get())) {
126 acctTxDb.AddTx(txid, sptx.get());
127 }
128 if (unconfirmedTx.count(txid) > 0) {
129 CWalletDB(strWalletFile).EraseUnconfirmedTx(txid);
130 unconfirmedTx.erase(txid);
131 }
132 }
133 if (acctTxDb.GetTxSize() > 0) { // write to disk
134 mapInBlockTx[blockhash] = acctTxDb; // add to map
135 acctTxDb.WriteToDisk();
136 }
137 };
138
139 auto DisConnectBlockProgress = [&]() {
140 for (const auto &sptx : pBlock->vptx) {
141 if (sptx->IsBlockRewardTx()) {
142 continue;
143 }
144 if (IsMine(sptx.get())) {
145 unconfirmedTx[sptx.get()->GetHash()] = sptx.get()->GetNewInstance();
146 CWalletDB(strWalletFile).WriteUnconfirmedTx(sptx.get()->GetHash(), unconfirmedTx[sptx.get()->GetHash()]);
147 }
148 }
149 if (mapInBlockTx.count(blockhash)) {
150 CWalletDB(strWalletFile).EraseBlockTx(blockhash);
151 mapInBlockTx.erase(blockhash);
152 }
153 };
154
155 auto IsConnect = [&]() { // Connect or disconnect
156 return mapBlockIndex.count(blockhash) && chainActive.Contains(mapBlockIndex[blockhash]);
157 };
158
159 {
160 LOCK2(cs_main, cs_wallet);
161 // GenesisBlock progress
162 if (SysCfg().GetGenesisBlockHash() == blockhash) {
163 GenesisBlockProgress();
164 } else if (IsConnect()) {
165 // connect block
166 ConnectBlockProgress();
167 } else {
168 // disconnect block
169 DisConnectBlockProgress();
170 }

Callers 1

SyncTransactionFunction · 0.80

Calls 15

CWalletDBClass · 0.85
AddTxMethod · 0.80
EraseUnconfirmedTxMethod · 0.80
IsBlockRewardTxMethod · 0.80
WriteUnconfirmedTxMethod · 0.80
EraseBlockTxMethod · 0.80
GetGenesisBlockHashMethod · 0.80
IsNullMethod · 0.45
GetHashMethod · 0.45
GetHeightMethod · 0.45
getMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected