Skip to content

Commit

Permalink
core: Implement RegtestWalletAppKit
Browse files Browse the repository at this point in the history
The RegtestWalletAppKit sets up BitcoinJ and loads the given wallets.
  • Loading branch information
alvasw committed Nov 10, 2024
1 parent ba28806 commit 33a968a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
5 changes: 5 additions & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id 'bisq.java-conventions'
id 'bisq.javafx'
id 'bisq.java-integration-tests'
}

javafx {
Expand Down Expand Up @@ -61,6 +62,10 @@ dependencies {
testAnnotationProcessor libs.lombok
testCompileOnly libs.lombok
testImplementation libs.natpryce.make.it.easy

integrationTestImplementation libs.junit.jupiter
integrationTestAnnotationProcessor libs.lombok
integrationTestCompileOnly libs.lombok
}

test {
Expand Down
41 changes: 41 additions & 0 deletions core/src/integrationTest/java/bisq/core/RegtestWalletAppKit.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package bisq.core;

import bisq.core.btc.wallet.WalletFactory;

import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.kits.WalletAppKit;
import org.bitcoinj.wallet.Wallet;

import java.nio.file.Path;

import java.util.List;

import lombok.Getter;

@Getter
public class RegtestWalletAppKit {
private final WalletAppKit walletAppKit;

public RegtestWalletAppKit(NetworkParameters networkParams, Path dataDirPath, List<Wallet> wallets) {
walletAppKit = new WalletAppKit(networkParams, dataDirPath.toFile(), "dataDirFilePrefix") {
@Override
protected void onSetupCompleted() {
super.onSetupCompleted();
wallets.forEach(wallet -> {
vChain.addWallet(wallet);
vPeerGroup.addWallet(wallet);
});
}
};
}

public void initialize() {
walletAppKit.connectToLocalHost();

var walletFactory = new WalletFactory(walletAppKit.params());
walletAppKit.setWalletFactory((params, keyChainGroup) -> walletFactory.createBsqWallet());

walletAppKit.startAsync();
walletAppKit.awaitRunning();
}
}

0 comments on commit 33a968a

Please sign in to comment.