Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BSQ swaps: Low risk refactorings [2] #5770

Merged
merged 202 commits into from Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
202 commits
Select commit Hold shift + click to select a range
577b07b
Move OfferPayload into package bisq.core.offer.bisq_v1
chimp1984 Oct 19, 2021
19f813e
Move CreateOfferService into package bisq.core.offer.bisq_v1
chimp1984 Oct 19, 2021
d98cb27
Move MarketPriceNotAvailableException into package bisq.core.offer.bi…
chimp1984 Oct 19, 2021
346fc79
Move MutableOfferPayloadFields into package bisq.core.offer.bisq_v1
chimp1984 Oct 19, 2021
8a4c05c
Move TriggerPriceService into package bisq.core.offer.bisq_v1
chimp1984 Oct 19, 2021
ade5d32
Move TakeOfferModel into package bisq.core.offer.bisq_v1
chimp1984 Oct 19, 2021
20d2980
Move AvailabilityResult into package bisq.core.offer.availability
chimp1984 Oct 19, 2021
0107519
Move bisq.core.offer.messages package into package bisq.core.offer.av…
chimp1984 Oct 19, 2021
ed9f248
Move content of bisq.core.offer.placeoffer package into package bisq.…
chimp1984 Oct 19, 2021
b584fdf
Rename OfferFilter to OfferFilterService
chimp1984 Oct 19, 2021
0e23cbe
Move Contract, SellerAsMakerTrade, SellerAsTakerTrade, SellerTrade,
chimp1984 Oct 19, 2021
c0cca78
Make updateDepositTxFromWallet public
chimp1984 Oct 19, 2021
0f7cfa9
Move Trade to bisq.core.trade.model.bisq_v1 package
chimp1984 Oct 19, 2021
5944218
Move MakerTrade and TakerTrade to bisq.core.trade.model package
chimp1984 Oct 19, 2021
5a0145d
Move Tradable to bisq.core.trade.model package
chimp1984 Oct 19, 2021
81ec06d
Move TradableList to bisq.core.trade.model package
chimp1984 Oct 19, 2021
2489bbc
Make FluentProtocol.Event public
chimp1984 Oct 19, 2021
c0d1308
Make setup in FluentProtocol public
chimp1984 Oct 19, 2021
87c12fd
Move protocol classes to bisq.core.trade.protocol.bisq_v1 package
chimp1984 Oct 19, 2021
babd70c
Move tasks package into bisq.core.trade.protocol.bisq_v1 package
chimp1984 Oct 19, 2021
5099d97
Move TradingPeer into bisq.core.trade.protocol.bisq_v1 package
chimp1984 Oct 19, 2021
a212cec
Move messages package into bisq.core.trade.protocol.bisq_v1 package
chimp1984 Oct 19, 2021
c9817ed
Move ClosedTradableManager, FailedTradesManager into bisq.core.trade.…
chimp1984 Oct 19, 2021
1b74b4e
Rename CleanupMailboxMessages to CleanupMailboxMessagesService
chimp1984 Oct 19, 2021
2141f8f
Move CleanupMailboxMessagesService, ClosedTradeUtil to package bisq.c…
chimp1984 Oct 19, 2021
f871e83
Move TransactionResultHandler, TradeResultHandler to package bisq.cor…
chimp1984 Oct 19, 2021
71c663e
Move TradeDataValidation, DumpDelayedPayoutTx, TradeDataValidation, T…
chimp1984 Oct 19, 2021
26e2676
Rename ProcessModelServiceProvider to Provider
chimp1984 Oct 19, 2021
c282b70
Rename txID to txId
chimp1984 Oct 19, 2021
30dd568
Move createoffer package inside bisq.desktop.main.offer.bisq_v1 package
chimp1984 Oct 19, 2021
0cd0e16
Move takeoffer package inside bisq.desktop.main.offer.bisq_v1 package
chimp1984 Oct 19, 2021
4169a87
Move MutableOffer view classes into bisq.desktop.main.offer.bisq_v1 p…
chimp1984 Oct 19, 2021
a2a7e87
Move OfferDataModel, OfferViewUtil into bisq.desktop.main.offer.bisq_…
chimp1984 Oct 19, 2021
a9f4bb7
Rename FeeUtil to OfferViewModelUtil
chimp1984 Oct 19, 2021
1e03aae
Move OfferViewModelUtil into bisq.desktop.main.offer.bisq_v1 package
chimp1984 Oct 19, 2021
72284d7
Cleanups, refromatting, add final qualifier
chimp1984 Oct 19, 2021
71eec7b
Move TradingPeer to package bisq.core.trade.protocol.bisq_v1.model
chimp1984 Oct 19, 2021
e1efc5e
Make setPaymentStartedAckMessage and setDepositTxSentAckMessage public
chimp1984 Oct 19, 2021
760732f
Move ProcessModel to package bisq.core.trade.protocol.bisq_v1.model
chimp1984 Oct 19, 2021
41d9d3f
Move OfferPayload into package bisq.core.offer.bisq_v1
chimp1984 Oct 19, 2021
edf5c3e
Move CreateOfferService into package bisq.core.offer.bisq_v1
chimp1984 Oct 19, 2021
4341a7e
Move MarketPriceNotAvailableException into package bisq.core.offer.bi…
chimp1984 Oct 19, 2021
042476a
Move MutableOfferPayloadFields into package bisq.core.offer.bisq_v1
chimp1984 Oct 19, 2021
d9fd8a4
Move TriggerPriceService into package bisq.core.offer.bisq_v1
chimp1984 Oct 19, 2021
e348000
Move TakeOfferModel into package bisq.core.offer.bisq_v1
chimp1984 Oct 19, 2021
a2d1e88
Move AvailabilityResult into package bisq.core.offer.availability
chimp1984 Oct 19, 2021
1badd69
Move bisq.core.offer.messages package into package bisq.core.offer.av…
chimp1984 Oct 19, 2021
7197b31
Move content of bisq.core.offer.placeoffer package into package bisq.…
chimp1984 Oct 19, 2021
1b4c487
Rename OfferFilter to OfferFilterService
chimp1984 Oct 19, 2021
1e9b606
Move Contract, SellerAsMakerTrade, SellerAsTakerTrade, SellerTrade,
chimp1984 Oct 19, 2021
8b21b85
Make updateDepositTxFromWallet public
chimp1984 Oct 19, 2021
d422427
Move Trade to bisq.core.trade.model.bisq_v1 package
chimp1984 Oct 19, 2021
fc3177c
Move MakerTrade and TakerTrade to bisq.core.trade.model package
chimp1984 Oct 19, 2021
58cfcff
Move Tradable to bisq.core.trade.model package
chimp1984 Oct 19, 2021
3474a2b
Move TradableList to bisq.core.trade.model package
chimp1984 Oct 19, 2021
d7b2e99
Make FluentProtocol.Event public
chimp1984 Oct 19, 2021
e3eea63
Make setup in FluentProtocol public
chimp1984 Oct 19, 2021
1b2e798
Move protocol classes to bisq.core.trade.protocol.bisq_v1 package
chimp1984 Oct 19, 2021
508296c
Move tasks package into bisq.core.trade.protocol.bisq_v1 package
chimp1984 Oct 19, 2021
97906e0
Move TradingPeer into bisq.core.trade.protocol.bisq_v1 package
chimp1984 Oct 19, 2021
cbf2822
Move messages package into bisq.core.trade.protocol.bisq_v1 package
chimp1984 Oct 19, 2021
fd6934c
Move ClosedTradableManager, FailedTradesManager into bisq.core.trade.…
chimp1984 Oct 19, 2021
fe2871b
Rename CleanupMailboxMessages to CleanupMailboxMessagesService
chimp1984 Oct 19, 2021
e80cdf8
Move CleanupMailboxMessagesService, ClosedTradeUtil to package bisq.c…
chimp1984 Oct 19, 2021
956ffc9
Move TransactionResultHandler, TradeResultHandler to package bisq.cor…
chimp1984 Oct 19, 2021
eacf446
Move TradeDataValidation, DumpDelayedPayoutTx, TradeDataValidation, T…
chimp1984 Oct 19, 2021
e1de502
Rename ProcessModelServiceProvider to Provider
chimp1984 Oct 19, 2021
2733af9
Rename txID to txId
chimp1984 Oct 19, 2021
932c0f8
Move createoffer package inside bisq.desktop.main.offer.bisq_v1 package
chimp1984 Oct 19, 2021
0efa0bd
Move takeoffer package inside bisq.desktop.main.offer.bisq_v1 package
chimp1984 Oct 19, 2021
601956d
Move MutableOffer view classes into bisq.desktop.main.offer.bisq_v1 p…
chimp1984 Oct 19, 2021
9777005
Move OfferDataModel, OfferViewUtil into bisq.desktop.main.offer.bisq_…
chimp1984 Oct 19, 2021
4a9db79
Rename FeeUtil to OfferViewModelUtil
chimp1984 Oct 19, 2021
25bbad1
Move OfferViewModelUtil into bisq.desktop.main.offer.bisq_v1 package
chimp1984 Oct 19, 2021
777287a
Cleanups, refromatting, add final qualifier
chimp1984 Oct 19, 2021
401880b
Move TradingPeer to package bisq.core.trade.protocol.bisq_v1.model
chimp1984 Oct 19, 2021
afed788
Make setPaymentStartedAckMessage and setDepositTxSentAckMessage public
chimp1984 Oct 19, 2021
734d429
Move ProcessModel to package bisq.core.trade.protocol.bisq_v1.model
chimp1984 Oct 19, 2021
dca0c93
Cleanups
chimp1984 Oct 20, 2021
e752965
Add linebreak in error popup
chimp1984 Oct 20, 2021
9f3034e
Fix layout/text issues
chimp1984 Oct 20, 2021
dc82fba
Increase visibility
chimp1984 Oct 20, 2021
8768345
Remove Inject annotation at abstract classes
chimp1984 Oct 20, 2021
d1d1706
Add delegate methods to offer
chimp1984 Oct 20, 2021
dfbc746
Move Offer.Direction one level up and rename to OfferDirection
chimp1984 Oct 20, 2021
6cf0a7c
Rename paymentMethod.isAsset to paymentMethod.isBlockchain
chimp1984 Oct 20, 2021
dad19ba
Add isFiat and isAltcoin methods.
chimp1984 Oct 20, 2021
88198be
Rename availableConfirmedBalance to availableBalance
chimp1984 Oct 20, 2021
d4bb026
Only check for localhost btc node if mainnet
chimp1984 Oct 20, 2021
f8751a8
Make TxConfidenceListener and its onTransactionConfidenceChanged meth…
chimp1984 Oct 20, 2021
a927bea
Add scriptTypeId to RawTransactionInput
chimp1984 Oct 20, 2021
75072eb
Add deprecated annotation, null checks and comment to getRawInputFrom…
chimp1984 Oct 20, 2021
561ebe9
Move test classes into bisq.desktop.main.offer.bisq_v1.createoffer
chimp1984 Oct 20, 2021
8ee2554
Merge branch 'bsq-swap-low-risk-refactorings' into wip-merge2
chimp1984 Oct 20, 2021
559bc58
Fix merge issues
chimp1984 Oct 20, 2021
34c4eef
Add allowSpendMyOwnUnconfirmedTxOutputs flag to BsqCoinSelector
chimp1984 Oct 20, 2021
4757288
Add isMine method. Add error logs
chimp1984 Oct 20, 2021
0f6364d
Inline TransactionWitness
chimp1984 Oct 20, 2021
e582ffd
Add new methods
chimp1984 Oct 20, 2021
54e81d1
Add signTx and verifyNonDustTxo methods
chimp1984 Oct 20, 2021
5f8bc83
Remove unused signTx method
chimp1984 Oct 20, 2021
d95356b
Add verifiedBalance field.
chimp1984 Oct 20, 2021
cfc404b
Rename signTx to signTxAndVerifyNoDustOutputs (no code change)
chimp1984 Oct 20, 2021
82c1be1
Change log level
chimp1984 Oct 20, 2021
c15fc0c
Add comment, cleanups
chimp1984 Oct 20, 2021
d7f1b00
Rename processModel.getTradingPeer to getTradePeer
chimp1984 Oct 20, 2021
02d7dfd
Only print stack trace if dev mode
chimp1984 Oct 20, 2021
9e4be13
Change log level
chimp1984 Oct 20, 2021
8d25798
Replace Value annotation with Getter and EqualsAndHashCode
chimp1984 Oct 20, 2021
d976f11
Add methods
chimp1984 Oct 20, 2021
a3b3d56
Simplify
chimp1984 Oct 20, 2021
9d10646
Move getRandomOfferId method to OfferUtil
chimp1984 Oct 20, 2021
e061d6a
Replace Value with Getter
chimp1984 Oct 20, 2021
5b0e9ab
Rename trade.getPhase to getTradePhase
chimp1984 Oct 20, 2021
544dd89
Rename trade.getState to getTradeState
chimp1984 Oct 20, 2021
12fff54
Cleanup
chimp1984 Oct 20, 2021
2440d72
Extract methods, Cleanups
chimp1984 Oct 20, 2021
4cb0746
Extract methods, cleanups. Rename methods and vars
chimp1984 Oct 20, 2021
7211f89
Add exclude fields to EqualsAndHashCode
chimp1984 Oct 20, 2021
07883e9
Rename trade.getPhase to getTradePhase
chimp1984 Oct 20, 2021
0148a36
Extract to method in TradeUtil
chimp1984 Oct 20, 2021
1051640
Use early return. cleanup
chimp1984 Oct 20, 2021
8219bf8
Extract method. Rename vars
chimp1984 Oct 20, 2021
ee374c3
Cleanups, apply rename of getTradePhase
chimp1984 Oct 20, 2021
e940f6f
Add method. Dont return null in case of no amount but min fee
chimp1984 Oct 21, 2021
19aabba
Add method. cleanups
chimp1984 Oct 21, 2021
1c0b52c
Move OfferDirection from bisq.core.offer.bisq_v1 to bisq.core.offer
chimp1984 Oct 21, 2021
0735419
Remove handling of BundleOfEnvelopes in send method.
chimp1984 Oct 21, 2021
b80b6ec
Cleanups
chimp1984 Oct 21, 2021
23af455
Add filterPredicate
chimp1984 Oct 21, 2021
2e384ed
Make onDeleteAccount more clear
chimp1984 Oct 21, 2021
9d8c705
Only add delay if not devmode
chimp1984 Oct 21, 2021
d285157
Reduce visibility
chimp1984 Oct 21, 2021
8bb42e1
Add methods, move field up
chimp1984 Oct 21, 2021
1aa5e70
Add method
chimp1984 Oct 21, 2021
8ac40a3
Add style
chimp1984 Oct 21, 2021
c60df6e
Add linebreak (no code change)
chimp1984 Oct 21, 2021
9fb6a6c
Add isNotPublished method (will be combined later with bsq swap checks)
chimp1984 Oct 21, 2021
cfae096
Add null checks, extract variables, cleanups
chimp1984 Oct 21, 2021
2ae1860
Move tests to package bisq.desktop.main.offer.bisq_v1.createoffer
chimp1984 Oct 21, 2021
080dc3e
Merge branch 'chimp-bsq-swap' into wip-merge021.10
chimp1984 Oct 21, 2021
ab6e4e1
Dummy commit to enforce rebuild at CI
chimp1984 Oct 21, 2021
5412f8b
Merge branch 'chimp-bsq-swap' into bsq-swap-low-risk-refactorings
chimp1984 Oct 21, 2021
c920da3
Add abstract classes and interfaces. Let ProcessModel and TradingPeer…
chimp1984 Oct 21, 2021
8cd85a7
Let Trade extend TradeModel
chimp1984 Oct 21, 2021
dcd0101
Generify TradeResultHandler
chimp1984 Oct 21, 2021
5d687bd
Use TradeModel and ProtocolModel in TradeTaskRunner, TradeTask, Trade…
chimp1984 Oct 21, 2021
308bb68
Use TradeModel
chimp1984 Oct 21, 2021
453229e
Impl. onAckMessage. Add fields for concrete types
chimp1984 Oct 21, 2021
c0e70b8
Use TradeModel in trade domain
chimp1984 Oct 21, 2021
d063aff
Let OfferPayload extend OfferPayloadBase
chimp1984 Oct 21, 2021
b194960
Use TradeModel instead of Trade where appropriate.
chimp1984 Oct 21, 2021
14765d6
Move protobuf OfferPayload.Direction to OfferDirection
chimp1984 Oct 21, 2021
611b944
Move protobuf OfferPayload.Direction to OfferDirection
chimp1984 Oct 21, 2021
2f40edd
Use bitcoinj 42bbae9 (with fix required for bsq swaps)
chimp1984 Oct 21, 2021
63c385b
Add support for RemoveDataMessage in testCapability
chimp1984 Oct 21, 2021
54f17b0
Cleanups
chimp1984 Oct 21, 2021
ebfd1b5
Remove todo
chimp1984 Oct 21, 2021
0942d8f
Move OfferPayload into package bisq.core.offer.bisq_v1
chimp1984 Oct 19, 2021
3838b45
Move CreateOfferService into package bisq.core.offer.bisq_v1
chimp1984 Oct 19, 2021
76441ff
Move MarketPriceNotAvailableException into package bisq.core.offer.bi…
chimp1984 Oct 19, 2021
b93295a
Move MutableOfferPayloadFields into package bisq.core.offer.bisq_v1
chimp1984 Oct 19, 2021
990c62b
Move TriggerPriceService into package bisq.core.offer.bisq_v1
chimp1984 Oct 19, 2021
0e8ff7d
Move TakeOfferModel into package bisq.core.offer.bisq_v1
chimp1984 Oct 19, 2021
ab91be8
Move AvailabilityResult into package bisq.core.offer.availability
chimp1984 Oct 19, 2021
fa9896d
Move bisq.core.offer.messages package into package bisq.core.offer.av…
chimp1984 Oct 19, 2021
aa02ac8
Move content of bisq.core.offer.placeoffer package into package bisq.…
chimp1984 Oct 19, 2021
4b968ce
Rename OfferFilter to OfferFilterService
chimp1984 Oct 19, 2021
09aa24c
Move Contract, SellerAsMakerTrade, SellerAsTakerTrade, SellerTrade,
chimp1984 Oct 19, 2021
b580a61
Make updateDepositTxFromWallet public
chimp1984 Oct 19, 2021
4dc7121
Move Trade to bisq.core.trade.model.bisq_v1 package
chimp1984 Oct 19, 2021
2b57309
Move MakerTrade and TakerTrade to bisq.core.trade.model package
chimp1984 Oct 19, 2021
eef55b7
Move Tradable to bisq.core.trade.model package
chimp1984 Oct 19, 2021
5b59d50
Move TradableList to bisq.core.trade.model package
chimp1984 Oct 19, 2021
838f7e2
Make FluentProtocol.Event public
chimp1984 Oct 19, 2021
e2f8236
Make setup in FluentProtocol public
chimp1984 Oct 19, 2021
21e9bb4
Move protocol classes to bisq.core.trade.protocol.bisq_v1 package
chimp1984 Oct 19, 2021
8305434
Move tasks package into bisq.core.trade.protocol.bisq_v1 package
chimp1984 Oct 19, 2021
97903e6
Move TradingPeer into bisq.core.trade.protocol.bisq_v1 package
chimp1984 Oct 19, 2021
69ca8de
Move messages package into bisq.core.trade.protocol.bisq_v1 package
chimp1984 Oct 19, 2021
c090116
Move ClosedTradableManager, FailedTradesManager into bisq.core.trade.…
chimp1984 Oct 19, 2021
bd7af46
Rename CleanupMailboxMessages to CleanupMailboxMessagesService
chimp1984 Oct 19, 2021
0bc5ede
Move CleanupMailboxMessagesService, ClosedTradeUtil to package bisq.c…
chimp1984 Oct 19, 2021
3b7a14c
Move TransactionResultHandler, TradeResultHandler to package bisq.cor…
chimp1984 Oct 19, 2021
ac8dd03
Move TradeDataValidation, DumpDelayedPayoutTx, TradeDataValidation, T…
chimp1984 Oct 19, 2021
449472e
Rename ProcessModelServiceProvider to Provider
chimp1984 Oct 19, 2021
3dd4a75
Rename txID to txId
chimp1984 Oct 19, 2021
f25d0d1
Move createoffer package inside bisq.desktop.main.offer.bisq_v1 package
chimp1984 Oct 19, 2021
9a1306a
Move takeoffer package inside bisq.desktop.main.offer.bisq_v1 package
chimp1984 Oct 19, 2021
cc4b001
Move MutableOffer view classes into bisq.desktop.main.offer.bisq_v1 p…
chimp1984 Oct 19, 2021
4ebbaa3
Move OfferDataModel, OfferViewUtil into bisq.desktop.main.offer.bisq_…
chimp1984 Oct 19, 2021
fbfdaf4
Rename FeeUtil to OfferViewModelUtil
chimp1984 Oct 19, 2021
3b5b20d
Move OfferViewModelUtil into bisq.desktop.main.offer.bisq_v1 package
chimp1984 Oct 19, 2021
6a8f612
Cleanups, refromatting, add final qualifier
chimp1984 Oct 19, 2021
3bb303b
Move TradingPeer to package bisq.core.trade.protocol.bisq_v1.model
chimp1984 Oct 19, 2021
993c602
Make setPaymentStartedAckMessage and setDepositTxSentAckMessage public
chimp1984 Oct 19, 2021
ed13d72
Move ProcessModel to package bisq.core.trade.protocol.bisq_v1.model
chimp1984 Oct 19, 2021
7d48cdb
Cleanups
chimp1984 Oct 20, 2021
56759be
Move tests to package bisq.desktop.main.offer.bisq_v1.createoffer
chimp1984 Oct 21, 2021
d5dfdb4
Merge branch 'chimp-bsq-swap-1' into bsq-swap-low-risk-refactorings-2
chimp1984 Nov 2, 2021
fd28c63
Fix merge issues (nothing critical)
chimp1984 Nov 2, 2021
ab7d6ed
Add missing class (merge mistake)
chimp1984 Nov 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 12 additions & 4 deletions core/src/main/java/bisq/core/btc/wallet/BsqCoinSelector.java
Expand Up @@ -26,6 +26,8 @@

import javax.inject.Inject;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

/**
Expand All @@ -36,9 +38,13 @@
public class BsqCoinSelector extends BisqDefaultCoinSelector {
private final DaoStateService daoStateService;
private final UnconfirmedBsqChangeOutputListService unconfirmedBsqChangeOutputListService;
@Setter
@Getter
private boolean allowSpendMyOwnUnconfirmedTxOutputs = true;

@Inject
public BsqCoinSelector(DaoStateService daoStateService, UnconfirmedBsqChangeOutputListService unconfirmedBsqChangeOutputListService) {
public BsqCoinSelector(DaoStateService daoStateService,
UnconfirmedBsqChangeOutputListService unconfirmedBsqChangeOutputListService) {
// permitForeignPendingTx is not relevant here as we do not support pending foreign utxos anyway.
super(false);
this.daoStateService = daoStateService;
Expand All @@ -53,17 +59,19 @@ protected boolean isTxOutputSpendable(TransactionOutput output) {
return false;

// If it is a normal confirmed BSQ output we use the default lookup at the daoState
if (daoStateService.isTxOutputSpendable(new TxOutputKey(parentTransaction.getTxId().toString(), output.getIndex())))
TxOutputKey txOutputKey = new TxOutputKey(parentTransaction.getTxId().toString(), output.getIndex());
if (daoStateService.isTxOutputSpendable(txOutputKey))
return true;

// It might be that it is an unconfirmed change output which we allow to be used for spending without requiring a confirmation.
// We check if we have the output in the dao state, if so we have a confirmed but unspendable output (e.g. confiscated).
if (daoStateService.getTxOutput(new TxOutputKey(parentTransaction.getTxId().toString(), output.getIndex())).isPresent())
if (daoStateService.getTxOutput(txOutputKey).isPresent())
return false;

// If we have set the isUnconfirmedSpendable flag to true (default) we check for unconfirmed own change outputs.
// Only if it's not existing yet in the dao state (unconfirmed) we use our unconfirmedBsqChangeOutputList to
// check if it is an own change output.
return unconfirmedBsqChangeOutputListService.hasTransactionOutput(output);
return allowSpendMyOwnUnconfirmedTxOutputs && unconfirmedBsqChangeOutputListService.hasTransactionOutput(output);
}

// For BSQ we do not check for dust attack utxos as they are 5.46 BSQ and a considerable value.
Expand Down
44 changes: 44 additions & 0 deletions core/src/main/java/bisq/core/btc/wallet/BtcWalletService.java
Expand Up @@ -23,6 +23,7 @@
import bisq.core.btc.exceptions.WalletException;
import bisq.core.btc.model.AddressEntry;
import bisq.core.btc.model.AddressEntryList;
import bisq.core.btc.model.RawTransactionInput;
import bisq.core.btc.setup.WalletsSetup;
import bisq.core.btc.wallet.http.MemPoolSpaceTxBroadcaster;
import bisq.core.provider.fee.FeeService;
Expand All @@ -47,6 +48,7 @@
import org.bitcoinj.script.Script;
import org.bitcoinj.script.ScriptBuilder;
import org.bitcoinj.script.ScriptPattern;
import org.bitcoinj.wallet.CoinSelection;
import org.bitcoinj.wallet.SendRequest;
import org.bitcoinj.wallet.Wallet;

Expand All @@ -61,6 +63,7 @@

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -152,6 +155,21 @@ String getWalletAsString(boolean includePrivKeys) {
// Public Methods
///////////////////////////////////////////////////////////////////////////////////////////

public Transaction signTx(Transaction tx) throws WalletException, TransactionVerificationException {
for (int i = 0; i < tx.getInputs().size(); i++) {
TransactionInput input = tx.getInput(i);
if (input.getConnectedOutput() != null && input.getConnectedOutput().isMine(wallet)) {
signTransactionInput(wallet, aesKey, tx, input, i);
checkScriptSig(tx, input, i);
}
}

checkWalletConsistency(wallet);
verifyTransaction(tx);
printTx("BTC wallet: Signed Tx", tx);
return tx;
}

///////////////////////////////////////////////////////////////////////////////////////////
// Burn BSQ txs (some proposal txs, asset listing fee tx, proof of burn tx)
///////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1330,4 +1348,30 @@ public Transaction createRefundPayoutTx(Coin buyerAmount,

return resultTx;
}


///////////////////////////////////////////////////////////////////////////////////////////
// Find inputs and change
///////////////////////////////////////////////////////////////////////////////////////////

public Tuple2<List<RawTransactionInput>, Coin> getInputsAndChange(Coin required) throws InsufficientMoneyException {
BtcCoinSelector coinSelector = new BtcCoinSelector(walletsSetup.getAddressesByContext(AddressEntry.Context.AVAILABLE),
preferences.getIgnoreDustThreshold());
CoinSelection coinSelection = coinSelector.select(required, Objects.requireNonNull(wallet).calculateAllSpendCandidates());

Coin change;
try {
change = coinSelector.getChange(required, coinSelection);
} catch (InsufficientMoneyException e) {
log.error("Missing funds in getSellersBtcInputsForBsqSwapTx. missing={}", e.missing);
throw new InsufficientMoneyException(e.missing);
}

Transaction dummyTx = new Transaction(params);
coinSelection.gathered.forEach(dummyTx::addInput);
List<RawTransactionInput> inputs = dummyTx.getInputs().stream()
.map(RawTransactionInput::new)
.collect(Collectors.toList());
return new Tuple2<>(inputs, change);
}
}
20 changes: 9 additions & 11 deletions core/src/main/java/bisq/core/btc/wallet/TradeWalletService.java
Expand Up @@ -889,8 +889,7 @@ public Transaction sellerSignsAndFinalizesPayoutTx(Transaction depositTx,
input.setScriptSig(inputScript);
} else {
input.setScriptSig(ScriptBuilder.createEmpty());
TransactionWitness witness = TransactionWitness.redeemP2WSH(redeemScript, sellerTxSig, buyerTxSig);
input.setWitness(witness);
input.setWitness(TransactionWitness.redeemP2WSH(redeemScript, sellerTxSig, buyerTxSig));
}
WalletService.printTx("payoutTx", payoutTx);
WalletService.verifyTransaction(payoutTx);
Expand Down Expand Up @@ -969,8 +968,7 @@ public Transaction finalizeMediatedPayoutTx(Transaction depositTx,
input.setScriptSig(inputScript);
} else {
input.setScriptSig(ScriptBuilder.createEmpty());
TransactionWitness witness = TransactionWitness.redeemP2WSH(redeemScript, sellerTxSig, buyerTxSig);
input.setWitness(witness);
input.setWitness(TransactionWitness.redeemP2WSH(redeemScript, sellerTxSig, buyerTxSig));
}
WalletService.printTx("mediated payoutTx", payoutTx);
WalletService.verifyTransaction(payoutTx);
Expand Down Expand Up @@ -1057,8 +1055,7 @@ public Transaction traderSignAndFinalizeDisputedPayoutTx(byte[] depositTxSeriali
input.setScriptSig(inputScript);
} else {
input.setScriptSig(ScriptBuilder.createEmpty());
TransactionWitness witness = TransactionWitness.redeemP2WSH(redeemScript, arbitratorTxSig, tradersTxSig);
input.setWitness(witness);
input.setWitness(TransactionWitness.redeemP2WSH(redeemScript, arbitratorTxSig, tradersTxSig));
}
WalletService.printTx("disputed payoutTx", payoutTx);
WalletService.verifyTransaction(payoutTx);
Expand Down Expand Up @@ -1147,8 +1144,7 @@ public Tuple2<String, String> emergencyApplySignatureToPayoutTxFrom2of2MultiSig(
input.setScriptSig(inputScript);
} else {
input.setScriptSig(ScriptBuilder.createEmpty());
TransactionWitness witness = TransactionWitness.redeemP2WSH(redeemScript, sellerTxSig, buyerTxSig);
input.setWitness(witness);
input.setWitness(TransactionWitness.redeemP2WSH(redeemScript, sellerTxSig, buyerTxSig));
}
String txId = payoutTx.getTxId().toString();
String signedTxHex = Utils.HEX.encode(payoutTx.bitcoinSerialize(!hashedMultiSigOutputIsLegacy));
Expand Down Expand Up @@ -1228,10 +1224,13 @@ private RawTransactionInput getRawInputFromTransactionInput(TransactionInput inp
input.getValue().value);
}

private TransactionInput getTransactionInput(Transaction depositTx,
private TransactionInput getTransactionInput(Transaction parentTransaction,
byte[] scriptProgram,
RawTransactionInput rawTransactionInput) {
return new TransactionInput(params, depositTx, scriptProgram, getConnectedOutPoint(rawTransactionInput),
return new TransactionInput(params,
parentTransaction,
scriptProgram,
getConnectedOutPoint(rawTransactionInput),
Coin.valueOf(rawTransactionInput.value));
}

Expand All @@ -1245,7 +1244,6 @@ public boolean isP2WH(RawTransactionInput rawTransactionInput) {
checkNotNull(getConnectedOutPoint(rawTransactionInput).getConnectedOutput()).getScriptPubKey());
}


// TODO: Once we have removed legacy arbitrator from dispute domain we can remove that method as well.
// Atm it is still used by traderSignAndFinalizeDisputedPayoutTx which is used by ArbitrationManager.

Expand Down
7 changes: 6 additions & 1 deletion core/src/main/java/bisq/core/btc/wallet/WalletService.java
Expand Up @@ -357,12 +357,13 @@ public static void signTransactionInput(Wallet wallet,
txIn.setScriptSig(ScriptBuilder.createEmpty());
txIn.setWitness(TransactionWitness.redeemP2WPKH(txSig, key));
} catch (ECKey.KeyIsEncryptedException e1) {
log.error(e1.toString());
throw e1;
} catch (ECKey.MissingPrivateKeyException e1) {
log.warn("No private key in keypair for input {}", index);
}
} else {
// log.error("Unexpected script type.");
log.error("Unexpected script type.");
throw new RuntimeException("Unexpected script type.");
}
} else {
Expand Down Expand Up @@ -546,6 +547,10 @@ public boolean isAddressUnused(Address address) {
return getNumTxOutputsForAddress(address) == 0;
}

public boolean isMine(TransactionOutput transactionOutput) {
return transactionOutput.isMine(wallet);
}

// BISQ issue #4039: Prevent dust outputs from being created.
// Check the outputs of a proposed transaction. If any are below the dust threshold,
// add up the dust, log the details, and return the cumulative dust amount.
Expand Down