Merge pull request #7322 from alvasw/RegtestWalletAppKit_Implement_createNewBsqWallet_method

RegtestWalletAppKit: Implement createNewBsqWallet method
This commit is contained in:
Alejandro García 2024-12-10 07:56:28 +00:00 committed by GitHub
commit e4b618d718
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2,7 +2,9 @@ package bisq.core;
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 @@ import lombok.Getter;
@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") {
@ -27,15 +30,25 @@ public class RegtestWalletAppKit {
});
}
};
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;
}
}