From 53467f953af76feb52a9ca0c47ff843759e1e6ff Mon Sep 17 00:00:00 2001 From: Alva Swanson Date: Mon, 9 Dec 2024 10:29:33 +0000 Subject: [PATCH] RegtestWalletAppKit: Implement createNewBsqWallet method The createNewBsqWallet method creates a new BitcoinJ wallet and registers it with BitcoinJ's BlockChain and PeerGroup. --- .../java/bisq/core/RegtestWalletAppKit.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/core/src/integrationTest/java/bisq/core/RegtestWalletAppKit.java b/core/src/integrationTest/java/bisq/core/RegtestWalletAppKit.java index 2e0b8f618e..38914e495c 100644 --- a/core/src/integrationTest/java/bisq/core/RegtestWalletAppKit.java +++ b/core/src/integrationTest/java/bisq/core/RegtestWalletAppKit.java @@ -2,7 +2,9 @@ import bisq.core.btc.wallet.WalletFactory; +import org.bitcoinj.core.BlockChain; import org.bitcoinj.core.NetworkParameters; +import org.bitcoinj.core.PeerGroup; import org.bitcoinj.kits.WalletAppKit; import org.bitcoinj.wallet.Wallet; @@ -15,6 +17,7 @@ @Getter public class RegtestWalletAppKit { private final WalletAppKit walletAppKit; + private final WalletFactory walletFactory; public RegtestWalletAppKit(NetworkParameters networkParams, Path dataDirPath, List wallets) { walletAppKit = new WalletAppKit(networkParams, dataDirPath.toFile(), "dataDirFilePrefix") { @@ -27,15 +30,25 @@ protected void onSetupCompleted() { }); } }; + + walletFactory = new WalletFactory(networkParams); } public void initialize() { walletAppKit.connectToLocalHost(); - - var walletFactory = new WalletFactory(walletAppKit.params()); walletAppKit.setWalletFactory((params, keyChainGroup) -> walletFactory.createBsqWallet()); walletAppKit.startAsync(); walletAppKit.awaitRunning(); } + + public Wallet createNewBsqWallet() { + Wallet bsqWallet = walletFactory.createBsqWallet(); + BlockChain blockChain = walletAppKit.chain(); + blockChain.addWallet(bsqWallet); + + PeerGroup peerGroup = walletAppKit.peerGroup(); + peerGroup.addWallet(bsqWallet); + return bsqWallet; + } }