fix serialisation issue with address entry

This commit is contained in:
Manfred Karrer 2015-11-07 03:39:37 +01:00
parent bce5460aa4
commit 6e1e3d4be3
10 changed files with 56 additions and 40 deletions

View file

@ -21,10 +21,15 @@ import io.bitsquare.app.Version;
import org.bitcoinj.core.Address;
import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.crypto.DeterministicKey;
import org.bitcoinj.params.MainNetParams;
import org.bitcoinj.params.RegTestParams;
import org.bitcoinj.params.TestNet3Params;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nullable;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;
/**
@ -56,7 +61,8 @@ public class AddressEntry implements Serializable {
private final Context context;
private final byte[] pubKey;
private final byte[] pubKeyHash;
private final NetworkParameters params;
private final String paramId;
transient private NetworkParameters params;
///////////////////////////////////////////////////////////////////////////////////////////
@ -75,10 +81,28 @@ public class AddressEntry implements Serializable {
this.context = context;
this.offerId = offerId;
paramId = params.getId();
pubKey = keyPair.getPubKey();
pubKeyHash = keyPair.getPubKeyHash();
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
try {
in.defaultReadObject();
if (MainNetParams.ID_MAINNET.equals(paramId))
params = MainNetParams.get();
else if (MainNetParams.ID_TESTNET.equals(paramId))
params = TestNet3Params.get();
else if (MainNetParams.ID_REGTEST.equals(paramId))
params = RegTestParams.get();
} catch (Throwable t) {
log.trace("Cannot be deserialized." + t.getMessage());
}
}
// Set after wallet is ready
public void setDeterministicKey(DeterministicKey deterministicKey) {
this.keyPair = deterministicKey;

View file

@ -188,6 +188,11 @@ public class WalletService {
UserThread.execute(resultHandler::handleResult);
}
};
// TODO try to get bitcoinj running over our tor proxy
/* if (!params.getId().equals(NetworkParameters.ID_REGTEST))
walletAppKit.useTor();*/
// Now configure and start the appkit. This will take a second or two - we could show a temporary splash screen
// or progress widget to keep the user engaged whilst we initialise, but we don't.
if (params == RegTestParams.get()) {