org.bitcoinj.wallet.listeners.AbstractKeyChainEventListener Java Examples
The following examples show how to use
org.bitcoinj.wallet.listeners.AbstractKeyChainEventListener.
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: DeterministicKeyChainTest.java From bcm-android with GNU General Public License v3.0 | 5 votes |
@Test public void events() throws Exception { // Check that we get the right events at the right time. final List<List<ECKey>> listenerKeys = Lists.newArrayList(); long secs = 1389353062L; chain = new DeterministicKeyChain(ENTROPY, "", secs); chain.addEventListener(new AbstractKeyChainEventListener() { @Override public void onKeysAdded(List<ECKey> keys) { listenerKeys.add(keys); } }, Threading.SAME_THREAD); assertEquals(0, listenerKeys.size()); chain.setLookaheadSize(5); assertEquals(0, listenerKeys.size()); ECKey key = chain.getKey(KeyChain.KeyPurpose.CHANGE); assertEquals(1, listenerKeys.size()); // 1 event final List<ECKey> firstEvent = listenerKeys.get(0); assertEquals(1, firstEvent.size()); assertTrue(firstEvent.contains(key)); // order is not specified. listenerKeys.clear(); chain.maybeLookAhead(); final List<ECKey> secondEvent = listenerKeys.get(0); assertEquals(12, secondEvent.size()); // (5 lookahead keys, +1 lookahead threshold) * 2 chains listenerKeys.clear(); chain.getKey(KeyChain.KeyPurpose.CHANGE); // At this point we've entered the threshold zone so more keys won't immediately trigger more generations. assertEquals(0, listenerKeys.size()); // 1 event final int lookaheadThreshold = chain.getLookaheadThreshold() + chain.getLookaheadSize(); for (int i = 0; i < lookaheadThreshold; i++) chain.getKey(KeyChain.KeyPurpose.CHANGE); assertEquals(1, listenerKeys.size()); // 1 event assertEquals(1, listenerKeys.get(0).size()); // 1 key. }
Example #2
Source File: BasicKeyChainTest.java From bcm-android with GNU General Public License v3.0 | 5 votes |
@Before public void setup() { chain = new BasicKeyChain(); onKeysAdded = new AtomicReference<>(); onKeysAddedRan = new AtomicBoolean(); chain.addEventListener(new AbstractKeyChainEventListener() { @Override public void onKeysAdded(List<ECKey> keys2) { onKeysAdded.set(keys2); onKeysAddedRan.set(true); } }, Threading.SAME_THREAD); }
Example #3
Source File: DeterministicKeyChainTest.java From green_android with GNU General Public License v3.0 | 5 votes |
@Test public void events() throws Exception { // Check that we get the right events at the right time. final List<List<ECKey>> listenerKeys = Lists.newArrayList(); long secs = 1389353062L; chain = new DeterministicKeyChain(ENTROPY, "", secs); chain.addEventListener(new AbstractKeyChainEventListener() { @Override public void onKeysAdded(List<ECKey> keys) { listenerKeys.add(keys); } }, Threading.SAME_THREAD); assertEquals(0, listenerKeys.size()); chain.setLookaheadSize(5); assertEquals(0, listenerKeys.size()); ECKey key = chain.getKey(KeyChain.KeyPurpose.CHANGE); assertEquals(1, listenerKeys.size()); // 1 event final List<ECKey> firstEvent = listenerKeys.get(0); assertEquals(1, firstEvent.size()); assertTrue(firstEvent.contains(key)); // order is not specified. listenerKeys.clear(); chain.maybeLookAhead(); final List<ECKey> secondEvent = listenerKeys.get(0); assertEquals(12, secondEvent.size()); // (5 lookahead keys, +1 lookahead threshold) * 2 chains listenerKeys.clear(); chain.getKey(KeyChain.KeyPurpose.CHANGE); // At this point we've entered the threshold zone so more keys won't immediately trigger more generations. assertEquals(0, listenerKeys.size()); // 1 event final int lookaheadThreshold = chain.getLookaheadThreshold() + chain.getLookaheadSize(); for (int i = 0; i < lookaheadThreshold; i++) chain.getKey(KeyChain.KeyPurpose.CHANGE); assertEquals(1, listenerKeys.size()); // 1 event assertEquals(1, listenerKeys.get(0).size()); // 1 key. }
Example #4
Source File: BasicKeyChainTest.java From green_android with GNU General Public License v3.0 | 5 votes |
@Before public void setup() { chain = new BasicKeyChain(); onKeysAdded = new AtomicReference<>(); onKeysAddedRan = new AtomicBoolean(); chain.addEventListener(new AbstractKeyChainEventListener() { @Override public void onKeysAdded(List<ECKey> keys2) { onKeysAdded.set(keys2); onKeysAddedRan.set(true); } }, Threading.SAME_THREAD); }
Example #5
Source File: DeterministicKeyChainTest.java From GreenBits with GNU General Public License v3.0 | 5 votes |
@Test public void events() throws Exception { // Check that we get the right events at the right time. final List<List<ECKey>> listenerKeys = Lists.newArrayList(); long secs = 1389353062L; chain = new DeterministicKeyChain(ENTROPY, "", secs); chain.addEventListener(new AbstractKeyChainEventListener() { @Override public void onKeysAdded(List<ECKey> keys) { listenerKeys.add(keys); } }, Threading.SAME_THREAD); assertEquals(0, listenerKeys.size()); chain.setLookaheadSize(5); assertEquals(0, listenerKeys.size()); ECKey key = chain.getKey(KeyChain.KeyPurpose.CHANGE); assertEquals(1, listenerKeys.size()); // 1 event final List<ECKey> firstEvent = listenerKeys.get(0); assertEquals(1, firstEvent.size()); assertTrue(firstEvent.contains(key)); // order is not specified. listenerKeys.clear(); chain.maybeLookAhead(); final List<ECKey> secondEvent = listenerKeys.get(0); assertEquals(12, secondEvent.size()); // (5 lookahead keys, +1 lookahead threshold) * 2 chains listenerKeys.clear(); chain.getKey(KeyChain.KeyPurpose.CHANGE); // At this point we've entered the threshold zone so more keys won't immediately trigger more generations. assertEquals(0, listenerKeys.size()); // 1 event final int lookaheadThreshold = chain.getLookaheadThreshold() + chain.getLookaheadSize(); for (int i = 0; i < lookaheadThreshold; i++) chain.getKey(KeyChain.KeyPurpose.CHANGE); assertEquals(1, listenerKeys.size()); // 1 event assertEquals(1, listenerKeys.get(0).size()); // 1 key. }
Example #6
Source File: BasicKeyChainTest.java From GreenBits with GNU General Public License v3.0 | 5 votes |
@Before public void setup() { chain = new BasicKeyChain(); onKeysAdded = new AtomicReference<>(); onKeysAddedRan = new AtomicBoolean(); chain.addEventListener(new AbstractKeyChainEventListener() { @Override public void onKeysAdded(List<ECKey> keys2) { onKeysAdded.set(keys2); onKeysAddedRan.set(true); } }, Threading.SAME_THREAD); }