3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-01-31 15:22:16 +00:00

WalletAppKit: Configure the peergroup with candidate peers before adding wallet extensions, as payment channel state can attempt to broadcast a transaction as soon as the state is loaded/instantiated. This ensures the number of min peers required for broadcast is correct at that point.

This commit is contained in:
Mike Hearn 2013-07-24 13:56:12 +02:00
parent a1daaa73be
commit 2a635317c3

View File

@ -98,7 +98,14 @@ public class WalletAppKit extends AbstractIdleService {
vStore = new SPVBlockStore(params, vChainFile);
vChain = new BlockChain(params, vStore);
vPeerGroup = new PeerGroup(params, vChain);
// Set up peer addresses or discovery first, so if wallet extensions try to broadcast a transaction
// before we're actually connected the broadcast waits for an appropriate number of connections.
if (vPeerAddresses != null) {
for (PeerAddress addr : vPeerAddresses) vPeerGroup.addAddress(addr);
vPeerAddresses = null;
} else {
vPeerGroup.addPeerDiscovery(new DnsDiscovery(params));
}
if (vWalletFile.exists()) {
walletStream = new FileInputStream(vWalletFile);
vWallet = new Wallet(params);
@ -113,12 +120,6 @@ public class WalletAppKit extends AbstractIdleService {
if (vUseAutoSave) vWallet.autosaveToFile(vWalletFile, 1, TimeUnit.SECONDS, null);
vChain.addWallet(vWallet);
vPeerGroup.addWallet(vWallet);
if (vPeerAddresses != null) {
for (PeerAddress addr : vPeerAddresses) vPeerGroup.addAddress(addr);
vPeerAddresses = null;
} else {
vPeerGroup.addPeerDiscovery(new DnsDiscovery(params));
}
vPeerGroup.startAndWait();
vPeerGroup.downloadBlockChain();
// Make sure we shut down cleanly.