Skip to content

Commit

Permalink
RegtestWalletAppKit: Implement createNewBsqWallet method
Browse files Browse the repository at this point in the history
The createNewBsqWallet method creates a new BitcoinJ wallet and
registers it with BitcoinJ's BlockChain and PeerGroup.
  • Loading branch information
alvasw committed Dec 9, 2024
1 parent b78f3ab commit 53467f9
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions core/src/integrationTest/java/bisq/core/RegtestWalletAppKit.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -15,6 +17,7 @@
@Getter
public class RegtestWalletAppKit {
private final WalletAppKit walletAppKit;
private final WalletFactory walletFactory;

public RegtestWalletAppKit(NetworkParameters networkParams, Path dataDirPath, List<Wallet> wallets) {
walletAppKit = new WalletAppKit(networkParams, dataDirPath.toFile(), "dataDirFilePrefix") {
Expand All @@ -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;
}
}

0 comments on commit 53467f9

Please sign in to comment.