Java Code Examples for org.bitcoinj.wallet.Wallet#setTransactionBroadcaster()

The following examples show how to use org.bitcoinj.wallet.Wallet#setTransactionBroadcaster() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PeerGroup.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * <p>Link the given wallet to this PeerGroup. This is used for three purposes:</p>
 * <p>
 * <ol>
 * <li>So the wallet receives broadcast transactions.</li>
 * <li>Announcing pending transactions that didn't get into the chain yet to our peers.</li>
 * <li>Set the fast catchup time using {@link PeerGroup#setFastCatchupTimeSecs(long)}, to optimize chain
 * download.</li>
 * </ol>
 * <p>
 * <p>Note that this should be done before chain download commences because if you add a wallet with keys earlier
 * than the current chain head, the relevant parts of the chain won't be redownloaded for you.</p>
 * <p>
 * <p>The Wallet will have an event listener registered on it, so to avoid leaks remember to use
 * {@link PeerGroup#removeWallet(Wallet)} on it if you wish to keep the Wallet but lose the PeerGroup.</p>
 */
public void addWallet(Wallet wallet) {
    lock.lock();
    try {
        checkNotNull(wallet);
        checkState(!wallets.contains(wallet));
        wallets.add(wallet);
        wallet.setTransactionBroadcaster(this);
        wallet.addCoinsReceivedEventListener(Threading.SAME_THREAD, walletCoinsReceivedEventListener);
        wallet.addKeyChainEventListener(Threading.SAME_THREAD, walletKeyEventListener);
        wallet.addScriptChangeEventListener(Threading.SAME_THREAD, walletScriptEventListener);
        addPeerFilterProvider(wallet);
        for (Peer peer : peers) {
            peer.addWallet(wallet);
        }
    } finally {
        lock.unlock();
    }
}
 
Example 2
Source File: PeerGroup.java    From green_android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * <p>Link the given wallet to this PeerGroup. This is used for three purposes:</p>
 *
 * <ol>
 *   <li>So the wallet receives broadcast transactions.</li>
 *   <li>Announcing pending transactions that didn't get into the chain yet to our peers.</li>
 *   <li>Set the fast catchup time using {@link PeerGroup#setFastCatchupTimeSecs(long)}, to optimize chain
 *       download.</li>
 * </ol>
 *
 * <p>Note that this should be done before chain download commences because if you add a wallet with keys earlier
 * than the current chain head, the relevant parts of the chain won't be redownloaded for you.</p>
 *
 * <p>The Wallet will have an event listener registered on it, so to avoid leaks remember to use
 * {@link PeerGroup#removeWallet(Wallet)} on it if you wish to keep the Wallet but lose the PeerGroup.</p>
 */
public void addWallet(Wallet wallet) {
    lock.lock();
    try {
        checkNotNull(wallet);
        checkState(!wallets.contains(wallet));
        wallets.add(wallet);
        wallet.setTransactionBroadcaster(this);
        wallet.addCoinsReceivedEventListener(Threading.SAME_THREAD, walletCoinsReceivedEventListener);
        wallet.addKeyChainEventListener(Threading.SAME_THREAD, walletKeyEventListener);
        wallet.addScriptChangeEventListener(Threading.SAME_THREAD, walletScriptEventListener);
        addPeerFilterProvider(wallet);
        for (Peer peer : peers) {
            peer.addWallet(wallet);
        }
    } finally {
        lock.unlock();
    }
}
 
Example 3
Source File: PeerGroup.java    From GreenBits with GNU General Public License v3.0 6 votes vote down vote up
/**
 * <p>Link the given wallet to this PeerGroup. This is used for three purposes:</p>
 *
 * <ol>
 *   <li>So the wallet receives broadcast transactions.</li>
 *   <li>Announcing pending transactions that didn't get into the chain yet to our peers.</li>
 *   <li>Set the fast catchup time using {@link PeerGroup#setFastCatchupTimeSecs(long)}, to optimize chain
 *       download.</li>
 * </ol>
 *
 * <p>Note that this should be done before chain download commences because if you add a wallet with keys earlier
 * than the current chain head, the relevant parts of the chain won't be redownloaded for you.</p>
 *
 * <p>The Wallet will have an event listener registered on it, so to avoid leaks remember to use
 * {@link PeerGroup#removeWallet(Wallet)} on it if you wish to keep the Wallet but lose the PeerGroup.</p>
 */
public void addWallet(Wallet wallet) {
    lock.lock();
    try {
        checkNotNull(wallet);
        checkState(!wallets.contains(wallet));
        wallets.add(wallet);
        wallet.setTransactionBroadcaster(this);
        wallet.addCoinsReceivedEventListener(Threading.SAME_THREAD, walletCoinsReceivedEventListener);
        wallet.addKeyChainEventListener(Threading.SAME_THREAD, walletKeyEventListener);
        wallet.addScriptChangeEventListener(Threading.SAME_THREAD, walletScriptEventListener);
        addPeerFilterProvider(wallet);
        for (Peer peer : peers) {
            peer.addWallet(wallet);
        }
    } finally {
        lock.unlock();
    }
}
 
Example 4
Source File: PeerGroup.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Unlinks the given wallet so it no longer receives broadcast transactions or has its transactions announced.
 */
public void removeWallet(Wallet wallet) {
    wallets.remove(checkNotNull(wallet));
    peerFilterProviders.remove(wallet);
    wallet.removeCoinsReceivedEventListener(walletCoinsReceivedEventListener);
    wallet.removeKeyChainEventListener(walletKeyEventListener);
    wallet.removeScriptChangeEventListener(walletScriptEventListener);
    wallet.setTransactionBroadcaster(null);
    for (Peer peer : peers) {
        peer.removeWallet(wallet);
    }
}
 
Example 5
Source File: MockTransactionBroadcaster.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets this mock broadcaster on the given wallet.
 */
public MockTransactionBroadcaster(Wallet wallet) {
    // This code achieves nothing directly, but it sets up the broadcaster/peergroup > wallet lock ordering
    // so inversions can be caught.
    lock.lock();
    try {
        this.wallet = wallet;
        wallet.setTransactionBroadcaster(this);
        wallet.getPendingTransactions();
    } finally {
        lock.unlock();
    }
}
 
Example 6
Source File: PeerGroup.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Unlinks the given wallet so it no longer receives broadcast transactions or has its transactions announced.
 */
public void removeWallet(Wallet wallet) {
    wallets.remove(checkNotNull(wallet));
    peerFilterProviders.remove(wallet);
    wallet.removeCoinsReceivedEventListener(walletCoinsReceivedEventListener);
    wallet.removeKeyChainEventListener(walletKeyEventListener);
    wallet.removeScriptChangeEventListener(walletScriptEventListener);
    wallet.setTransactionBroadcaster(null);
    for (Peer peer : peers) {
        peer.removeWallet(wallet);
    }        
}
 
Example 7
Source File: MockTransactionBroadcaster.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
/** Sets this mock broadcaster on the given wallet. */
public MockTransactionBroadcaster(Wallet wallet) {
    // This code achieves nothing directly, but it sets up the broadcaster/peergroup > wallet lock ordering
    // so inversions can be caught.
    lock.lock();
    try {
        this.wallet = wallet;
        wallet.setTransactionBroadcaster(this);
        wallet.getPendingTransactions();
    } finally {
        lock.unlock();
    }
}
 
Example 8
Source File: PeerGroup.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Unlinks the given wallet so it no longer receives broadcast transactions or has its transactions announced.
 */
public void removeWallet(Wallet wallet) {
    wallets.remove(checkNotNull(wallet));
    peerFilterProviders.remove(wallet);
    wallet.removeCoinsReceivedEventListener(walletCoinsReceivedEventListener);
    wallet.removeKeyChainEventListener(walletKeyEventListener);
    wallet.removeScriptChangeEventListener(walletScriptEventListener);
    wallet.setTransactionBroadcaster(null);
    for (Peer peer : peers) {
        peer.removeWallet(wallet);
    }        
}
 
Example 9
Source File: MockTransactionBroadcaster.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
/** Sets this mock broadcaster on the given wallet. */
public MockTransactionBroadcaster(Wallet wallet) {
    // This code achieves nothing directly, but it sets up the broadcaster/peergroup > wallet lock ordering
    // so inversions can be caught.
    lock.lock();
    try {
        this.wallet = wallet;
        wallet.setTransactionBroadcaster(this);
        wallet.getPendingTransactions();
    } finally {
        lock.unlock();
    }
}