Changeset View
Changeset View
Standalone View
Standalone View
src/interfaces/wallet.cpp
Show All 20 Lines | |||||
#include <wallet/load.h> | #include <wallet/load.h> | ||||
#include <wallet/rpcdump.h> | #include <wallet/rpcdump.h> | ||||
#include <wallet/rpcwallet.h> | #include <wallet/rpcwallet.h> | ||||
#include <wallet/wallet.h> | #include <wallet/wallet.h> | ||||
namespace interfaces { | namespace interfaces { | ||||
namespace { | namespace { | ||||
class PendingWalletTxImpl : public PendingWalletTx { | |||||
public: | |||||
explicit PendingWalletTxImpl(CWallet &wallet) : m_wallet(wallet) {} | |||||
const CTransaction &get() override { return *m_tx; } | |||||
bool commit(WalletValueMap value_map, WalletOrderForm order_form, | |||||
std::string &reject_reason) override { | |||||
auto locked_chain = m_wallet.chain().lock(); | |||||
LOCK(m_wallet.cs_wallet); | |||||
CValidationState state; | |||||
if (!m_wallet.CommitTransaction(m_tx, std::move(value_map), | |||||
std::move(order_form), state)) { | |||||
reject_reason = state.GetRejectReason(); | |||||
return false; | |||||
} | |||||
return true; | |||||
} | |||||
CTransactionRef m_tx; | |||||
CWallet &m_wallet; | |||||
}; | |||||
//! Construct wallet tx struct. | //! Construct wallet tx struct. | ||||
static WalletTx MakeWalletTx(interfaces::Chain::Lock &locked_chain, | static WalletTx MakeWalletTx(interfaces::Chain::Lock &locked_chain, | ||||
CWallet &wallet, const CWalletTx &wtx) { | CWallet &wallet, const CWalletTx &wtx) { | ||||
WalletTx result; | WalletTx result; | ||||
result.tx = wtx.tx; | result.tx = wtx.tx; | ||||
result.txin_is_mine.reserve(wtx.tx->vin.size()); | result.txin_is_mine.reserve(wtx.tx->vin.size()); | ||||
for (const auto &txin : wtx.tx->vin) { | for (const auto &txin : wtx.tx->vin) { | ||||
result.txin_is_mine.emplace_back(wallet.IsMine(txin)); | result.txin_is_mine.emplace_back(wallet.IsMine(txin)); | ||||
▲ Show 20 Lines • Show All 171 Lines • ▼ Show 20 Lines | public: | ||||
LOCK(m_wallet->cs_wallet); | 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 { | ||||
auto locked_chain = m_wallet->chain().lock(); | auto locked_chain = m_wallet->chain().lock(); | ||||
LOCK(m_wallet->cs_wallet); | LOCK(m_wallet->cs_wallet); | ||||
return m_wallet->ListLockedCoins(outputs); | return m_wallet->ListLockedCoins(outputs); | ||||
} | } | ||||
std::unique_ptr<PendingWalletTx> | CTransactionRef | ||||
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 { | ||||
auto locked_chain = m_wallet->chain().lock(); | auto locked_chain = m_wallet->chain().lock(); | ||||
LOCK(m_wallet->cs_wallet); | LOCK(m_wallet->cs_wallet); | ||||
auto pending = std::make_unique<PendingWalletTxImpl>(*m_wallet); | CTransactionRef tx; | ||||
if (!m_wallet->CreateTransaction(*locked_chain, recipients, | if (!m_wallet->CreateTransaction(*locked_chain, recipients, tx, fee, | ||||
pending->m_tx, fee, change_pos, | change_pos, fail_reason, | ||||
fail_reason, coin_control, sign)) { | coin_control, sign)) { | ||||
return {}; | return {}; | ||||
} | } | ||||
return pending; | return tx; | ||||
} | |||||
bool commitTransaction(CTransactionRef tx, WalletValueMap value_map, | |||||
WalletOrderForm order_form, | |||||
std::string &reject_reason) override { | |||||
auto locked_chain = m_wallet->chain().lock(); | |||||
LOCK(m_wallet->cs_wallet); | |||||
CValidationState state; | |||||
if (!m_wallet->CommitTransaction(std::move(tx), | |||||
std::move(value_map), | |||||
std::move(order_form), state)) { | |||||
reject_reason = state.GetRejectReason(); | |||||
return false; | |||||
} | |||||
return true; | |||||
} | } | ||||
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 { | ||||
auto locked_chain = m_wallet->chain().lock(); | auto locked_chain = m_wallet->chain().lock(); | ||||
LOCK(m_wallet->cs_wallet); | LOCK(m_wallet->cs_wallet); | ||||
return m_wallet->AbandonTransaction(*locked_chain, txid); | return m_wallet->AbandonTransaction(*locked_chain, txid); | ||||
▲ Show 20 Lines • Show All 266 Lines • Show Last 20 Lines |