core: Implement WalletFactory

The WalletFactory can create BTC and BSQ wallets.
This commit is contained in:
Alva Swanson 2024-11-08 19:11:47 +00:00
parent 4a65e40d5c
commit 77c48d8dd8
No known key found for this signature in database
GPG Key ID: 004760E77F753090

View File

@ -0,0 +1,34 @@
package bisq.core.btc.wallet;
import bisq.core.btc.setup.BisqKeyChainGroupStructure;
import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.script.Script;
import org.bitcoinj.wallet.KeyChainGroup;
import org.bitcoinj.wallet.KeyChainGroupStructure;
import org.bitcoinj.wallet.Wallet;
public class WalletFactory {
private final NetworkParameters networkParams;
public WalletFactory(NetworkParameters networkParams) {
this.networkParams = networkParams;
}
public Wallet createBtcWallet() {
return createWallet(false);
}
public Wallet createBsqWallet() {
return createWallet(true);
}
private Wallet createWallet(boolean isBsqWallet) {
KeyChainGroupStructure structure = new BisqKeyChainGroupStructure(isBsqWallet);
KeyChainGroup.Builder kcgBuilder = KeyChainGroup.builder(networkParams, structure);
Script.ScriptType preferredOutputScriptType = Script.ScriptType.P2WPKH;
kcgBuilder.fromRandom(preferredOutputScriptType);
return new Wallet(networkParams, kcgBuilder.build());
}
}