Merge pull request #7287 from alvasw/core_Implement_WalletFactory

core: Implement WalletFactory
This commit is contained in:
Alejandro García 2024-11-12 06:31:18 +00:00 committed by GitHub
commit 9af707d4e4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

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());
}
}