examples/tools: use explicit script type and wallet structure

* Explicitly use P2WPKH (this changes behavior to segwit)
* Explicitly use BIP32 (this is the same behavior as before)
This commit is contained in:
Sean Gilligan 2022-04-30 13:10:07 -07:00 committed by Andreas Schildbach
parent bd775eafad
commit c3896e6caf
5 changed files with 14 additions and 5 deletions

View File

@ -20,8 +20,10 @@ import org.bitcoinj.core.listeners.PreMessageReceivedEventListener;
import org.bitcoinj.core.*; import org.bitcoinj.core.*;
import org.bitcoinj.kits.WalletAppKit; import org.bitcoinj.kits.WalletAppKit;
import org.bitcoinj.params.RegTestParams; import org.bitcoinj.params.RegTestParams;
import org.bitcoinj.script.Script;
import org.bitcoinj.utils.BriefLogFormatter; import org.bitcoinj.utils.BriefLogFormatter;
import org.bitcoinj.utils.Threading; import org.bitcoinj.utils.Threading;
import org.bitcoinj.wallet.KeyChainGroupStructure;
import org.bitcoinj.wallet.Wallet; import org.bitcoinj.wallet.Wallet;
import java.io.File; import java.io.File;
@ -37,7 +39,7 @@ public class DoubleSpend {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
BriefLogFormatter.init(); BriefLogFormatter.init();
final RegTestParams params = RegTestParams.get(); final RegTestParams params = RegTestParams.get();
WalletAppKit kit = new WalletAppKit(params, new File("."), "doublespend"); WalletAppKit kit = new WalletAppKit(params, Script.ScriptType.P2WPKH, KeyChainGroupStructure.BIP32, new File("."), "doublespend");
kit.connectToLocalHost(); kit.connectToLocalHost();
kit.setAutoSave(false); kit.setAutoSave(false);
kit.startAsync(); kit.startAsync();

View File

@ -29,7 +29,9 @@ import org.bitcoinj.kits.WalletAppKit;
import org.bitcoinj.params.MainNetParams; import org.bitcoinj.params.MainNetParams;
import org.bitcoinj.params.RegTestParams; import org.bitcoinj.params.RegTestParams;
import org.bitcoinj.params.TestNet3Params; import org.bitcoinj.params.TestNet3Params;
import org.bitcoinj.script.Script;
import org.bitcoinj.utils.BriefLogFormatter; import org.bitcoinj.utils.BriefLogFormatter;
import org.bitcoinj.wallet.KeyChainGroupStructure;
import org.bitcoinj.wallet.SendRequest; import org.bitcoinj.wallet.SendRequest;
import org.bitcoinj.wallet.Wallet; import org.bitcoinj.wallet.Wallet;
import org.bitcoinj.wallet.listeners.WalletCoinsReceivedEventListener; import org.bitcoinj.wallet.listeners.WalletCoinsReceivedEventListener;
@ -78,7 +80,7 @@ public class ForwardingService {
System.out.println("Forwarding address: " + forwardingAddress); System.out.println("Forwarding address: " + forwardingAddress);
// Start up a basic app using a class that automates some boilerplate. // Start up a basic app using a class that automates some boilerplate.
kit = new WalletAppKit(params, new File("."), filePrefix); kit = new WalletAppKit(params, Script.ScriptType.P2WPKH, KeyChainGroupStructure.BIP32, new File("."), filePrefix);
if (params == RegTestParams.get()) { if (params == RegTestParams.get()) {
// Regression test mode is designed for testing and development only, so there's no public network for it. // Regression test mode is designed for testing and development only, so there's no public network for it.

View File

@ -20,6 +20,7 @@ import org.bitcoinj.core.*;
import org.bitcoinj.kits.WalletAppKit; import org.bitcoinj.kits.WalletAppKit;
import org.bitcoinj.params.TestNet3Params; import org.bitcoinj.params.TestNet3Params;
import org.bitcoinj.script.Script; import org.bitcoinj.script.Script;
import org.bitcoinj.wallet.KeyChainGroupStructure;
import org.bitcoinj.wallet.Wallet; import org.bitcoinj.wallet.Wallet;
import org.bitcoinj.wallet.listeners.KeyChainEventListener; import org.bitcoinj.wallet.listeners.KeyChainEventListener;
import org.bitcoinj.wallet.listeners.ScriptsChangeEventListener; import org.bitcoinj.wallet.listeners.ScriptsChangeEventListener;
@ -55,7 +56,7 @@ public class Kit {
// Now we initialize a new WalletAppKit. The kit handles all the boilerplate for us and is the easiest way to get everything up and running. // Now we initialize a new WalletAppKit. The kit handles all the boilerplate for us and is the easiest way to get everything up and running.
// Have a look at the WalletAppKit documentation and its source to understand what's happening behind the scenes: https://github.com/bitcoinj/bitcoinj/blob/master/core/src/main/java/org/bitcoinj/kits/WalletAppKit.java // Have a look at the WalletAppKit documentation and its source to understand what's happening behind the scenes: https://github.com/bitcoinj/bitcoinj/blob/master/core/src/main/java/org/bitcoinj/kits/WalletAppKit.java
WalletAppKit kit = new WalletAppKit(params, new File("."), "walletappkit-example"); WalletAppKit kit = new WalletAppKit(params, Script.ScriptType.P2WPKH, KeyChainGroupStructure.BIP32, new File("."), "walletappkit-example");
// In case you want to connect with your local bitcoind tell the kit to connect to localhost. // In case you want to connect with your local bitcoind tell the kit to connect to localhost.
// You must do that in reg test mode. // You must do that in reg test mode.

View File

@ -19,6 +19,8 @@ package org.bitcoinj.examples;
import org.bitcoinj.core.*; import org.bitcoinj.core.*;
import org.bitcoinj.kits.WalletAppKit; import org.bitcoinj.kits.WalletAppKit;
import org.bitcoinj.params.TestNet3Params; import org.bitcoinj.params.TestNet3Params;
import org.bitcoinj.script.Script;
import org.bitcoinj.wallet.KeyChainGroupStructure;
import org.bitcoinj.wallet.Wallet; import org.bitcoinj.wallet.Wallet;
import org.bitcoinj.wallet.Wallet.BalanceType; import org.bitcoinj.wallet.Wallet.BalanceType;
@ -34,7 +36,7 @@ public class SendRequest {
// We use the WalletAppKit that handles all the boilerplate for us. Have a look at the Kit.java example for more details. // We use the WalletAppKit that handles all the boilerplate for us. Have a look at the Kit.java example for more details.
NetworkParameters params = TestNet3Params.get(); NetworkParameters params = TestNet3Params.get();
WalletAppKit kit = new WalletAppKit(params, new File("."), "sendrequest-example"); WalletAppKit kit = new WalletAppKit(params, Script.ScriptType.P2WPKH, KeyChainGroupStructure.BIP32, new File("."), "sendrequest-example");
kit.startAsync(); kit.startAsync();
kit.awaitRunning(); kit.awaitRunning();

View File

@ -21,7 +21,9 @@ import org.bitcoinj.core.listeners.PeerConnectedEventListener;
import org.bitcoinj.core.listeners.PeerDisconnectedEventListener; import org.bitcoinj.core.listeners.PeerDisconnectedEventListener;
import org.bitcoinj.kits.WalletAppKit; import org.bitcoinj.kits.WalletAppKit;
import org.bitcoinj.params.MainNetParams; import org.bitcoinj.params.MainNetParams;
import org.bitcoinj.script.Script;
import org.bitcoinj.utils.BriefLogFormatter; import org.bitcoinj.utils.BriefLogFormatter;
import org.bitcoinj.wallet.KeyChainGroupStructure;
import org.bitcoinj.wallet.SendRequest; import org.bitcoinj.wallet.SendRequest;
import org.bitcoinj.wallet.Wallet; import org.bitcoinj.wallet.Wallet;
@ -47,7 +49,7 @@ public class TestFeeLevel {
Coin feeRateToTest = Coin.valueOf(Long.parseLong(args[0])); Coin feeRateToTest = Coin.valueOf(Long.parseLong(args[0]));
System.out.println("Fee rate to test is " + feeRateToTest.toFriendlyString() + "/kB"); System.out.println("Fee rate to test is " + feeRateToTest.toFriendlyString() + "/kB");
kit = new WalletAppKit(PARAMS, new File("."), "testfeelevel"); kit = new WalletAppKit(PARAMS, Script.ScriptType.P2WPKH, KeyChainGroupStructure.BIP32, new File("."), "testfeelevel");
kit.startAsync(); kit.startAsync();
kit.awaitRunning(); kit.awaitRunning();
try { try {