HD wallets alpha preview

This commit is contained in:
Mike Hearn
2014-03-26 20:05:33 +01:00
parent 780be05260
commit 5638387d3a
71 changed files with 6582 additions and 1601 deletions

View File

@@ -17,10 +17,7 @@
package com.google.bitcoin.examples;
import com.google.bitcoin.core.ECKey;
import com.google.bitcoin.core.NetworkParameters;
import com.google.bitcoin.core.Utils;
import com.google.bitcoin.core.Wallet;
import com.google.bitcoin.core.*;
import com.google.bitcoin.kits.WalletAppKit;
import com.google.bitcoin.params.RegTestParams;
import com.google.bitcoin.protocols.channels.PaymentChannelClientConnection;
@@ -28,6 +25,7 @@ import com.google.bitcoin.protocols.channels.StoredPaymentChannelClientStates;
import com.google.bitcoin.protocols.channels.ValueOutOfRangeException;
import com.google.bitcoin.utils.BriefLogFormatter;
import com.google.bitcoin.utils.Threading;
import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
@@ -38,6 +36,7 @@ import java.io.File;
import java.io.IOException;
import java.math.BigInteger;
import java.net.InetSocketAddress;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
@@ -72,11 +71,11 @@ public class ExamplePaymentChannelClient {
// the plugin that knows how to parse all the additional data is present during the load.
appKit = new WalletAppKit(params, new File("."), "payment_channel_example_client") {
@Override
protected void addWalletExtensions() {
protected List<WalletExtension> provideWalletExtensions() {
// The StoredPaymentChannelClientStates object is responsible for, amongst other things, broadcasting
// the refund transaction if its lock time has expired. It also persists channels so we can resume them
// after a restart.
wallet().addExtension(new StoredPaymentChannelClientStates(wallet(), peerGroup()));
return ImmutableList.<WalletExtension>of(new StoredPaymentChannelClientStates(null, peerGroup()));
}
};
appKit.connectToLocalHost();
@@ -84,7 +83,7 @@ public class ExamplePaymentChannelClient {
appKit.awaitRunning();
// We now have active network connections and a fully synced wallet.
// Add a new key which will be used for the multisig contract.
appKit.wallet().addKey(myKey);
appKit.wallet().importKey(myKey);
appKit.wallet().allowSpendingUnconfirmedTransactions();
System.out.println(appKit.wallet());

View File

@@ -20,15 +20,18 @@ package com.google.bitcoin.examples;
import com.google.bitcoin.core.NetworkParameters;
import com.google.bitcoin.core.Sha256Hash;
import com.google.bitcoin.core.VerificationException;
import com.google.bitcoin.core.WalletExtension;
import com.google.bitcoin.kits.WalletAppKit;
import com.google.bitcoin.params.RegTestParams;
import com.google.bitcoin.protocols.channels.*;
import com.google.bitcoin.utils.BriefLogFormatter;
import com.google.common.collect.ImmutableList;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.math.BigInteger;
import java.net.SocketAddress;
import java.util.List;
/**
* Simple server that listens on port 4242 for incoming payment channels.
@@ -52,12 +55,11 @@ public class ExamplePaymentChannelServer implements PaymentChannelServerListener
// the plugin that knows how to parse all the additional data is present during the load.
appKit = new WalletAppKit(params, new File("."), "payment_channel_example_server") {
@Override
protected void addWalletExtensions() {
protected List<WalletExtension> provideWalletExtensions() {
// The StoredPaymentChannelClientStates object is responsible for, amongst other things, broadcasting
// the refund transaction if its lock time has expired. It also persists channels so we can resume them
// after a restart.
storedStates = new StoredPaymentChannelServerStates(wallet(), peerGroup());
wallet().addExtension(storedStates);
return ImmutableList.<WalletExtension>of(new StoredPaymentChannelServerStates(null, peerGroup()));
}
};
appKit.connectToLocalHost();

View File

@@ -110,7 +110,7 @@ public class ForwardingService {
}
});
Address sendToAddress = kit.wallet().getKeys().get(0).toAddress(params);
Address sendToAddress = kit.wallet().currentReceiveKey().toAddress(params);
System.out.println("Send coins to: " + sendToAddress);
System.out.println("Waiting for coins to arrive. Press Ctrl-C to quit.");

View File

@@ -46,7 +46,7 @@ public class PrivateKeys {
key = dumpedPrivateKey.getKey();
} else {
BigInteger privKey = Base58.decodeToBigInteger(args[0]);
key = new ECKey(privKey);
key = ECKey.fromPrivate(privKey);
}
System.out.println("Address from private key is: " + key.toAddress(params).toString());
// And the address ...
@@ -54,7 +54,7 @@ public class PrivateKeys {
// Import the private key to a fresh wallet.
Wallet wallet = new Wallet(params);
wallet.addKey(key);
wallet.importKey(key);
// Find the transactions that involve those coins.
final MemoryBlockStore blockStore = new MemoryBlockStore(params);