Skip to content

Commit

Permalink
Merge pull request #24 from haraldh/testnet3
Browse files Browse the repository at this point in the history
Add testnet3 mode
  • Loading branch information
ksedgwic committed Jul 31, 2014
2 parents b64df9d + 57f1c5b commit 1c3eadf
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 9 deletions.
Binary file added assets/checkpoints-testnet
Binary file not shown.
37 changes: 37 additions & 0 deletions src/com/bonsai/wallet32/Constants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.bonsai.wallet32;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

import com.google.bitcoin.core.NetworkParameters;
import com.google.bitcoin.params.MainNetParams;
import com.google.bitcoin.params.TestNet3Params;

/**
* @author Harald Hoyer
*/
public class Constants
{
private static NetworkParameters networkParameters = null;
public static String CHECKPOINTS_FILENAME = null;

public static NetworkParameters getNetworkParameters(Context context)
{
if (networkParameters == null) {
boolean TESTNET = true;

try {
PackageInfo pinfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
TESTNET = pinfo.versionName.contains("-test");
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}

networkParameters = TESTNET ? TestNet3Params.get() : MainNetParams.get();
CHECKPOINTS_FILENAME = TESTNET ? "checkpoints-testnet" : "checkpoints";
}

return networkParameters;
}
}
3 changes: 1 addition & 2 deletions src/com/bonsai/wallet32/PairWalletActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.slf4j.LoggerFactory;

import com.google.bitcoin.core.NetworkParameters;
import com.google.bitcoin.params.MainNetParams;

import android.app.ProgressDialog;
import android.content.Intent;
Expand Down Expand Up @@ -142,7 +141,7 @@ protected Void doInBackground(JSONObject... args)

WalletApplication wallapp =
(WalletApplication) getApplicationContext();
NetworkParameters params = MainNetParams.get();
NetworkParameters params = Constants.getNetworkParameters(wallapp);
String filePrefix = "wallet32";

// Setup a wallet with the restore seed.
Expand Down
3 changes: 1 addition & 2 deletions src/com/bonsai/wallet32/RestoreWalletActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import com.google.bitcoin.core.NetworkParameters;
import com.google.bitcoin.crypto.MnemonicCodeX;
import com.google.bitcoin.crypto.MnemonicException;
import com.google.bitcoin.params.MainNetParams;

public class RestoreWalletActivity extends ActionBarActivity {

Expand Down Expand Up @@ -87,7 +86,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
public void restoreWallet(View view) {
mLogger.info("restore wallet");

NetworkParameters params = MainNetParams.get();
NetworkParameters params = Constants.getNetworkParameters(getApplicationContext());

String filePrefix = "wallet32";

Expand Down
5 changes: 2 additions & 3 deletions src/com/bonsai/wallet32/WalletService.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
import com.google.bitcoin.core.WrongNetworkException;
import com.google.bitcoin.crypto.KeyCrypter;
import com.google.bitcoin.crypto.MnemonicCodeX;
import com.google.bitcoin.params.MainNetParams;
import com.google.bitcoin.script.Script;
import com.google.bitcoin.wallet.WalletTransaction;
import com.google.common.util.concurrent.FutureCallback;
Expand Down Expand Up @@ -461,7 +460,7 @@ protected Integer doInBackground(Long... params)

mLogger.info("getting network parameters");

mParams = MainNetParams.get();
mParams = Constants.getNetworkParameters(getApplicationContext());

// Try to restore existing wallet.
mHDWallet = null;
Expand Down Expand Up @@ -492,7 +491,7 @@ protected Integer doInBackground(Long... params)
InputStream chkpntis = null;
if (scanTime != 0) {
try {
chkpntis = getAssets().open("checkpoints");
chkpntis = getAssets().open(Constants.CHECKPOINTS_FILENAME);
} catch (IOException e) {
chkpntis = null;
}
Expand Down
3 changes: 1 addition & 2 deletions src/com/bonsai/wallet32/WalletUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
import com.google.bitcoin.crypto.KeyCrypterScrypt;
import com.google.bitcoin.crypto.MnemonicCodeX;
import com.google.bitcoin.crypto.TransactionSignature;
import com.google.bitcoin.params.MainNetParams;
import com.google.bitcoin.script.Script;
import com.google.bitcoin.script.ScriptBuilder;
import com.google.protobuf.ByteString;
Expand Down Expand Up @@ -120,7 +119,7 @@ public static void createWallet(Context context) {
WalletApplication wallapp =
(WalletApplication) context.getApplicationContext();

NetworkParameters params = MainNetParams.get();
NetworkParameters params = Constants.getNetworkParameters(context);

// Generate a new seed.
SecureRandom random = new SecureRandom();
Expand Down

0 comments on commit 1c3eadf

Please sign in to comment.