mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-25 15:29:38 +01:00
Refactor:
- Rename getFundsNeededForTradeAsLong to getFundsNeededForTrade - Use checkNotNull instead of if/else check - Cleanups
This commit is contained in:
parent
690104e6ea
commit
944a77d695
4 changed files with 26 additions and 28 deletions
|
@ -357,7 +357,7 @@ public class TradeManager implements PersistedDataHost {
|
|||
|
||||
private void initPendingTrade(Trade trade) {
|
||||
initTrade(trade, trade.getProcessModel().isUseSavingsWallet(),
|
||||
trade.getProcessModel().getFundsNeededForTradeAsLong());
|
||||
trade.getProcessModel().getFundsNeededForTrade());
|
||||
trade.updateDepositTxFromWallet();
|
||||
tradesForStatistics.add(trade);
|
||||
}
|
||||
|
@ -419,7 +419,7 @@ public class TradeManager implements PersistedDataHost {
|
|||
tradableListStorage,
|
||||
btcWalletService);
|
||||
|
||||
initTrade(trade, trade.getProcessModel().isUseSavingsWallet(), trade.getProcessModel().getFundsNeededForTradeAsLong());
|
||||
initTrade(trade, trade.getProcessModel().isUseSavingsWallet(), trade.getProcessModel().getFundsNeededForTrade());
|
||||
tradableList.add(trade);
|
||||
((MakerTrade) trade).handleTakeOfferRequest(inputsForDepositTxRequest, peer, errorMessage -> {
|
||||
if (takeOfferRequestErrorMessageHandler != null)
|
||||
|
|
|
@ -311,7 +311,7 @@ public class ProcessModel implements Model, PersistablePayload {
|
|||
return paymentAccount != null ? paymentAccount.getPaymentAccountPayload() : null;
|
||||
}
|
||||
|
||||
public Coin getFundsNeededForTradeAsLong() {
|
||||
public Coin getFundsNeededForTrade() {
|
||||
return Coin.valueOf(fundsNeededForTradeAsLong);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
package bisq.core.trade.protocol.tasks.seller_as_taker;
|
||||
|
||||
import bisq.core.btc.model.InputsAndChangeOutput;
|
||||
import bisq.core.offer.Offer;
|
||||
import bisq.core.trade.Trade;
|
||||
import bisq.core.trade.protocol.tasks.TradeTask;
|
||||
|
||||
|
@ -31,8 +32,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
|
||||
@Slf4j
|
||||
public class SellerAsTakerCreatesDepositTxInputs extends TradeTask {
|
||||
@SuppressWarnings({"unused"})
|
||||
public SellerAsTakerCreatesDepositTxInputs(TaskRunner taskHandler, Trade trade) {
|
||||
public SellerAsTakerCreatesDepositTxInputs(TaskRunner<Trade> taskHandler, Trade trade) {
|
||||
super(taskHandler, trade);
|
||||
}
|
||||
|
||||
|
@ -40,25 +40,24 @@ public class SellerAsTakerCreatesDepositTxInputs extends TradeTask {
|
|||
protected void run() {
|
||||
try {
|
||||
runInterceptHook();
|
||||
if (trade.getTradeAmount() != null) {
|
||||
Coin txFee = trade.getTxFee();
|
||||
Coin takerInputAmount = checkNotNull(trade.getOffer()).getSellerSecurityDeposit()
|
||||
.add(txFee)
|
||||
.add(txFee)
|
||||
.add(trade.getTradeAmount());
|
||||
InputsAndChangeOutput result = processModel.getTradeWalletService().takerCreatesDepositTxInputs(
|
||||
processModel.getTakeOfferFeeTx(),
|
||||
takerInputAmount,
|
||||
txFee);
|
||||
|
||||
processModel.setRawTransactionInputs(result.rawTransactionInputs);
|
||||
processModel.setChangeOutputValue(result.changeOutputValue);
|
||||
processModel.setChangeOutputAddress(result.changeOutputAddress);
|
||||
Coin tradeAmount = checkNotNull(trade.getTradeAmount());
|
||||
Offer offer = checkNotNull(trade.getOffer());
|
||||
Coin txFee = trade.getTxFee();
|
||||
Coin takerInputAmount = offer.getSellerSecurityDeposit()
|
||||
.add(txFee)
|
||||
.add(txFee) // We add 2 times the fee as one is for the payout tx
|
||||
.add(tradeAmount);
|
||||
InputsAndChangeOutput result = processModel.getTradeWalletService().takerCreatesDepositTxInputs(
|
||||
processModel.getTakeOfferFeeTx(),
|
||||
takerInputAmount,
|
||||
txFee);
|
||||
|
||||
complete();
|
||||
} else {
|
||||
failed("trade.getTradeAmount() = null");
|
||||
}
|
||||
processModel.setRawTransactionInputs(result.rawTransactionInputs);
|
||||
processModel.setChangeOutputValue(result.changeOutputValue);
|
||||
processModel.setChangeOutputAddress(result.changeOutputAddress);
|
||||
|
||||
complete();
|
||||
} catch (Throwable t) {
|
||||
failed(t);
|
||||
}
|
||||
|
|
|
@ -36,7 +36,6 @@ import lombok.extern.slf4j.Slf4j;
|
|||
@Slf4j
|
||||
public class CreateTakerFeeTx extends TradeTask {
|
||||
|
||||
@SuppressWarnings({"unused"})
|
||||
public CreateTakerFeeTx(TaskRunner taskHandler, Trade trade) {
|
||||
super(taskHandler, trade);
|
||||
}
|
||||
|
@ -51,16 +50,16 @@ public class CreateTakerFeeTx extends TradeTask {
|
|||
|
||||
// We enforce here to create a MULTI_SIG and TRADE_PAYOUT address entry to avoid that the change output would be used later
|
||||
// for those address entries. Because we do not commit our fee tx yet the change address would
|
||||
// appear as unused and therefor selected for the outputs for the MS tx.
|
||||
// appear as unused and therefore selected for the outputs for the MS tx.
|
||||
// That would cause incorrect display of the balance as
|
||||
// the change output would be considered as not available balance (part of the locked trade amount).
|
||||
walletService.getNewAddressEntry(id, AddressEntry.Context.MULTI_SIG);
|
||||
walletService.getNewAddressEntry(id, AddressEntry.Context.TRADE_PAYOUT);
|
||||
|
||||
AddressEntry addressEntry = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.OFFER_FUNDING);
|
||||
AddressEntry fundingAddressEntry = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.OFFER_FUNDING);
|
||||
AddressEntry reservedForTradeAddressEntry = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.RESERVED_FOR_TRADE);
|
||||
AddressEntry changeAddressEntry = walletService.getFreshAddressEntry();
|
||||
Address fundingAddress = addressEntry.getAddress();
|
||||
Address fundingAddress = fundingAddressEntry.getAddress();
|
||||
Address reservedForTradeAddress = reservedForTradeAddressEntry.getAddress();
|
||||
Address changeAddress = changeAddressEntry.getAddress();
|
||||
TradeWalletService tradeWalletService = processModel.getTradeWalletService();
|
||||
|
@ -73,7 +72,7 @@ public class CreateTakerFeeTx extends TradeTask {
|
|||
fundingAddress,
|
||||
reservedForTradeAddress,
|
||||
changeAddress,
|
||||
processModel.getFundsNeededForTradeAsLong(),
|
||||
processModel.getFundsNeededForTrade(),
|
||||
processModel.isUseSavingsWallet(),
|
||||
trade.getTakerFee(),
|
||||
trade.getTxFee(),
|
||||
|
@ -86,7 +85,7 @@ public class CreateTakerFeeTx extends TradeTask {
|
|||
fundingAddress,
|
||||
reservedForTradeAddress,
|
||||
changeAddress,
|
||||
processModel.getFundsNeededForTradeAsLong(),
|
||||
processModel.getFundsNeededForTrade(),
|
||||
processModel.isUseSavingsWallet(),
|
||||
trade.getTxFee());
|
||||
transaction = processModel.getBsqWalletService().signTx(txWithBsqFee);
|
||||
|
|
Loading…
Add table
Reference in a new issue