@Override public void run() { try { Context.propagate(context); r.run(); } catch (Exception e) { log.error("Exception in thread", e); Throwables.propagate(e); } } }, name);
@Override public void run() { try { Context.propagate(context); r.run(); } catch (Exception e) { log.error("Exception in thread", e); Throwables.propagate(e); } } }, name);
@Override public void run() { try { Context.propagate(context); r.run(); } catch (Exception e) { log.error("Exception in thread", e); Throwables.propagate(e); } } }, name);
@Override public void run() { try { Context.propagate(context); r.run(); } catch (Exception e) { log.error("Exception in thread", e); Throwables.propagate(e); } } }, name);
@Override public void run() { Context.propagate(context); if (clientSet != null) clientSet.add(BlockingClient.this); try { socket.connect(serverAddress, connectTimeoutMillis); connection.connectionOpened(); connectFuture.set(serverAddress); InputStream stream = socket.getInputStream(); runReadLoop(stream, connection); } catch (Exception e) { if (!vCloseRequested) { log.error("Error trying to open/read from connection: {}: {}", serverAddress, e.getMessage()); connectFuture.setException(e); } } finally { try { socket.close(); } catch (IOException e1) { // At this point there isn't much we can do, and we can probably assume the channel is closed } if (clientSet != null) clientSet.remove(BlockingClient.this); connection.connectionClosed(); } } };
@Override public void run() { Context.propagate(context); if (clientSet != null) clientSet.add(BlockingClient.this); try { socket.connect(serverAddress, connectTimeoutMillis); connection.connectionOpened(); connectFuture.set(serverAddress); InputStream stream = socket.getInputStream(); runReadLoop(stream, connection); } catch (Exception e) { if (!vCloseRequested) { log.error("Error trying to open/read from connection: {}: {}", serverAddress, e.getMessage()); connectFuture.setException(e); } } finally { try { socket.close(); } catch (IOException e1) { // At this point there isn't much we can do, and we can probably assume the channel is closed } if (clientSet != null) clientSet.remove(BlockingClient.this); connection.connectionClosed(); } } };
@Override public void run() { Context.propagate(context); if (clientSet != null) clientSet.add(BlockingClient.this); try { socket.connect(serverAddress, connectTimeoutMillis); connection.connectionOpened(); connectFuture.set(serverAddress); InputStream stream = socket.getInputStream(); runReadLoop(stream, connection); } catch (Exception e) { if (!vCloseRequested) { log.error("Error trying to open/read from connection: {}: {}", serverAddress, e.getMessage()); connectFuture.setException(e); } } finally { try { socket.close(); } catch (IOException e1) { // At this point there isn't much we can do, and we can probably assume the channel is closed } if (clientSet != null) clientSet.remove(BlockingClient.this); connection.connectionClosed(); } } };
@Override public void run() { Context.propagate(context); if (clientSet != null) clientSet.add(BlockingClient.this); try { socket.connect(serverAddress, connectTimeoutMillis); connection.connectionOpened(); connectFuture.set(serverAddress); InputStream stream = socket.getInputStream(); runReadLoop(stream, connection); } catch (Exception e) { if (!vCloseRequested) { log.error("Error trying to open/read from connection: {}: {}", serverAddress, e.getMessage()); connectFuture.setException(e); } } finally { try { socket.close(); } catch (IOException e1) { // At this point there isn't much we can do, and we can probably assume the channel is closed } if (clientSet != null) clientSet.remove(BlockingClient.this); connection.connectionClosed(); } } };
@Override protected void shutDown() throws Exception { // Runs in a separate thread. try { Context.propagate(context); vPeerGroup.stop(); vWallet.saveToFile(vWalletFile); vStore.close(); vPeerGroup = null; vWallet = null; vStore = null; vChain = null; } catch (BlockStoreException e) { throw new IOException(e); } }
@Override protected void shutDown() throws Exception { // Runs in a separate thread. try { Context.propagate(context); vPeerGroup.stop(); vWallet.saveToFile(vWalletFile); vStore.close(); vPeerGroup = null; vWallet = null; vStore = null; vChain = null; } catch (BlockStoreException e) { throw new IOException(e); } }
@Override protected void shutDown() throws Exception { // Runs in a separate thread. try { Context.propagate(context); vPeerGroup.stop(); vWallet.saveToFile(vWalletFile); vStore.close(); vPeerGroup = null; vWallet = null; vStore = null; vChain = null; } catch (BlockStoreException e) { throw new IOException(e); } }
@Override protected void shutDown() throws Exception { // Runs in a separate thread. try { Context.propagate(context); vPeerGroup.stop(); vWallet.saveToFile(vWalletFile); vStore.close(); vPeerGroup = null; vWallet = null; vStore = null; vChain = null; } catch (BlockStoreException e) { throw new IOException(e); } }
/** * Adds a listener to the bitcoinj wallet which processes incoming * transactions directed to the wallet's addresses. * It is assumed that old transactions which are already in blocks are also * handed to the listener when starting up the monitor application. * * @see <a href="https://groups.google.com/d/msg/bitcoinj/bYcUTimAz9w/jwS_7gOsCwAJ">google groups bitcoinj answer</a> */ private void addCoinsReceivedListener() { // The provided listener is only called once per transaction, e.g. when // the transaction is first seen on the network. It will not be called // again for the same transaction when it is added to a block. wallet.addCoinsReceivedEventListener((wallet_, bitcoinjTx, prevBalance, newBalance) -> { Context.propagate(this.bitcoinContext); bitcoinjTx.getOutputs().stream() .filter(utxo -> utxo.getScriptPubKey().isSentToAddress()) .map(utxo -> new BitcoinTransactionAdapter( utxo, bitcoinNetworkParameters, bitcoinBlockStore, investorService)) .forEach(tx -> { try { processDependingOnStatus(tx); } catch (Throwable t) { LOG.error("Error while processing transaction.", t); } }); }); }
@Before public void setUp() throws Exception { BriefLogFormatter.init(); Context.propagate(new Context(PARAMS, 100, Coin.ZERO, false)); }
public void setUp() throws Exception { BriefLogFormatter.init(); Context.propagate(new Context(PARAMS, 100, Coin.ZERO, false)); wallet = new Wallet(PARAMS); myKey = wallet.currentReceiveKey(); myAddress = myKey.toAddress(PARAMS); blockStore = new MemoryBlockStore(PARAMS); chain = new BlockChain(PARAMS, wallet, blockStore); }
public void setUp(BlockStore blockStore) throws Exception { BriefLogFormatter.init(); Context.propagate(new Context(PARAMS, 100, Coin.ZERO, false)); this.blockStore = blockStore; // Allow subclasses to override the wallet object with their own. if (wallet == null) { wallet = new Wallet(PARAMS); key = wallet.freshReceiveKey(); address = key.toAddress(PARAMS); } blockChain = new BlockChain(PARAMS, wallet, blockStore); startPeerServers(); if (clientType == ClientType.NIO_CLIENT_MANAGER || clientType == ClientType.BLOCKING_CLIENT_MANAGER) { channels.startAsync(); channels.awaitRunning(); } socketAddress = new InetSocketAddress("127.0.0.1", 1111); }
@Test public void walletTest() throws Exception { NetworkParameters params = MainNetParams.get(); Context.propagate(new Context(params)); DumpedPrivateKey privKey = DumpedPrivateKey.fromBase58(params, "5Kg1gnAjaLfKiwhhPpGS3QfRg2m6awQvaj98JCZBZQ5SuS2F15C"); Address addr = privKey.getKey().toAddress(params); assertTrue(addr.toString().equals("17Wx1GQfyPTNWpQMHrTwRSMTCAonSiZx9e")); KeyChainGroup group = new KeyChainGroup(params); // Add a random key which happens to have been used in a recent generation group.importKeys(ECKey.fromPublicOnly(privKey.getKey().getPubKeyPoint()), ECKey.fromPublicOnly(HEX.decode("03cb219f69f1b49468bd563239a86667e74a06fcba69ac50a08a5cbc42a5808e99"))); Wallet wallet = new Wallet(params, group); wallet.commitTx(new Transaction(params, HEX.decode("01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0d038754030114062f503253482fffffffff01c05e559500000000232103cb219f69f1b49468bd563239a86667e74a06fcba69ac50a08a5cbc42a5808e99ac00000000"))); // We should have 2 per pubkey, and one for the pay-2-pubkey output we have assertEquals(5, wallet.getBloomFilterElementCount()); BloomFilter filter = wallet.getBloomFilter(wallet.getBloomFilterElementCount(), 0.001, 0); // Value generated by Bitcoin Core assertTrue(Arrays.equals(HEX.decode("082ae5edc8e51d4a03080000000000000002"), filter.unsafeBitcoinSerialize())); } }
@Before public void setUp() throws Exception { BriefLogFormatter.initVerbose(); Context.propagate(new Context(testNet, 100, Coin.ZERO, false)); testNetChain = new BlockChain(testNet, new Wallet(testNet), new MemoryBlockStore(testNet)); Context.propagate(new Context(PARAMS, 100, Coin.ZERO, false)); wallet = new Wallet(PARAMS) { @Override public void receiveFromBlock(Transaction tx, StoredBlock block, BlockChain.NewBlockType blockType, int relativityOffset) throws VerificationException { super.receiveFromBlock(tx, block, blockType, relativityOffset); BlockChainTest.this.block[0] = block; if (isTransactionRelevant(tx) && tx.isCoinBase()) { BlockChainTest.this.coinbaseTransaction = tx; } } }; wallet.freshReceiveKey(); resetBlockStore(); chain = new BlockChain(PARAMS, wallet, blockStore); coinbaseTo = wallet.currentReceiveKey().toAddress(PARAMS); }
@Override @Before public void setUp() throws Exception { Utils.setMockClock(); // Use mock clock super.setUp(); Context.propagate(new Context(PARAMS, 100, Coin.ZERO, false)); wallet.addExtension(new StoredPaymentChannelClientStates(wallet, new TransactionBroadcaster() { @Override public TransactionBroadcast broadcastTransaction(Transaction tx) { fail(); return null; } })); sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, COIN); chain = new BlockChain(PARAMS, wallet, blockStore); // Recreate chain as sendMoneyToWallet will confuse it serverWallet = new Wallet(PARAMS); serverKey = serverWallet.freshReceiveKey(); chain.addWallet(serverWallet); broadcasts = new LinkedBlockingQueue<>(); mockBroadcaster = new TransactionBroadcaster() { @Override public TransactionBroadcast broadcastTransaction(Transaction tx) { SettableFuture<Transaction> future = SettableFuture.create(); broadcasts.add(new TxFuturePair(tx, future)); return TransactionBroadcast.createMockBroadcast(tx, future); } }; }
@Before public void setUp() throws Exception { BriefLogFormatter.init(); Utils.setMockClock(); // Use mock clock Context.propagate(new Context(PARAMS, 100, Coin.ZERO, false)); MemoryBlockStore blockStore = new MemoryBlockStore(PARAMS); wallet = new Wallet(PARAMS); ECKey key1 = wallet.freshReceiveKey(); ECKey key2 = wallet.freshReceiveKey(); chain = new BlockChain(PARAMS, wallet, blockStore); coinsTo = key1.toAddress(PARAMS); coinsTo2 = key2.toAddress(PARAMS); someOtherGuy = new ECKey().toAddress(PARAMS); }