send: refactor CreateTransaction flow to return a BResult<CTransactionRef>

This commit is contained in:
furszy
2022-04-08 16:43:10 -03:00
parent 198fcca162
commit 22351725bc
9 changed files with 81 additions and 93 deletions

View File

@@ -204,10 +204,10 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact
{
CAmount nFeeRequired = 0;
int nChangePosRet = -1;
bilingual_str error;
auto& newTx = transaction.getWtx();
newTx = m_wallet->createTransaction(vecSend, coinControl, !wallet().privateKeysDisabled() /* sign */, nChangePosRet, nFeeRequired, error);
const auto& res = m_wallet->createTransaction(vecSend, coinControl, !wallet().privateKeysDisabled() /* sign */, nChangePosRet, nFeeRequired);
newTx = res ? res.GetObj() : nullptr;
transaction.setTransactionFee(nFeeRequired);
if (fSubtractFeeFromAmount && newTx)
transaction.reassignAmounts(nChangePosRet);
@@ -218,7 +218,7 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact
{
return SendCoinsReturn(AmountWithFeeExceedsBalance);
}
Q_EMIT message(tr("Send Coins"), QString::fromStdString(error.translated),
Q_EMIT message(tr("Send Coins"), QString::fromStdString(res.GetError().translated),
CClientUIInterface::MSG_ERROR);
return TransactionCreationFailed;
}