Changeset View
Changeset View
Standalone View
Standalone View
src/interfaces/wallet.cpp
Show All 37 Lines | public: | ||||
PendingWalletTxImpl(CWallet &wallet) | PendingWalletTxImpl(CWallet &wallet) | ||||
: m_wallet(wallet), m_key(&wallet) {} | : m_wallet(wallet), m_key(&wallet) {} | ||||
const CTransaction &get() override { return *m_tx; } | const CTransaction &get() override { return *m_tx; } | ||||
bool commit(WalletValueMap value_map, WalletOrderForm order_form, | bool commit(WalletValueMap value_map, WalletOrderForm order_form, | ||||
std::string from_account, | std::string from_account, | ||||
std::string &reject_reason) override { | std::string &reject_reason) override { | ||||
LOCK2(cs_main, m_wallet.cs_wallet); | auto locked_chain = m_wallet.chain().lock(); | ||||
LOCK(m_wallet.cs_wallet); | |||||
CValidationState state; | CValidationState state; | ||||
if (!m_wallet.CommitTransaction( | if (!m_wallet.CommitTransaction( | ||||
m_tx, std::move(value_map), std::move(order_form), | m_tx, std::move(value_map), std::move(order_form), | ||||
std::move(from_account), m_key, g_connman.get(), state)) { | std::move(from_account), m_key, g_connman.get(), state)) { | ||||
reject_reason = state.GetRejectReason(); | reject_reason = state.GetRejectReason(); | ||||
return false; | return false; | ||||
} | } | ||||
return true; | return true; | ||||
▲ Show 20 Lines • Show All 157 Lines • ▼ Show 20 Lines | public: | ||||
LOCK(m_wallet.cs_wallet); | LOCK(m_wallet.cs_wallet); | ||||
return m_wallet.EraseDestData(dest, key); | return m_wallet.EraseDestData(dest, key); | ||||
} | } | ||||
std::vector<std::string> | std::vector<std::string> | ||||
getDestValues(const std::string &prefix) override { | getDestValues(const std::string &prefix) override { | ||||
return m_wallet.GetDestValues(prefix); | return m_wallet.GetDestValues(prefix); | ||||
} | } | ||||
void lockCoin(const COutPoint &output) override { | void lockCoin(const COutPoint &output) override { | ||||
LOCK2(cs_main, m_wallet.cs_wallet); | auto locked_chain = m_wallet.chain().lock(); | ||||
LOCK(m_wallet.cs_wallet); | |||||
return m_wallet.LockCoin(output); | return m_wallet.LockCoin(output); | ||||
} | } | ||||
void unlockCoin(const COutPoint &output) override { | void unlockCoin(const COutPoint &output) override { | ||||
LOCK2(cs_main, m_wallet.cs_wallet); | auto locked_chain = m_wallet.chain().lock(); | ||||
LOCK(m_wallet.cs_wallet); | |||||
return m_wallet.UnlockCoin(output); | return m_wallet.UnlockCoin(output); | ||||
} | } | ||||
bool isLockedCoin(const COutPoint &output) override { | bool isLockedCoin(const COutPoint &output) override { | ||||
LOCK2(cs_main, m_wallet.cs_wallet); | auto locked_chain = m_wallet.chain().lock(); | ||||
LOCK(m_wallet.cs_wallet); | |||||
return m_wallet.IsLockedCoin(output); | return m_wallet.IsLockedCoin(output); | ||||
} | } | ||||
void listLockedCoins(std::vector<COutPoint> &outputs) override { | void listLockedCoins(std::vector<COutPoint> &outputs) override { | ||||
LOCK2(cs_main, m_wallet.cs_wallet); | auto locked_chain = m_wallet.chain().lock(); | ||||
LOCK(m_wallet.cs_wallet); | |||||
return m_wallet.ListLockedCoins(outputs); | return m_wallet.ListLockedCoins(outputs); | ||||
} | } | ||||
std::unique_ptr<PendingWalletTx> | std::unique_ptr<PendingWalletTx> | ||||
createTransaction(const std::vector<CRecipient> &recipients, | createTransaction(const std::vector<CRecipient> &recipients, | ||||
const CCoinControl &coin_control, bool sign, | const CCoinControl &coin_control, bool sign, | ||||
int &change_pos, Amount &fee, | int &change_pos, Amount &fee, | ||||
std::string &fail_reason) override { | std::string &fail_reason) override { | ||||
LOCK2(cs_main, m_wallet.cs_wallet); | auto locked_chain = m_wallet.chain().lock(); | ||||
LOCK(m_wallet.cs_wallet); | |||||
auto pending = std::make_unique<PendingWalletTxImpl>(m_wallet); | auto pending = std::make_unique<PendingWalletTxImpl>(m_wallet); | ||||
if (!m_wallet.CreateTransaction(recipients, pending->m_tx, | if (!m_wallet.CreateTransaction(recipients, pending->m_tx, | ||||
pending->m_key, fee, change_pos, | pending->m_key, fee, change_pos, | ||||
fail_reason, coin_control, sign)) { | fail_reason, coin_control, sign)) { | ||||
return {}; | return {}; | ||||
} | } | ||||
return pending; | return pending; | ||||
} | } | ||||
bool transactionCanBeAbandoned(const TxId &txid) override { | bool transactionCanBeAbandoned(const TxId &txid) override { | ||||
return m_wallet.TransactionCanBeAbandoned(txid); | return m_wallet.TransactionCanBeAbandoned(txid); | ||||
} | } | ||||
bool abandonTransaction(const TxId &txid) override { | bool abandonTransaction(const TxId &txid) override { | ||||
LOCK2(cs_main, m_wallet.cs_wallet); | auto locked_chain = m_wallet.chain().lock(); | ||||
LOCK(m_wallet.cs_wallet); | |||||
return m_wallet.AbandonTransaction(txid); | return m_wallet.AbandonTransaction(txid); | ||||
} | } | ||||
CTransactionRef getTx(const TxId &txid) override { | CTransactionRef getTx(const TxId &txid) override { | ||||
LOCK2(::cs_main, m_wallet.cs_wallet); | auto locked_chain = m_wallet.chain().lock(); | ||||
LOCK(m_wallet.cs_wallet); | |||||
auto mi = m_wallet.mapWallet.find(txid); | auto mi = m_wallet.mapWallet.find(txid); | ||||
if (mi != m_wallet.mapWallet.end()) { | if (mi != m_wallet.mapWallet.end()) { | ||||
return mi->second.tx; | return mi->second.tx; | ||||
} | } | ||||
return {}; | return {}; | ||||
} | } | ||||
WalletTx getWalletTx(const TxId &txid) override { | WalletTx getWalletTx(const TxId &txid) override { | ||||
LOCK2(::cs_main, m_wallet.cs_wallet); | auto locked_chain = m_wallet.chain().lock(); | ||||
LOCK(m_wallet.cs_wallet); | |||||
auto mi = m_wallet.mapWallet.find(txid); | auto mi = m_wallet.mapWallet.find(txid); | ||||
if (mi != m_wallet.mapWallet.end()) { | if (mi != m_wallet.mapWallet.end()) { | ||||
return MakeWalletTx(m_wallet, mi->second); | return MakeWalletTx(m_wallet, mi->second); | ||||
} | } | ||||
return {}; | return {}; | ||||
} | } | ||||
std::vector<WalletTx> getWalletTxs() override { | std::vector<WalletTx> getWalletTxs() override { | ||||
LOCK2(::cs_main, m_wallet.cs_wallet); | auto locked_chain = m_wallet.chain().lock(); | ||||
LOCK(m_wallet.cs_wallet); | |||||
std::vector<WalletTx> result; | std::vector<WalletTx> result; | ||||
result.reserve(m_wallet.mapWallet.size()); | result.reserve(m_wallet.mapWallet.size()); | ||||
for (const auto &entry : m_wallet.mapWallet) { | for (const auto &entry : m_wallet.mapWallet) { | ||||
result.emplace_back(MakeWalletTx(m_wallet, entry.second)); | result.emplace_back(MakeWalletTx(m_wallet, entry.second)); | ||||
} | } | ||||
return result; | return result; | ||||
} | } | ||||
bool tryGetTxStatus(const TxId &txid, | bool tryGetTxStatus(const TxId &txid, | ||||
interfaces::WalletTxStatus &tx_status, | interfaces::WalletTxStatus &tx_status, | ||||
int &num_blocks, int64_t &block_time) override { | int &num_blocks, int64_t &block_time) override { | ||||
TRY_LOCK(::cs_main, locked_chain); | auto locked_chain = m_wallet.chain().lock(true /* try_lock */); | ||||
if (!locked_chain) { | if (!locked_chain) { | ||||
return false; | return false; | ||||
} | } | ||||
TRY_LOCK(m_wallet.cs_wallet, locked_wallet); | TRY_LOCK(m_wallet.cs_wallet, locked_wallet); | ||||
if (!locked_wallet) { | if (!locked_wallet) { | ||||
return false; | return false; | ||||
} | } | ||||
auto mi = m_wallet.mapWallet.find(txid); | auto mi = m_wallet.mapWallet.find(txid); | ||||
if (mi == m_wallet.mapWallet.end()) { | if (mi == m_wallet.mapWallet.end()) { | ||||
return false; | return false; | ||||
} | } | ||||
num_blocks = ::chainActive.Height(); | num_blocks = ::chainActive.Height(); | ||||
block_time = ::chainActive.Tip()->GetBlockTime(); | block_time = ::chainActive.Tip()->GetBlockTime(); | ||||
tx_status = MakeWalletTxStatus(mi->second); | tx_status = MakeWalletTxStatus(mi->second); | ||||
return true; | return true; | ||||
} | } | ||||
WalletTx getWalletTxDetails(const TxId &txid, WalletTxStatus &tx_status, | WalletTx getWalletTxDetails(const TxId &txid, WalletTxStatus &tx_status, | ||||
WalletOrderForm &order_form, | WalletOrderForm &order_form, | ||||
bool &in_mempool, | bool &in_mempool, | ||||
int &num_blocks) override { | int &num_blocks) override { | ||||
LOCK2(::cs_main, m_wallet.cs_wallet); | auto locked_chain = m_wallet.chain().lock(); | ||||
LOCK(m_wallet.cs_wallet); | |||||
auto mi = m_wallet.mapWallet.find(txid); | auto mi = m_wallet.mapWallet.find(txid); | ||||
if (mi != m_wallet.mapWallet.end()) { | if (mi != m_wallet.mapWallet.end()) { | ||||
num_blocks = ::chainActive.Height(); | num_blocks = ::chainActive.Height(); | ||||
in_mempool = mi->second.InMempool(); | in_mempool = mi->second.InMempool(); | ||||
order_form = mi->second.vOrderForm; | order_form = mi->second.vOrderForm; | ||||
tx_status = MakeWalletTxStatus(mi->second); | tx_status = MakeWalletTxStatus(mi->second); | ||||
return MakeWalletTx(m_wallet, mi->second); | return MakeWalletTx(m_wallet, mi->second); | ||||
} | } | ||||
Show All 12 Lines | public: | ||||
m_wallet.GetUnconfirmedWatchOnlyBalance(); | m_wallet.GetUnconfirmedWatchOnlyBalance(); | ||||
result.immature_watch_only_balance = | result.immature_watch_only_balance = | ||||
m_wallet.GetImmatureWatchOnlyBalance(); | m_wallet.GetImmatureWatchOnlyBalance(); | ||||
} | } | ||||
return result; | return result; | ||||
} | } | ||||
bool tryGetBalances(WalletBalances &balances, | bool tryGetBalances(WalletBalances &balances, | ||||
int &num_blocks) override { | int &num_blocks) override { | ||||
TRY_LOCK(cs_main, locked_chain); | auto locked_chain = m_wallet.chain().lock(true /* try_lock */); | ||||
if (!locked_chain) { | if (!locked_chain) { | ||||
return false; | return false; | ||||
} | } | ||||
TRY_LOCK(m_wallet.cs_wallet, locked_wallet); | TRY_LOCK(m_wallet.cs_wallet, locked_wallet); | ||||
if (!locked_wallet) { | if (!locked_wallet) { | ||||
return false; | return false; | ||||
} | } | ||||
balances = getBalances(); | balances = getBalances(); | ||||
num_blocks = ::chainActive.Height(); | num_blocks = ::chainActive.Height(); | ||||
return true; | return true; | ||||
} | } | ||||
Amount getBalance() override { return m_wallet.GetBalance(); } | Amount getBalance() override { return m_wallet.GetBalance(); } | ||||
Amount getAvailableBalance(const CCoinControl &coin_control) override { | Amount getAvailableBalance(const CCoinControl &coin_control) override { | ||||
return m_wallet.GetAvailableBalance(&coin_control); | return m_wallet.GetAvailableBalance(&coin_control); | ||||
} | } | ||||
isminetype txinIsMine(const CTxIn &txin) override { | isminetype txinIsMine(const CTxIn &txin) override { | ||||
LOCK2(::cs_main, m_wallet.cs_wallet); | auto locked_chain = m_wallet.chain().lock(); | ||||
LOCK(m_wallet.cs_wallet); | |||||
return m_wallet.IsMine(txin); | return m_wallet.IsMine(txin); | ||||
} | } | ||||
isminetype txoutIsMine(const CTxOut &txout) override { | isminetype txoutIsMine(const CTxOut &txout) override { | ||||
LOCK2(::cs_main, m_wallet.cs_wallet); | auto locked_chain = m_wallet.chain().lock(); | ||||
LOCK(m_wallet.cs_wallet); | |||||
return m_wallet.IsMine(txout); | return m_wallet.IsMine(txout); | ||||
} | } | ||||
Amount getDebit(const CTxIn &txin, isminefilter filter) override { | Amount getDebit(const CTxIn &txin, isminefilter filter) override { | ||||
LOCK2(::cs_main, m_wallet.cs_wallet); | auto locked_chain = m_wallet.chain().lock(); | ||||
LOCK(m_wallet.cs_wallet); | |||||
return m_wallet.GetDebit(txin, filter); | return m_wallet.GetDebit(txin, filter); | ||||
} | } | ||||
Amount getCredit(const CTxOut &txout, isminefilter filter) override { | Amount getCredit(const CTxOut &txout, isminefilter filter) override { | ||||
LOCK2(::cs_main, m_wallet.cs_wallet); | auto locked_chain = m_wallet.chain().lock(); | ||||
LOCK(m_wallet.cs_wallet); | |||||
return m_wallet.GetCredit(txout, filter); | return m_wallet.GetCredit(txout, filter); | ||||
} | } | ||||
CoinsList listCoins() override { | CoinsList listCoins() override { | ||||
LOCK2(::cs_main, m_wallet.cs_wallet); | auto locked_chain = m_wallet.chain().lock(); | ||||
LOCK(m_wallet.cs_wallet); | |||||
CoinsList result; | CoinsList result; | ||||
for (const auto &entry : m_wallet.ListCoins()) { | for (const auto &entry : m_wallet.ListCoins()) { | ||||
auto &group = result[entry.first]; | auto &group = result[entry.first]; | ||||
for (const auto &coin : entry.second) { | for (const auto &coin : entry.second) { | ||||
group.emplace_back(COutPoint(coin.tx->GetId(), coin.i), | group.emplace_back(COutPoint(coin.tx->GetId(), coin.i), | ||||
MakeWalletTxOut(m_wallet, *coin.tx, | MakeWalletTxOut(m_wallet, *coin.tx, | ||||
coin.i, coin.nDepth)); | coin.i, coin.nDepth)); | ||||
} | } | ||||
} | } | ||||
return result; | return result; | ||||
} | } | ||||
std::vector<WalletTxOut> | std::vector<WalletTxOut> | ||||
getCoins(const std::vector<COutPoint> &outputs) override { | getCoins(const std::vector<COutPoint> &outputs) override { | ||||
LOCK2(::cs_main, m_wallet.cs_wallet); | auto locked_chain = m_wallet.chain().lock(); | ||||
LOCK(m_wallet.cs_wallet); | |||||
std::vector<WalletTxOut> result; | std::vector<WalletTxOut> result; | ||||
result.reserve(outputs.size()); | result.reserve(outputs.size()); | ||||
for (const auto &output : outputs) { | for (const auto &output : outputs) { | ||||
result.emplace_back(); | result.emplace_back(); | ||||
auto it = m_wallet.mapWallet.find(output.GetTxId()); | auto it = m_wallet.mapWallet.find(output.GetTxId()); | ||||
if (it != m_wallet.mapWallet.end()) { | if (it != m_wallet.mapWallet.end()) { | ||||
int depth = it->second.GetDepthInMainChain(); | int depth = it->second.GetDepthInMainChain(); | ||||
if (depth >= 0) { | if (depth >= 0) { | ||||
▲ Show 20 Lines • Show All 90 Lines • Show Last 20 Lines |