105 lines
2.7 KiB
C++
105 lines
2.7 KiB
C++
/*
|
|
* Copyright (c) 2018, evilny0
|
|
*
|
|
* This file is part of cpfm.
|
|
*
|
|
* cpfm is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* cpm is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with cpfm. If not, see <http://www.gnu.org/licenses/>.
|
|
*
|
|
*/
|
|
|
|
#include "wallet.h"
|
|
#include "wallets/btc.h"
|
|
#include "wallets/bch.h"
|
|
#include "wallets/eth.h"
|
|
|
|
WalletsManager::WalletsManager(int userId)
|
|
{
|
|
m_userId = userId;
|
|
}
|
|
|
|
WalletsManager::~WalletsManager()
|
|
{
|
|
|
|
}
|
|
|
|
void WalletsManager::analyzeUserWallets()
|
|
{
|
|
mysql::connection db(getMysqlConfig());
|
|
const auto wallets = TableWallets{};
|
|
|
|
// Identify coins, we need one analyzer object per coin.
|
|
list<WalletHandler*> handlers;
|
|
for (const auto& row: db.run(select(wallets.type_id).from(wallets).where(wallets.user_id == m_userId).group_by(wallets.type_id)))
|
|
{
|
|
int typeId = row.type_id;
|
|
WalletHandler* walletHandler;
|
|
switch (typeId)
|
|
{
|
|
case CPFM_WALLET_TYPE_ID_BTC:
|
|
walletHandler = new WalletHandlerBTC(m_userId);
|
|
handlers.push_back(walletHandler);
|
|
break;
|
|
case CPFM_WALLET_TYPE_ID_BCH:
|
|
walletHandler = new WalletHandlerBCH(m_userId);
|
|
handlers.push_back(walletHandler);
|
|
break;
|
|
case CPFM_WALLET_TYPE_ID_ETH:
|
|
walletHandler = new WalletHandlerETH(m_userId);
|
|
handlers.push_back(walletHandler);
|
|
break;
|
|
default:
|
|
lerr << "Unsupported wallet type: " << typeId;
|
|
break;
|
|
}
|
|
}
|
|
|
|
emptyWalletsTx();
|
|
|
|
for (auto const& handler: handlers)
|
|
{
|
|
handler->analyzeUserWallets();
|
|
delete handler;
|
|
}
|
|
}
|
|
|
|
void WalletsManager::emptyWalletsTx()
|
|
{
|
|
mysql::connection db(getMysqlConfig());
|
|
const auto wallets = TableWallets{};
|
|
const auto wallets_tx = TableWalletsTx{};
|
|
|
|
list<int> userWallets;
|
|
for (const auto& row: db.run(select(wallets.wallet_id).from(wallets).where(wallets.user_id == m_userId)))
|
|
{
|
|
userWallets.push_back(row.wallet_id);
|
|
}
|
|
|
|
for (const auto& id: userWallets)
|
|
{
|
|
db.run(remove_from(wallets_tx).where(wallets_tx.wallet_id == id));
|
|
}
|
|
|
|
linfo << "Emptied Wallets Tx DB table for user " << m_userId;
|
|
}
|
|
|
|
WalletHandler::WalletHandler(int userId)
|
|
{
|
|
m_userId = userId;
|
|
}
|
|
|
|
WalletHandler::~WalletHandler()
|
|
{
|
|
|
|
}
|