| 4408 | } |
| 4409 | |
| 4410 | bool CWallet::AddTokenEntry(const CTokenInfo &token, bool fFlushOnClose) { |
| 4411 | LOCK(cs_wallet); |
| 4412 | |
| 4413 | CWalletDB walletdb(strWalletFile, "r+", fFlushOnClose); |
| 4414 | |
| 4415 | uint256 hash = token.GetHash(); |
| 4416 | |
| 4417 | bool fInsertedNew = true; |
| 4418 | |
| 4419 | std::map<uint256, CTokenInfo>::iterator it = mapToken.find(hash); |
| 4420 | if(it!=mapToken.end()) { |
| 4421 | fInsertedNew = false; |
| 4422 | } |
| 4423 | |
| 4424 | // Write to disk |
| 4425 | CTokenInfo wtoken = token; |
| 4426 | if(!fInsertedNew) { |
| 4427 | wtoken.nCreateTime = GetAdjustedTime(); |
| 4428 | } else { |
| 4429 | wtoken.nCreateTime = it->second.nCreateTime; |
| 4430 | } |
| 4431 | |
| 4432 | if (!walletdb.WriteToken(wtoken)) |
| 4433 | return false; |
| 4434 | |
| 4435 | mapToken[hash] = wtoken; |
| 4436 | |
| 4437 | NotifyTokenChanged(this, hash, fInsertedNew ? CT_NEW : CT_UPDATED); |
| 4438 | |
| 4439 | // Refresh token tx |
| 4440 | if(fInsertedNew) |
| 4441 | { |
| 4442 | for(auto it = mapTokenTx.begin(); it != mapTokenTx.end(); it++) |
| 4443 | { |
| 4444 | uint256 tokenTxHash = it->second.GetHash(); |
| 4445 | NotifyTokenTransactionChanged(this, tokenTxHash, CT_UPDATED); |
| 4446 | } |
| 4447 | } |
| 4448 | |
| 4449 | LogPrintf("AddTokenEntry %s\n", wtoken.GetHash().ToString()); |
| 4450 | |
| 4451 | return true; |
| 4452 | } |
| 4453 | |
| 4454 | bool CWallet::AddTokenTxEntry(const CTokenTx &tokenTx, bool fFlushOnClose) { |
| 4455 | LOCK(cs_wallet); |
no test coverage detected