mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-11-02 21:47:18 +00:00
Integrate checkpoints into WalletAppKit so they're used by default in the non-Android context.
This commit is contained in:
@@ -25,11 +25,11 @@ import com.google.common.io.BaseEncoding;
|
||||
import com.google.common.io.Resources;
|
||||
import com.google.common.primitives.Ints;
|
||||
import com.google.common.primitives.UnsignedLongs;
|
||||
|
||||
import org.spongycastle.crypto.digests.RIPEMD160Digest;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.math.BigInteger;
|
||||
import java.net.URL;
|
||||
@@ -603,4 +603,22 @@ public class Utils {
|
||||
return Joiner.on('\n').join(lines);
|
||||
}
|
||||
|
||||
// Can't use Closeable here because it's Java 7 only and Android devices only got that with KitKat.
|
||||
public static InputStream closeUnchecked(InputStream stream) {
|
||||
try {
|
||||
stream.close();
|
||||
return stream;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static OutputStream closeUnchecked(OutputStream stream) {
|
||||
try {
|
||||
stream.close();
|
||||
return stream;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,11 @@
|
||||
|
||||
package org.bitcoinj.kits;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.util.concurrent.AbstractIdleService;
|
||||
import com.google.common.util.concurrent.MoreExecutors;
|
||||
import com.google.common.util.concurrent.Service;
|
||||
import com.subgraph.orchid.TorClient;
|
||||
import org.bitcoinj.core.*;
|
||||
import org.bitcoinj.net.discovery.DnsDiscovery;
|
||||
import org.bitcoinj.protocols.channels.StoredPaymentChannelClientStates;
|
||||
@@ -26,11 +31,6 @@ import org.bitcoinj.store.SPVBlockStore;
|
||||
import org.bitcoinj.store.WalletProtobufSerializer;
|
||||
import org.bitcoinj.wallet.DeterministicSeed;
|
||||
import org.bitcoinj.wallet.KeyChainGroup;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.util.concurrent.AbstractIdleService;
|
||||
import com.google.common.util.concurrent.MoreExecutors;
|
||||
import com.google.common.util.concurrent.Service;
|
||||
import com.subgraph.orchid.TorClient;
|
||||
import org.bitcoinj.wallet.Protos;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -97,6 +97,11 @@ public class WalletAppKit extends AbstractIdleService {
|
||||
this.params = checkNotNull(params);
|
||||
this.directory = checkNotNull(directory);
|
||||
this.filePrefix = checkNotNull(filePrefix);
|
||||
if (!Utils.isAndroidRuntime()) {
|
||||
InputStream stream = WalletAppKit.class.getResourceAsStream("/" + params.getId() + ".checkpoints");
|
||||
if (stream != null)
|
||||
setCheckpoints(stream);
|
||||
}
|
||||
}
|
||||
|
||||
/** Will only connect to the given addresses. Cannot be called after startup. */
|
||||
@@ -144,6 +149,8 @@ public class WalletAppKit extends AbstractIdleService {
|
||||
* block sync faster for new users - please refer to the documentation on the bitcoinj website for further details.
|
||||
*/
|
||||
public WalletAppKit setCheckpoints(InputStream checkpoints) {
|
||||
if (this.checkpoints != null)
|
||||
Utils.closeUnchecked(this.checkpoints);
|
||||
this.checkpoints = checkNotNull(checkpoints);
|
||||
return this;
|
||||
}
|
||||
|
||||
BIN
core/src/main/resources/org.bitcoin.production.checkpoints
Normal file
BIN
core/src/main/resources/org.bitcoin.production.checkpoints
Normal file
Binary file not shown.
BIN
core/src/main/resources/org.bitcoin.test.checkpoints
Normal file
BIN
core/src/main/resources/org.bitcoin.test.checkpoints
Normal file
Binary file not shown.
Reference in New Issue
Block a user