-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use watched scripts to pick up broadcast of staged txs
Since the multisig escrow outputs of the deposit & warning txs do not belong to the user, bitcoinj won't pick up any txs spending them unless a corresponding watched script (the ScriptPubKey) is added to the wallet. To this end, provide a trade task to add watched scripts for those three outputs, which runs just before the client or the peer might broadcast the deposit tx. Also remove them upon withdrawal of funds at the end of the trade (closed normally or through a dispute). We need to add watched scripts for the deposit tx output and both the user's and the peer's warning tx outputs, so that the peer's warning, redirect and claim txs are all picked up, regardless of any message sent to the client. TODO: Possibly find a way to clear out old watched scripts from failed trades, as they will otherwise remain in the user's wallet permanently, creating a growing burden for the wallet. Also, we should possibly re- add all the watched scripts if the wallet is restored from seed.
- Loading branch information
Showing
7 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/AddWatchedScriptsToWallet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* This file is part of Bisq. | ||
* | ||
* Bisq is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or (at | ||
* your option) any later version. | ||
* | ||
* Bisq is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public | ||
* License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Bisq. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package bisq.core.trade.protocol.bisq_v5.tasks; | ||
|
||
import bisq.core.btc.wallet.BtcWalletService; | ||
import bisq.core.trade.model.bisq_v1.Trade; | ||
import bisq.core.trade.protocol.bisq_v1.tasks.TradeTask; | ||
|
||
import bisq.common.taskrunner.TaskRunner; | ||
|
||
import org.bitcoinj.core.Transaction; | ||
import org.bitcoinj.core.TransactionOutput; | ||
import org.bitcoinj.script.Script; | ||
|
||
import java.util.List; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
public class AddWatchedScriptsToWallet extends TradeTask { | ||
public AddWatchedScriptsToWallet(TaskRunner<Trade> taskHandler, Trade trade) { | ||
super(taskHandler, trade); | ||
} | ||
|
||
@Override | ||
protected void run() { | ||
try { | ||
runInterceptHook(); | ||
|
||
BtcWalletService btcWalletService = processModel.getBtcWalletService(); | ||
|
||
long creationTimeSeconds = System.currentTimeMillis() / 1000; | ||
List<Script> watchedScripts = trade.getWatchedScripts(btcWalletService); | ||
watchedScripts.forEach(script -> script.setCreationTimeSeconds(creationTimeSeconds)); | ||
|
||
// TODO: Possibly find a way to re-add watched scripts in the event that the wallet is restored from seed. | ||
btcWalletService.getWallet().addWatchedScripts(watchedScripts); | ||
|
||
complete(); | ||
} catch (Throwable t) { | ||
failed(t); | ||
} | ||
} | ||
} |