mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-09 07:08:25 +02:00
refactor: interfaces, make 'createTransaction' less error-prone
Bundle all function's outputs inside the util::Result returned object. Reasons for the refactoring: - The 'change_pos' ref argument has been a source of bugs in the past. - The 'fee' ref argument is currently only set when the transaction creation process succeeds.
This commit is contained in:
@@ -257,21 +257,13 @@ public:
|
||||
LOCK(m_wallet->cs_wallet);
|
||||
return m_wallet->ListLockedCoins(outputs);
|
||||
}
|
||||
util::Result<CTransactionRef> createTransaction(const std::vector<CRecipient>& recipients,
|
||||
util::Result<wallet::CreatedTransactionResult> createTransaction(const std::vector<CRecipient>& recipients,
|
||||
const CCoinControl& coin_control,
|
||||
bool sign,
|
||||
int& change_pos,
|
||||
CAmount& fee) override
|
||||
std::optional<unsigned int> change_pos) override
|
||||
{
|
||||
LOCK(m_wallet->cs_wallet);
|
||||
auto res = CreateTransaction(*m_wallet, recipients, change_pos == -1 ? std::nullopt : std::make_optional(change_pos),
|
||||
coin_control, sign);
|
||||
if (!res) return util::Error{util::ErrorString(res)};
|
||||
const auto& txr = *res;
|
||||
fee = txr.fee;
|
||||
change_pos = txr.change_pos ? int(*txr.change_pos) : -1;
|
||||
|
||||
return txr.tx;
|
||||
return CreateTransaction(*m_wallet, recipients, change_pos, coin_control, sign);
|
||||
}
|
||||
void commitTransaction(CTransactionRef tx,
|
||||
WalletValueMap value_map,
|
||||
|
||||
Reference in New Issue
Block a user