mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-01-31 15:22:16 +00:00
Add/Remove wallets to the connected peers as they are added/removed
to/from the PeerGroup
This commit is contained in:
parent
a24f5cb5ba
commit
2010614fd6
@ -881,6 +881,9 @@ public class PeerGroup extends AbstractExecutionThreadService implements Transac
|
||||
wallet.setTransactionBroadcaster(this);
|
||||
wallet.addEventListener(walletEventListener, Threading.SAME_THREAD);
|
||||
addPeerFilterProvider(wallet);
|
||||
for (Peer peer : peers) {
|
||||
peer.addWallet(wallet);
|
||||
}
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
@ -919,6 +922,9 @@ public class PeerGroup extends AbstractExecutionThreadService implements Transac
|
||||
peerFilterProviders.remove(wallet);
|
||||
wallet.removeEventListener(walletEventListener);
|
||||
wallet.setTransactionBroadcaster(null);
|
||||
for (Peer peer : peers) {
|
||||
peer.removeWallet(wallet);
|
||||
}
|
||||
}
|
||||
|
||||
public static enum FilterRecalculateMode {
|
||||
|
@ -241,6 +241,44 @@ public class PeerGroupTest extends TestWithPeerGroup {
|
||||
peerGroup.awaitTerminated();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void receiveTxBroadcastOnAddedWallet() throws Exception {
|
||||
// Check that when we receive transactions on all our peers, we do the right thing.
|
||||
peerGroup.startAsync();
|
||||
peerGroup.awaitRunning();
|
||||
|
||||
// Create a peer.
|
||||
InboundMessageQueuer p1 = connectPeer(1);
|
||||
|
||||
Wallet wallet2 = new Wallet(unitTestParams);
|
||||
ECKey key2 = wallet2.freshReceiveKey();
|
||||
Address address2 = key2.toAddress(unitTestParams);
|
||||
|
||||
peerGroup.addWallet(wallet2);
|
||||
blockChain.addWallet(wallet2);
|
||||
|
||||
assertTrue(outbound(p1) instanceof BloomFilter);
|
||||
assertTrue(outbound(p1) instanceof MemoryPoolMessage);
|
||||
|
||||
Coin value = COIN;
|
||||
Transaction t1 = FakeTxBuilder.createFakeTx(unitTestParams, value, address2);
|
||||
InventoryMessage inv = new InventoryMessage(unitTestParams);
|
||||
inv.addTransaction(t1);
|
||||
|
||||
inbound(p1, inv);
|
||||
assertTrue(outbound(p1) instanceof GetDataMessage);
|
||||
inbound(p1, t1);
|
||||
// Asks for dependency.
|
||||
GetDataMessage getdata = (GetDataMessage) outbound(p1);
|
||||
assertNotNull(getdata);
|
||||
inbound(p1, new NotFoundMessage(unitTestParams, getdata.getItems()));
|
||||
pingAndWait(p1);
|
||||
assertEquals(value, wallet2.getBalance(Wallet.BalanceType.ESTIMATED));
|
||||
peerGroup.stopAsync();
|
||||
peerGroup.awaitTerminated();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleDownloadPeer1() throws Exception {
|
||||
// Check that we don't attempt to retrieve blocks on multiple peers.
|
||||
|
Loading…
Reference in New Issue
Block a user