mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2024-11-20 18:22:12 +01:00
Wallet: Remove (or reduce visibility of) the deprecated constructors.
Replace usages in unit tests and examples with usage of the static createDeterministic() constructor.
This commit is contained in:
parent
c18cf90a8e
commit
783dd45c4b
@ -258,18 +258,6 @@ public class Wallet extends BaseTaggableObject
|
||||
return createDeterministic(Context.getOrCreate(params), outputScriptType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new, empty wallet with a randomly chosen seed and no transactions. Make sure to provide for sufficient
|
||||
* backup! Any keys will be derived from the seed. If you want to restore a wallet from disk instead, see
|
||||
* {@link #loadFromFile}.
|
||||
* @param params network parameters
|
||||
* @deprecated Use {@link #createDeterministic(NetworkParameters, ScriptType)}
|
||||
*/
|
||||
@Deprecated
|
||||
public Wallet(NetworkParameters params) {
|
||||
this(params, KeyChainGroup.builder(params).fromRandom(Script.ScriptType.P2PKH).build());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new, empty wallet with a randomly chosen seed and no transactions. Make sure to provide for sufficient
|
||||
* backup! Any keys will be derived from the seed. If you want to restore a wallet from disk instead, see
|
||||
@ -287,7 +275,8 @@ public class Wallet extends BaseTaggableObject
|
||||
* @deprecated Use {@link #createDeterministic(Context, ScriptType)}
|
||||
*/
|
||||
@Deprecated
|
||||
public Wallet(Context context) {
|
||||
@VisibleForTesting
|
||||
protected Wallet(Context context) {
|
||||
this(context, KeyChainGroup.builder(context.getParams()).fromRandom(Script.ScriptType.P2PKH).build());
|
||||
}
|
||||
|
||||
|
@ -310,7 +310,7 @@ public abstract class AbstractFullPrunedBlockChainTest {
|
||||
rollingBlock = rollingBlock.createNextBlock(null);
|
||||
|
||||
// Create 1 BTC spend to a key in this wallet (to ourselves).
|
||||
Wallet wallet = new Wallet(PARAMS);
|
||||
Wallet wallet = Wallet.createDeterministic(PARAMS, Script.ScriptType.P2PKH);
|
||||
assertEquals("Available balance is incorrect", Coin.ZERO, wallet.getBalance(Wallet.BalanceType.AVAILABLE));
|
||||
assertEquals("Estimated balance is incorrect", Coin.ZERO, wallet.getBalance(Wallet.BalanceType.ESTIMATED));
|
||||
|
||||
|
@ -20,6 +20,7 @@ package org.bitcoinj.core;
|
||||
import org.bitcoinj.params.MainNetParams;
|
||||
import org.bitcoinj.params.TestNet3Params;
|
||||
import org.bitcoinj.params.UnitTestParams;
|
||||
import org.bitcoinj.script.Script;
|
||||
import org.bitcoinj.store.BlockStore;
|
||||
import org.bitcoinj.store.MemoryBlockStore;
|
||||
import org.bitcoinj.testing.FakeTxBuilder;
|
||||
@ -76,9 +77,9 @@ public class BlockChainTest {
|
||||
public void setUp() throws Exception {
|
||||
BriefLogFormatter.initVerbose();
|
||||
Context.propagate(new Context(TESTNET, 100, Coin.ZERO, false));
|
||||
testNetChain = new BlockChain(TESTNET, new Wallet(TESTNET), new MemoryBlockStore(TESTNET));
|
||||
testNetChain = new BlockChain(TESTNET, Wallet.createDeterministic(TESTNET, Script.ScriptType.P2PKH), new MemoryBlockStore(TESTNET));
|
||||
Context.propagate(new Context(UNITTEST, 100, Coin.ZERO, false));
|
||||
wallet = new Wallet(UNITTEST) {
|
||||
wallet = new Wallet(Context.get()) {
|
||||
@Override
|
||||
public void receiveFromBlock(Transaction tx, StoredBlock block, BlockChain.NewBlockType blockType,
|
||||
int relativityOffset) throws VerificationException {
|
||||
@ -314,7 +315,7 @@ public class BlockChainTest {
|
||||
// Check that a coinbase transaction is only available to spend after NetworkParameters.getSpendableCoinbaseDepth() blocks.
|
||||
|
||||
// Create a second wallet to receive the coinbase spend.
|
||||
Wallet wallet2 = new Wallet(UNITTEST);
|
||||
Wallet wallet2 = Wallet.createDeterministic(UNITTEST, Script.ScriptType.P2PKH);
|
||||
ECKey receiveKey = wallet2.freshReceiveKey();
|
||||
int height = 1;
|
||||
chain.addWallet(wallet2);
|
||||
|
@ -23,6 +23,7 @@ import org.bitcoinj.core.AbstractBlockChain.NewBlockType;
|
||||
import org.bitcoinj.params.MainNetParams;
|
||||
import org.bitcoinj.params.TestNet3Params;
|
||||
import org.bitcoinj.params.UnitTestParams;
|
||||
import org.bitcoinj.script.Script;
|
||||
import org.bitcoinj.script.ScriptOpCodes;
|
||||
import org.bitcoinj.wallet.Wallet;
|
||||
import org.bitcoinj.wallet.Wallet.BalanceType;
|
||||
@ -220,7 +221,7 @@ public class BlockTest {
|
||||
ECKey miningKey = DumpedPrivateKey.fromBase58(MAINNET, MINING_PRIVATE_KEY).getKey();
|
||||
assertNotNull(miningKey);
|
||||
Context context = new Context(MAINNET);
|
||||
Wallet wallet = new Wallet(context);
|
||||
Wallet wallet = Wallet.createDeterministic(context, Script.ScriptType.P2PKH);
|
||||
wallet.importKey(miningKey);
|
||||
|
||||
// Initial balance should be zero by construction.
|
||||
|
@ -20,6 +20,7 @@ package org.bitcoinj.core;
|
||||
import org.bitcoinj.core.listeners.TransactionConfidenceEventListener;
|
||||
import org.bitcoinj.core.TransactionConfidence.ConfidenceType;
|
||||
import org.bitcoinj.params.UnitTestParams;
|
||||
import org.bitcoinj.script.Script;
|
||||
import org.bitcoinj.store.MemoryBlockStore;
|
||||
import org.bitcoinj.testing.FakeTxBuilder;
|
||||
import org.bitcoinj.utils.BriefLogFormatter;
|
||||
@ -61,7 +62,7 @@ public class ChainSplitTest {
|
||||
Utils.setMockClock(); // Use mock clock
|
||||
Context.propagate(new Context(UNITTEST, 100, Coin.ZERO, false));
|
||||
MemoryBlockStore blockStore = new MemoryBlockStore(UNITTEST);
|
||||
wallet = new Wallet(UNITTEST);
|
||||
wallet = Wallet.createDeterministic(UNITTEST, Script.ScriptType.P2PKH);
|
||||
ECKey key1 = wallet.freshReceiveKey();
|
||||
ECKey key2 = wallet.freshReceiveKey();
|
||||
chain = new BlockChain(UNITTEST, wallet, blockStore);
|
||||
|
@ -19,6 +19,7 @@ package org.bitcoinj.core;
|
||||
|
||||
import org.bitcoinj.params.MainNetParams;
|
||||
import org.bitcoinj.params.UnitTestParams;
|
||||
import org.bitcoinj.script.Script;
|
||||
import org.bitcoinj.store.BlockStore;
|
||||
import org.bitcoinj.store.MemoryBlockStore;
|
||||
import org.bitcoinj.wallet.Wallet;
|
||||
@ -85,7 +86,7 @@ public class ParseByteCacheTest {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
Context context = new Context(UNITTEST);
|
||||
Wallet wallet = new Wallet(context);
|
||||
Wallet wallet = Wallet.createDeterministic(context, Script.ScriptType.P2PKH);
|
||||
wallet.freshReceiveKey();
|
||||
|
||||
resetBlockStore();
|
||||
|
@ -243,7 +243,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
|
||||
// Create a peer.
|
||||
InboundMessageQueuer p1 = connectPeer(1);
|
||||
|
||||
Wallet wallet2 = new Wallet(UNITTEST);
|
||||
Wallet wallet2 = Wallet.createDeterministic(UNITTEST, Script.ScriptType.P2PKH);
|
||||
ECKey key2 = wallet2.freshReceiveKey();
|
||||
Address address2 = LegacyAddress.fromKey(UNITTEST, key2);
|
||||
|
||||
@ -419,7 +419,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
|
||||
final long now = Utils.currentTimeSeconds();
|
||||
peerGroup.start();
|
||||
assertTrue(peerGroup.getFastCatchupTimeSecs() > now - WEEK - 10000);
|
||||
Wallet w2 = new Wallet(UNITTEST);
|
||||
Wallet w2 = Wallet.createDeterministic(UNITTEST, Script.ScriptType.P2PKH);
|
||||
ECKey key1 = new ECKey();
|
||||
key1.setCreationTimeSeconds(now - 86400); // One day ago.
|
||||
w2.importKey(key1);
|
||||
|
@ -19,6 +19,7 @@ package org.bitcoinj.core;
|
||||
import com.google.common.collect.*;
|
||||
import org.bitcoinj.core.listeners.*;
|
||||
import org.bitcoinj.params.TestNet3Params;
|
||||
import org.bitcoinj.script.Script;
|
||||
import org.bitcoinj.testing.FakeTxBuilder;
|
||||
import org.bitcoinj.testing.InboundMessageQueuer;
|
||||
import org.bitcoinj.testing.TestWithNetworkConnections;
|
||||
@ -686,7 +687,7 @@ public class PeerTest extends TestWithNetworkConnections {
|
||||
connectWithVersion(70001, VersionMessage.NODE_NETWORK);
|
||||
// Test that if we receive a relevant transaction that has a lock time, it doesn't result in a notification
|
||||
// until we explicitly opt in to seeing those.
|
||||
Wallet wallet = new Wallet(UNITTEST);
|
||||
Wallet wallet = Wallet.createDeterministic(UNITTEST, Script.ScriptType.P2PKH);
|
||||
ECKey key = wallet.freshReceiveKey();
|
||||
peer.addWallet(wallet);
|
||||
final Transaction[] vtx = new Transaction[1];
|
||||
@ -737,7 +738,7 @@ public class PeerTest extends TestWithNetworkConnections {
|
||||
private void checkTimeLockedDependency(boolean shouldAccept) throws Exception {
|
||||
// Initial setup.
|
||||
connectWithVersion(70001, VersionMessage.NODE_NETWORK);
|
||||
Wallet wallet = new Wallet(UNITTEST);
|
||||
Wallet wallet = Wallet.createDeterministic(UNITTEST, Script.ScriptType.P2PKH);
|
||||
ECKey key = wallet.freshReceiveKey();
|
||||
wallet.setAcceptRiskyTransactions(shouldAccept);
|
||||
peer.addWallet(wallet);
|
||||
|
@ -22,6 +22,7 @@ import static org.junit.Assert.assertNull;
|
||||
import java.util.List;
|
||||
|
||||
import org.bitcoinj.params.UnitTestParams;
|
||||
import org.bitcoinj.script.Script;
|
||||
import org.bitcoinj.script.ScriptBuilder;
|
||||
import org.bitcoinj.testing.FakeTxBuilder;
|
||||
import org.bitcoinj.wallet.AllowUnconfirmedCoinSelector;
|
||||
@ -36,7 +37,7 @@ public class TransactionInputTest {
|
||||
|
||||
@Test
|
||||
public void testStandardWalletDisconnect() throws Exception {
|
||||
Wallet w = new Wallet(new Context(UNITTEST));
|
||||
Wallet w = Wallet.createDeterministic(new Context(UNITTEST), Script.ScriptType.P2PKH);
|
||||
w.setCoinSelector(new AllowUnconfirmedCoinSelector());
|
||||
Address a = w.currentReceiveAddress();
|
||||
Transaction tx1 = FakeTxBuilder.createFakeTxWithoutChangeAddress(UNITTEST, Coin.COIN, a);
|
||||
@ -58,7 +59,7 @@ public class TransactionInputTest {
|
||||
|
||||
@Test
|
||||
public void testUTXOWalletDisconnect() throws Exception {
|
||||
Wallet w = new Wallet(new Context(UNITTEST));
|
||||
Wallet w = Wallet.createDeterministic(new Context(UNITTEST), Script.ScriptType.P2PKH);
|
||||
Address a = w.currentReceiveAddress();
|
||||
final UTXO utxo = new UTXO(Sha256Hash.of(new byte[] { 1, 2, 3 }), 1, Coin.COIN, 0, false,
|
||||
ScriptBuilder.createOutputScript(a));
|
||||
|
@ -18,6 +18,7 @@ package org.bitcoinj.protocols.channels;
|
||||
|
||||
import org.bitcoinj.core.*;
|
||||
import org.bitcoinj.protocols.channels.PaymentChannelClient.VersionSelector;
|
||||
import org.bitcoinj.script.Script;
|
||||
import org.bitcoinj.script.ScriptPattern;
|
||||
import org.bitcoinj.testing.TestWithWallet;
|
||||
import org.bitcoinj.utils.Threading;
|
||||
@ -117,7 +118,7 @@ public class ChannelConnectionTest extends TestWithWallet {
|
||||
sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, COIN);
|
||||
sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, COIN);
|
||||
wallet.addExtension(new StoredPaymentChannelClientStates(wallet, failBroadcaster));
|
||||
serverWallet = new Wallet(UNITTEST);
|
||||
serverWallet = Wallet.createDeterministic(UNITTEST, Script.ScriptType.P2PKH);
|
||||
serverWallet.addExtension(new StoredPaymentChannelServerStates(serverWallet, failBroadcaster));
|
||||
serverWallet.freshReceiveKey();
|
||||
// Use an atomic boolean to indicate failure because fail()/assert*() don't work in network threads
|
||||
@ -689,7 +690,7 @@ public class ChannelConnectionTest extends TestWithWallet {
|
||||
|
||||
@Test
|
||||
public void testEmptyWallet() throws Exception {
|
||||
Wallet emptyWallet = new Wallet(UNITTEST);
|
||||
Wallet emptyWallet = Wallet.createDeterministic(UNITTEST, Script.ScriptType.P2PKH);
|
||||
emptyWallet.freshReceiveKey();
|
||||
ChannelTestUtils.RecordingPair pair = ChannelTestUtils.makeRecorders(serverWallet, mockBroadcaster);
|
||||
PaymentChannelServer server = pair.server;
|
||||
|
@ -102,7 +102,7 @@ public class PaymentChannelStateTest extends TestWithWallet {
|
||||
}));
|
||||
sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, COIN);
|
||||
chain = new BlockChain(UNITTEST, wallet, blockStore); // Recreate chain as sendMoneyToWallet will confuse it
|
||||
serverWallet = new Wallet(UNITTEST);
|
||||
serverWallet = Wallet.createDeterministic(UNITTEST, Script.ScriptType.P2PKH);
|
||||
serverKey = serverWallet.freshReceiveKey();
|
||||
chain.addWallet(serverWallet);
|
||||
|
||||
|
@ -193,7 +193,7 @@ public class WalletProtobufSerializerTest {
|
||||
for (int i = 0 ; i < 20 ; i++) {
|
||||
myKey = new ECKey();
|
||||
myAddress = LegacyAddress.fromKey(UNITTEST, myKey);
|
||||
myWallet = new Wallet(UNITTEST);
|
||||
myWallet = Wallet.createDeterministic(UNITTEST, Script.ScriptType.P2PKH);
|
||||
myWallet.importKey(myKey);
|
||||
Wallet wallet1 = roundTrip(myWallet);
|
||||
ECKey foundKey = wallet1.findKeyFromPubKeyHash(myKey.getPubKeyHash(), null);
|
||||
@ -207,7 +207,7 @@ public class WalletProtobufSerializerTest {
|
||||
// Test the lastBlockSeenHash field works.
|
||||
|
||||
// LastBlockSeenHash should be empty if never set.
|
||||
Wallet wallet = new Wallet(UNITTEST);
|
||||
Wallet wallet = Wallet.createDeterministic(UNITTEST, Script.ScriptType.P2PKH);
|
||||
Protos.Wallet walletProto = new WalletProtobufSerializer().walletToProto(wallet);
|
||||
ByteString lastSeenBlockHash = walletProto.getLastSeenBlockHash();
|
||||
assertTrue(lastSeenBlockHash.isEmpty());
|
||||
@ -233,7 +233,7 @@ public class WalletProtobufSerializerTest {
|
||||
|
||||
@Test
|
||||
public void testSequenceNumber() throws Exception {
|
||||
Wallet wallet = new Wallet(UNITTEST);
|
||||
Wallet wallet = Wallet.createDeterministic(UNITTEST, Script.ScriptType.P2PKH);
|
||||
Transaction tx1 = createFakeTx(UNITTEST, Coin.COIN, wallet.currentReceiveAddress());
|
||||
tx1.getInput(0).setSequenceNumber(TransactionInput.NO_SEQUENCE);
|
||||
wallet.receivePending(tx1, null);
|
||||
@ -358,7 +358,7 @@ public class WalletProtobufSerializerTest {
|
||||
@Test
|
||||
public void testRoundTripMarriedWallet() throws Exception {
|
||||
// create 2-of-2 married wallet
|
||||
myWallet = new Wallet(UNITTEST);
|
||||
myWallet = Wallet.createDeterministic(UNITTEST, Script.ScriptType.P2PKH);
|
||||
final DeterministicKeyChain partnerChain = DeterministicKeyChain.builder().random(new SecureRandom()).build();
|
||||
DeterministicKey partnerKey = DeterministicKey.deserializeB58(null, partnerChain.getWatchingKey().serializePubB58(UNITTEST), UNITTEST);
|
||||
MarriedKeyChain chain = MarriedKeyChain.builder()
|
||||
@ -429,7 +429,7 @@ public class WalletProtobufSerializerTest {
|
||||
assertTrue(wallet.getExtensions().containsKey("com.whatever.required"));
|
||||
|
||||
// Non-mandatory extensions are ignored if the wallet doesn't know how to read them.
|
||||
Wallet wallet2 = new Wallet(UNITTEST);
|
||||
Wallet wallet2 = Wallet.createDeterministic(UNITTEST, Script.ScriptType.P2PKH);
|
||||
wallet2.addExtension(new FooWalletExtension("com.whatever.optional", false));
|
||||
Protos.Wallet proto2 = new WalletProtobufSerializer().walletToProto(wallet2);
|
||||
Wallet wallet5 = new WalletProtobufSerializer().readWallet(UNITTEST, null, proto2);
|
||||
|
@ -115,7 +115,7 @@ public class WalletTest extends TestWithWallet {
|
||||
}
|
||||
|
||||
private void createMarriedWallet(int threshold, int numKeys, boolean addSigners) throws BlockStoreException {
|
||||
wallet = new Wallet(UNITTEST);
|
||||
wallet = Wallet.createDeterministic(UNITTEST, Script.ScriptType.P2PKH);
|
||||
blockStore = new MemoryBlockStore(UNITTEST);
|
||||
chain = new BlockChain(UNITTEST, wallet, blockStore);
|
||||
|
||||
@ -173,7 +173,7 @@ public class WalletTest extends TestWithWallet {
|
||||
|
||||
@Test
|
||||
public void basicSpendingWithEncryptedWallet() throws Exception {
|
||||
Wallet encryptedWallet = new Wallet(UNITTEST);
|
||||
Wallet encryptedWallet = Wallet.createDeterministic(UNITTEST, Script.ScriptType.P2PKH);
|
||||
encryptedWallet.encrypt(PASSWORD1);
|
||||
Address myEncryptedAddress = LegacyAddress.fromKey(UNITTEST, encryptedWallet.freshReceiveKey());
|
||||
basicSpendingCommon(encryptedWallet, myEncryptedAddress, OTHER_ADDRESS, encryptedWallet);
|
||||
@ -723,7 +723,7 @@ public class WalletTest extends TestWithWallet {
|
||||
|
||||
@Test
|
||||
public void isTxConsistentReturnsFalseAsExpected() {
|
||||
Wallet wallet = new Wallet(UNITTEST);
|
||||
Wallet wallet = Wallet.createDeterministic(UNITTEST, Script.ScriptType.P2PKH);
|
||||
TransactionOutput to = createMock(TransactionOutput.class);
|
||||
EasyMock.expect(to.isAvailableForSpending()).andReturn(true);
|
||||
EasyMock.expect(to.isMineOrWatched(wallet)).andReturn(true);
|
||||
@ -739,7 +739,7 @@ public class WalletTest extends TestWithWallet {
|
||||
|
||||
@Test
|
||||
public void isTxConsistentReturnsFalseAsExpected_WhenAvailableForSpendingEqualsFalse() {
|
||||
Wallet wallet = new Wallet(UNITTEST);
|
||||
Wallet wallet = Wallet.createDeterministic(UNITTEST, Script.ScriptType.P2PKH);
|
||||
TransactionOutput to = createMock(TransactionOutput.class);
|
||||
EasyMock.expect(to.isAvailableForSpending()).andReturn(false);
|
||||
EasyMock.expect(to.getSpentBy()).andReturn(null);
|
||||
@ -1525,7 +1525,7 @@ public class WalletTest extends TestWithWallet {
|
||||
public void keyCreationTime() throws Exception {
|
||||
Utils.setMockClock();
|
||||
long now = Utils.currentTimeSeconds();
|
||||
wallet = new Wallet(UNITTEST);
|
||||
wallet = Wallet.createDeterministic(UNITTEST, Script.ScriptType.P2PKH);
|
||||
assertEquals(now, wallet.getEarliestKeyCreationTime());
|
||||
Utils.rollMockClock(60);
|
||||
wallet.freshReceiveKey();
|
||||
@ -1536,7 +1536,7 @@ public class WalletTest extends TestWithWallet {
|
||||
public void scriptCreationTime() throws Exception {
|
||||
Utils.setMockClock();
|
||||
long now = Utils.currentTimeSeconds();
|
||||
wallet = new Wallet(UNITTEST);
|
||||
wallet = Wallet.createDeterministic(UNITTEST, Script.ScriptType.P2PKH);
|
||||
assertEquals(now, wallet.getEarliestKeyCreationTime());
|
||||
Utils.rollMockClock(-120);
|
||||
wallet.addWatchedAddress(OTHER_ADDRESS);
|
||||
@ -1970,7 +1970,7 @@ public class WalletTest extends TestWithWallet {
|
||||
|
||||
@Test
|
||||
public void encryptionDecryptionAESBasic() throws Exception {
|
||||
Wallet encryptedWallet = new Wallet(UNITTEST);
|
||||
Wallet encryptedWallet = Wallet.createDeterministic(UNITTEST, Script.ScriptType.P2PKH);
|
||||
encryptedWallet.encrypt(PASSWORD1);
|
||||
KeyCrypter keyCrypter = encryptedWallet.getKeyCrypter();
|
||||
KeyParameter aesKey = keyCrypter.deriveKey(PASSWORD1);
|
||||
@ -1993,7 +1993,7 @@ public class WalletTest extends TestWithWallet {
|
||||
|
||||
@Test
|
||||
public void encryptionDecryptionPasswordBasic() throws Exception {
|
||||
Wallet encryptedWallet = new Wallet(UNITTEST);
|
||||
Wallet encryptedWallet = Wallet.createDeterministic(UNITTEST, Script.ScriptType.P2PKH);
|
||||
encryptedWallet.encrypt(PASSWORD1);
|
||||
|
||||
assertTrue(encryptedWallet.isEncrypted());
|
||||
@ -2011,7 +2011,7 @@ public class WalletTest extends TestWithWallet {
|
||||
|
||||
@Test
|
||||
public void encryptionDecryptionBadPassword() throws Exception {
|
||||
Wallet encryptedWallet = new Wallet(UNITTEST);
|
||||
Wallet encryptedWallet = Wallet.createDeterministic(UNITTEST, Script.ScriptType.P2PKH);
|
||||
encryptedWallet.encrypt(PASSWORD1);
|
||||
KeyCrypter keyCrypter = encryptedWallet.getKeyCrypter();
|
||||
KeyParameter wrongAesKey = keyCrypter.deriveKey(WRONG_PASSWORD);
|
||||
@ -2031,7 +2031,7 @@ public class WalletTest extends TestWithWallet {
|
||||
|
||||
@Test
|
||||
public void changePasswordTest() {
|
||||
Wallet encryptedWallet = new Wallet(UNITTEST);
|
||||
Wallet encryptedWallet = Wallet.createDeterministic(UNITTEST, Script.ScriptType.P2PKH);
|
||||
encryptedWallet.encrypt(PASSWORD1);
|
||||
CharSequence newPassword = "My name is Tom";
|
||||
encryptedWallet.changeEncryptionPassword(PASSWORD1, newPassword);
|
||||
@ -2041,7 +2041,7 @@ public class WalletTest extends TestWithWallet {
|
||||
|
||||
@Test
|
||||
public void changeAesKeyTest() {
|
||||
Wallet encryptedWallet = new Wallet(UNITTEST);
|
||||
Wallet encryptedWallet = Wallet.createDeterministic(UNITTEST, Script.ScriptType.P2PKH);
|
||||
encryptedWallet.encrypt(PASSWORD1);
|
||||
|
||||
KeyCrypter keyCrypter = encryptedWallet.getKeyCrypter();
|
||||
@ -2058,7 +2058,7 @@ public class WalletTest extends TestWithWallet {
|
||||
|
||||
@Test
|
||||
public void encryptionDecryptionCheckExceptions() throws Exception {
|
||||
Wallet encryptedWallet = new Wallet(UNITTEST);
|
||||
Wallet encryptedWallet = Wallet.createDeterministic(UNITTEST, Script.ScriptType.P2PKH);
|
||||
encryptedWallet.encrypt(PASSWORD1);
|
||||
KeyCrypter keyCrypter = encryptedWallet.getKeyCrypter();
|
||||
KeyParameter aesKey = keyCrypter.deriveKey(PASSWORD1);
|
||||
@ -2097,7 +2097,7 @@ public class WalletTest extends TestWithWallet {
|
||||
|
||||
@Test(expected = KeyCrypterException.class)
|
||||
public void addUnencryptedKeyToEncryptedWallet() throws Exception {
|
||||
Wallet encryptedWallet = new Wallet(UNITTEST);
|
||||
Wallet encryptedWallet = Wallet.createDeterministic(UNITTEST, Script.ScriptType.P2PKH);
|
||||
encryptedWallet.encrypt(PASSWORD1);
|
||||
|
||||
ECKey key1 = new ECKey();
|
||||
@ -2106,7 +2106,7 @@ public class WalletTest extends TestWithWallet {
|
||||
|
||||
@Test(expected = KeyCrypterException.class)
|
||||
public void addEncryptedKeyToUnencryptedWallet() throws Exception {
|
||||
Wallet encryptedWallet = new Wallet(UNITTEST);
|
||||
Wallet encryptedWallet = Wallet.createDeterministic(UNITTEST, Script.ScriptType.P2PKH);
|
||||
encryptedWallet.encrypt(PASSWORD1);
|
||||
KeyCrypter keyCrypter = encryptedWallet.getKeyCrypter();
|
||||
|
||||
@ -2117,7 +2117,7 @@ public class WalletTest extends TestWithWallet {
|
||||
|
||||
@Test(expected = KeyCrypterException.class)
|
||||
public void mismatchedCrypter() throws Exception {
|
||||
Wallet encryptedWallet = new Wallet(UNITTEST);
|
||||
Wallet encryptedWallet = Wallet.createDeterministic(UNITTEST, Script.ScriptType.P2PKH);
|
||||
encryptedWallet.encrypt(PASSWORD1);
|
||||
KeyCrypter keyCrypter = encryptedWallet.getKeyCrypter();
|
||||
KeyParameter aesKey = keyCrypter.deriveKey(PASSWORD1);
|
||||
@ -2132,7 +2132,7 @@ public class WalletTest extends TestWithWallet {
|
||||
|
||||
@Test
|
||||
public void importAndEncrypt() throws InsufficientMoneyException {
|
||||
Wallet encryptedWallet = new Wallet(UNITTEST);
|
||||
Wallet encryptedWallet = Wallet.createDeterministic(UNITTEST, Script.ScriptType.P2PKH);
|
||||
encryptedWallet.encrypt(PASSWORD1);
|
||||
|
||||
final ECKey key = new ECKey();
|
||||
@ -2926,7 +2926,7 @@ public class WalletTest extends TestWithWallet {
|
||||
public void keyRotationRandom() throws Exception {
|
||||
Utils.setMockClock();
|
||||
// Start with an empty wallet (no HD chain).
|
||||
wallet = new Wallet(UNITTEST);
|
||||
wallet = Wallet.createDeterministic(UNITTEST, Script.ScriptType.P2PKH);
|
||||
// Watch out for wallet-initiated broadcasts.
|
||||
MockTransactionBroadcaster broadcaster = new MockTransactionBroadcaster(wallet);
|
||||
// Send three cents to two different random keys, then add a key and mark the initial keys as compromised.
|
||||
@ -3009,7 +3009,7 @@ public class WalletTest extends TestWithWallet {
|
||||
public void keyRotationHD() throws Exception {
|
||||
// Test that if we rotate an HD chain, a new one is created and all arrivals on the old keys are moved.
|
||||
Utils.setMockClock();
|
||||
wallet = new Wallet(UNITTEST);
|
||||
wallet = Wallet.createDeterministic(UNITTEST, Script.ScriptType.P2PKH);
|
||||
ECKey key1 = wallet.freshReceiveKey();
|
||||
ECKey key2 = wallet.freshReceiveKey();
|
||||
sendMoneyToWallet(wallet, AbstractBlockChain.NewBlockType.BEST_CHAIN, CENT, LegacyAddress.fromKey(UNITTEST, key1));
|
||||
|
@ -19,6 +19,7 @@ package org.bitcoinj.examples;
|
||||
import org.bitcoinj.core.NetworkParameters;
|
||||
import org.bitcoinj.core.Utils;
|
||||
import org.bitcoinj.params.TestNet3Params;
|
||||
import org.bitcoinj.script.Script;
|
||||
import org.bitcoinj.wallet.DeterministicSeed;
|
||||
import org.bitcoinj.wallet.Wallet;
|
||||
|
||||
@ -35,7 +36,7 @@ public class BackupToMnemonicSeed {
|
||||
public static void main(String[] args) {
|
||||
|
||||
NetworkParameters params = TestNet3Params.get();
|
||||
Wallet wallet = new Wallet(params);
|
||||
Wallet wallet = Wallet.createDeterministic(params, Script.ScriptType.P2PKH);
|
||||
|
||||
DeterministicSeed seed = wallet.getKeyChainSeed();
|
||||
System.out.println("seed: " + seed.toString());
|
||||
|
@ -27,6 +27,7 @@ import org.bitcoinj.core.NetworkParameters;
|
||||
import org.bitcoinj.core.PeerAddress;
|
||||
import org.bitcoinj.core.PeerGroup;
|
||||
import org.bitcoinj.params.MainNetParams;
|
||||
import org.bitcoinj.script.Script;
|
||||
import org.bitcoinj.store.MemoryBlockStore;
|
||||
import org.bitcoinj.wallet.Wallet;
|
||||
|
||||
@ -63,7 +64,7 @@ public class PrivateKeys {
|
||||
Address destination = LegacyAddress.fromBase58(params, args[1]);
|
||||
|
||||
// Import the private key to a fresh wallet.
|
||||
Wallet wallet = new Wallet(params);
|
||||
Wallet wallet = Wallet.createDeterministic(params, Script.ScriptType.P2PKH);
|
||||
wallet.importKey(key);
|
||||
|
||||
// Find the transactions that involve those coins.
|
||||
|
Loading…
Reference in New Issue
Block a user