org.bitcoinj.store.MemoryBlockStore Java Examples
The following examples show how to use
org.bitcoinj.store.MemoryBlockStore.
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: VersionTallyTest.java From GreenBits with GNU General Public License v3.0 | 6 votes |
@Test public void testInitialize() throws BlockStoreException { final BlockStore blockStore = new MemoryBlockStore(PARAMS); final BlockChain chain = new BlockChain(PARAMS, blockStore); // Build a historical chain of version 2 blocks long timeSeconds = 1231006505; StoredBlock chainHead = null; for (int height = 0; height < PARAMS.getMajorityWindow(); height++) { chainHead = FakeTxBuilder.createFakeBlock(blockStore, 2, timeSeconds, height).storedBlock; assertEquals(2, chainHead.getHeader().getVersion()); timeSeconds += 60; } VersionTally instance = new VersionTally(PARAMS); instance.initialize(blockStore, chainHead); assertEquals(PARAMS.getMajorityWindow(), instance.getCountAtOrAbove(2).intValue()); }
Example #2
Source File: BlockChainTest.java From green_android with GNU General Public License v3.0 | 6 votes |
@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); }
Example #3
Source File: VersionTallyTest.java From green_android with GNU General Public License v3.0 | 6 votes |
@Test public void testInitialize() throws BlockStoreException { final BlockStore blockStore = new MemoryBlockStore(PARAMS); final BlockChain chain = new BlockChain(PARAMS, blockStore); // Build a historical chain of version 2 blocks long timeSeconds = 1231006505; StoredBlock chainHead = null; for (int height = 0; height < PARAMS.getMajorityWindow(); height++) { chainHead = FakeTxBuilder.createFakeBlock(blockStore, 2, timeSeconds, height).storedBlock; assertEquals(2, chainHead.getHeader().getVersion()); timeSeconds += 60; } VersionTally instance = new VersionTally(PARAMS); instance.initialize(blockStore, chainHead); assertEquals(PARAMS.getMajorityWindow(), instance.getCountAtOrAbove(2).intValue()); }
Example #4
Source File: FetchBlock.java From green_android with GNU General Public License v3.0 | 6 votes |
public static void main(String[] args) throws Exception { BriefLogFormatter.init(); System.out.println("Connecting to node"); final NetworkParameters params = TestNet3Params.get(); BlockStore blockStore = new MemoryBlockStore(params); BlockChain chain = new BlockChain(params, blockStore); PeerGroup peerGroup = new PeerGroup(params, chain); peerGroup.start(); PeerAddress addr = new PeerAddress(params, InetAddress.getLocalHost()); peerGroup.addAddress(addr); peerGroup.waitForPeers(1).get(); Peer peer = peerGroup.getConnectedPeers().get(0); Sha256Hash blockHash = Sha256Hash.wrap(args[0]); Future<Block> future = peer.getBlock(blockHash); System.out.println("Waiting for node to send us the requested block: " + blockHash); Block block = future.get(); System.out.println(block); peerGroup.stopAsync(); }
Example #5
Source File: FetchBlock.java From GreenBits with GNU General Public License v3.0 | 6 votes |
public static void main(String[] args) throws Exception { BriefLogFormatter.init(); System.out.println("Connecting to node"); final NetworkParameters params = TestNet3Params.get(); BlockStore blockStore = new MemoryBlockStore(params); BlockChain chain = new BlockChain(params, blockStore); PeerGroup peerGroup = new PeerGroup(params, chain); peerGroup.start(); PeerAddress addr = new PeerAddress(params, InetAddress.getLocalHost()); peerGroup.addAddress(addr); peerGroup.waitForPeers(1).get(); Peer peer = peerGroup.getConnectedPeers().get(0); Sha256Hash blockHash = Sha256Hash.wrap(args[0]); Future<Block> future = peer.getBlock(blockHash); System.out.println("Waiting for node to send us the requested block: " + blockHash); Block block = future.get(); System.out.println(block); peerGroup.stopAsync(); }
Example #6
Source File: BlockChainTest.java From bcm-android with GNU General Public License v3.0 | 6 votes |
@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(UNITTEST, 100, Coin.ZERO, false)); wallet = new Wallet(UNITTEST) { @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(UNITTEST, wallet, blockStore); coinbaseTo = LegacyAddress.fromKey(UNITTEST, wallet.currentReceiveKey()); }
Example #7
Source File: BlockChainTest.java From GreenBits with GNU General Public License v3.0 | 6 votes |
@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); }
Example #8
Source File: VersionTallyTest.java From bcm-android with GNU General Public License v3.0 | 6 votes |
@Test public void testInitialize() throws BlockStoreException { final BlockStore blockStore = new MemoryBlockStore(UNITTEST); final BlockChain chain = new BlockChain(UNITTEST, blockStore); // Build a historical chain of version 2 blocks long timeSeconds = 1231006505; StoredBlock chainHead = null; for (int height = 0; height < UNITTEST.getMajorityWindow(); height++) { chainHead = FakeTxBuilder.createFakeBlock(blockStore, 2, timeSeconds, height).storedBlock; assertEquals(2, chainHead.getHeader().getVersion()); timeSeconds += 60; } VersionTally instance = new VersionTally(UNITTEST); instance.initialize(blockStore, chainHead); assertEquals(UNITTEST.getMajorityWindow(), instance.getCountAtOrAbove(2).intValue()); }
Example #9
Source File: ChainSplitTest.java From GreenBits with GNU General Public License v3.0 | 5 votes |
@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); }
Example #10
Source File: TestWithWallet.java From GreenBits with GNU General Public License v3.0 | 5 votes |
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); }
Example #11
Source File: TestWithWallet.java From bcm-android with GNU General Public License v3.0 | 5 votes |
public void setUp() throws Exception { BriefLogFormatter.init(); Context.propagate(new Context(UNITTEST, 100, Coin.ZERO, false)); wallet = new Wallet(UNITTEST); myKey = wallet.currentReceiveKey(); myAddress = LegacyAddress.fromKey(UNITTEST, myKey); blockStore = new MemoryBlockStore(UNITTEST); chain = new BlockChain(UNITTEST, wallet, blockStore); }
Example #12
Source File: FetchTransactions.java From GreenBits with GNU General Public License v3.0 | 5 votes |
public static void main(String[] args) throws Exception { BriefLogFormatter.init(); System.out.println("Connecting to node"); final NetworkParameters params = TestNet3Params.get(); BlockStore blockStore = new MemoryBlockStore(params); BlockChain chain = new BlockChain(params, blockStore); PeerGroup peerGroup = new PeerGroup(params, chain); peerGroup.start(); peerGroup.addAddress(new PeerAddress(params, InetAddress.getLocalHost())); peerGroup.waitForPeers(1).get(); Peer peer = peerGroup.getConnectedPeers().get(0); Sha256Hash txHash = Sha256Hash.wrap(args[0]); ListenableFuture<Transaction> future = peer.getPeerMempoolTransaction(txHash); System.out.println("Waiting for node to send us the requested transaction: " + txHash); Transaction tx = future.get(); System.out.println(tx); System.out.println("Waiting for node to send us the dependencies ..."); List<Transaction> deps = peer.downloadDependencies(tx).get(); for (Transaction dep : deps) { System.out.println("Got dependency " + dep.getHashAsString()); } System.out.println("Done."); peerGroup.stop(); }
Example #13
Source File: RefreshWallet.java From GreenBits with GNU General Public License v3.0 | 5 votes |
public static void main(String[] args) throws Exception { File file = new File(args[0]); Wallet wallet = Wallet.loadFromFile(file); System.out.println(wallet.toString()); // Set up the components and link them together. final NetworkParameters params = TestNet3Params.get(); BlockStore blockStore = new MemoryBlockStore(params); BlockChain chain = new BlockChain(params, wallet, blockStore); final PeerGroup peerGroup = new PeerGroup(params, chain); peerGroup.startAsync(); wallet.addCoinsReceivedEventListener(new WalletCoinsReceivedEventListener() { @Override public synchronized void onCoinsReceived(Wallet w, Transaction tx, Coin prevBalance, Coin newBalance) { System.out.println("\nReceived tx " + tx.getHashAsString()); System.out.println(tx.toString()); } }); // Now download and process the block chain. peerGroup.downloadBlockChain(); peerGroup.stopAsync(); wallet.saveToFile(file); System.out.println("\nDone!\n"); System.out.println(wallet.toString()); }
Example #14
Source File: BlockChainTest.java From GreenBits with GNU General Public License v3.0 | 5 votes |
private void testDeprecatedBlockVersion(final long deprecatedVersion, final long newVersion) throws Exception { final BlockStore versionBlockStore = new MemoryBlockStore(PARAMS); final BlockChain versionChain = new BlockChain(PARAMS, versionBlockStore); // Build a historical chain of version 3 blocks long timeSeconds = 1231006505; int height = 0; FakeTxBuilder.BlockPair chainHead = null; // Put in just enough v2 blocks to be a minority for (height = 0; height < (PARAMS.getMajorityWindow() - PARAMS.getMajorityRejectBlockOutdated()); height++) { chainHead = FakeTxBuilder.createFakeBlock(versionBlockStore, deprecatedVersion, timeSeconds, height); versionChain.add(chainHead.block); timeSeconds += 60; } // Fill the rest of the window with v3 blocks for (; height < PARAMS.getMajorityWindow(); height++) { chainHead = FakeTxBuilder.createFakeBlock(versionBlockStore, newVersion, timeSeconds, height); versionChain.add(chainHead.block); timeSeconds += 60; } chainHead = FakeTxBuilder.createFakeBlock(versionBlockStore, deprecatedVersion, timeSeconds, height); // Trying to add a new v2 block should result in rejection thrown.expect(VerificationException.BlockVersionOutOfDate.class); try { versionChain.add(chainHead.block); } catch(final VerificationException ex) { throw (Exception) ex.getCause(); } }
Example #15
Source File: BlockChainTest.java From GreenBits with GNU General Public License v3.0 | 5 votes |
@Test public void estimatedBlockTime() throws Exception { NetworkParameters params = MainNetParams.get(); BlockChain prod = new BlockChain(new Context(params), new MemoryBlockStore(params)); Date d = prod.estimateBlockTime(200000); // The actual date of block 200,000 was 2012-09-22 10:47:00 assertEquals(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US).parse("2012-10-23T08:35:05.000-0700"), d); }
Example #16
Source File: BlockChainTest.java From green_android with GNU General Public License v3.0 | 5 votes |
@Test public void estimatedBlockTime() throws Exception { NetworkParameters params = MainNetParams.get(); BlockChain prod = new BlockChain(new Context(params), new MemoryBlockStore(params)); Date d = prod.estimateBlockTime(200000); // The actual date of block 200,000 was 2012-09-22 10:47:00 assertEquals(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US).parse("2012-10-23T08:35:05.000-0700"), d); }
Example #17
Source File: BlockChainTest.java From green_android with GNU General Public License v3.0 | 5 votes |
private void testDeprecatedBlockVersion(final long deprecatedVersion, final long newVersion) throws Exception { final BlockStore versionBlockStore = new MemoryBlockStore(PARAMS); final BlockChain versionChain = new BlockChain(PARAMS, versionBlockStore); // Build a historical chain of version 3 blocks long timeSeconds = 1231006505; int height = 0; FakeTxBuilder.BlockPair chainHead = null; // Put in just enough v2 blocks to be a minority for (height = 0; height < (PARAMS.getMajorityWindow() - PARAMS.getMajorityRejectBlockOutdated()); height++) { chainHead = FakeTxBuilder.createFakeBlock(versionBlockStore, deprecatedVersion, timeSeconds, height); versionChain.add(chainHead.block); timeSeconds += 60; } // Fill the rest of the window with v3 blocks for (; height < PARAMS.getMajorityWindow(); height++) { chainHead = FakeTxBuilder.createFakeBlock(versionBlockStore, newVersion, timeSeconds, height); versionChain.add(chainHead.block); timeSeconds += 60; } chainHead = FakeTxBuilder.createFakeBlock(versionBlockStore, deprecatedVersion, timeSeconds, height); // Trying to add a new v2 block should result in rejection thrown.expect(VerificationException.BlockVersionOutOfDate.class); try { versionChain.add(chainHead.block); } catch(final VerificationException ex) { throw (Exception) ex.getCause(); } }
Example #18
Source File: ChainSplitTest.java From green_android with GNU General Public License v3.0 | 5 votes |
@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); }
Example #19
Source File: ChainSplitTest.java From bcm-android with GNU General Public License v3.0 | 5 votes |
@Before public void setUp() throws Exception { BriefLogFormatter.init(); Utils.setMockClock(); // Use mock clock Context.propagate(new Context(UNITTEST, 100, Coin.ZERO, false)); MemoryBlockStore blockStore = new MemoryBlockStore(UNITTEST); wallet = new Wallet(UNITTEST); ECKey key1 = wallet.freshReceiveKey(); ECKey key2 = wallet.freshReceiveKey(); chain = new BlockChain(UNITTEST, wallet, blockStore); coinsTo = LegacyAddress.fromKey(UNITTEST, key1); coinsTo2 = LegacyAddress.fromKey(UNITTEST, key2); someOtherGuy = LegacyAddress.fromKey(UNITTEST, new ECKey()); }
Example #20
Source File: TestWithWallet.java From green_android with GNU General Public License v3.0 | 5 votes |
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); }
Example #21
Source File: FetchTransactions.java From green_android with GNU General Public License v3.0 | 5 votes |
public static void main(String[] args) throws Exception { BriefLogFormatter.init(); System.out.println("Connecting to node"); final NetworkParameters params = TestNet3Params.get(); BlockStore blockStore = new MemoryBlockStore(params); BlockChain chain = new BlockChain(params, blockStore); PeerGroup peerGroup = new PeerGroup(params, chain); peerGroup.start(); peerGroup.addAddress(new PeerAddress(params, InetAddress.getLocalHost())); peerGroup.waitForPeers(1).get(); Peer peer = peerGroup.getConnectedPeers().get(0); Sha256Hash txHash = Sha256Hash.wrap(args[0]); ListenableFuture<Transaction> future = peer.getPeerMempoolTransaction(txHash); System.out.println("Waiting for node to send us the requested transaction: " + txHash); Transaction tx = future.get(); System.out.println(tx); System.out.println("Waiting for node to send us the dependencies ..."); List<Transaction> deps = peer.downloadDependencies(tx).get(); for (Transaction dep : deps) { System.out.println("Got dependency " + dep.getHashAsString()); } System.out.println("Done."); peerGroup.stop(); }
Example #22
Source File: RefreshWallet.java From green_android with GNU General Public License v3.0 | 5 votes |
public static void main(String[] args) throws Exception { File file = new File(args[0]); Wallet wallet = Wallet.loadFromFile(file); System.out.println(wallet.toString()); // Set up the components and link them together. final NetworkParameters params = TestNet3Params.get(); BlockStore blockStore = new MemoryBlockStore(params); BlockChain chain = new BlockChain(params, wallet, blockStore); final PeerGroup peerGroup = new PeerGroup(params, chain); peerGroup.startAsync(); wallet.addCoinsReceivedEventListener(new WalletCoinsReceivedEventListener() { @Override public synchronized void onCoinsReceived(Wallet w, Transaction tx, Coin prevBalance, Coin newBalance) { System.out.println("\nReceived tx " + tx.getHashAsString()); System.out.println(tx.toString()); } }); // Now download and process the block chain. peerGroup.downloadBlockChain(); peerGroup.stopAsync(); wallet.saveToFile(file); System.out.println("\nDone!\n"); System.out.println(wallet.toString()); }
Example #23
Source File: BlockChainTest.java From bcm-android with GNU General Public License v3.0 | 5 votes |
@Test public void estimatedBlockTime() throws Exception { BlockChain prod = new BlockChain(new Context(MAINNET), new MemoryBlockStore(MAINNET)); Date d = prod.estimateBlockTime(200000); // The actual date of block 200,000 was 2012-09-22 10:47:00 assertEquals(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US).parse("2012-10-23T08:35:05.000-0700"), d); }
Example #24
Source File: BlockChainTest.java From bcm-android with GNU General Public License v3.0 | 5 votes |
private void testDeprecatedBlockVersion(final long deprecatedVersion, final long newVersion) throws Exception { final BlockStore versionBlockStore = new MemoryBlockStore(UNITTEST); final BlockChain versionChain = new BlockChain(UNITTEST, versionBlockStore); // Build a historical chain of version 3 blocks long timeSeconds = 1231006505; int height = 0; FakeTxBuilder.BlockPair chainHead = null; // Put in just enough v2 blocks to be a minority for (height = 0; height < (UNITTEST.getMajorityWindow() - UNITTEST.getMajorityRejectBlockOutdated()); height++) { chainHead = FakeTxBuilder.createFakeBlock(versionBlockStore, deprecatedVersion, timeSeconds, height); versionChain.add(chainHead.block); timeSeconds += 60; } // Fill the rest of the window with v3 blocks for (; height < UNITTEST.getMajorityWindow(); height++) { chainHead = FakeTxBuilder.createFakeBlock(versionBlockStore, newVersion, timeSeconds, height); versionChain.add(chainHead.block); timeSeconds += 60; } chainHead = FakeTxBuilder.createFakeBlock(versionBlockStore, deprecatedVersion, timeSeconds, height); // Trying to add a new v2 block should result in rejection thrown.expect(VerificationException.BlockVersionOutOfDate.class); try { versionChain.add(chainHead.block); } catch (final VerificationException ex) { throw (Exception) ex.getCause(); } }
Example #25
Source File: TestWithNetworkConnections.java From bcm-android with GNU General Public License v3.0 | 4 votes |
public void setUp() throws Exception { setUp(new MemoryBlockStore(UNITTEST)); }
Example #26
Source File: ParseByteCacheTest.java From green_android with GNU General Public License v3.0 | 4 votes |
private void resetBlockStore() { blockStore = new MemoryBlockStore(PARAMS); }
Example #27
Source File: ParseByteCacheTest.java From bcm-android with GNU General Public License v3.0 | 4 votes |
private void resetBlockStore() { blockStore = new MemoryBlockStore(UNITTEST); }
Example #28
Source File: BlockChainTest.java From GreenBits with GNU General Public License v3.0 | 4 votes |
private void resetBlockStore() { blockStore = new MemoryBlockStore(PARAMS); }
Example #29
Source File: ParseByteCacheTest.java From GreenBits with GNU General Public License v3.0 | 4 votes |
private void resetBlockStore() { blockStore = new MemoryBlockStore(PARAMS); }
Example #30
Source File: BlockChainTest.java From bcm-android with GNU General Public License v3.0 | 4 votes |
private void resetBlockStore() { blockStore = new MemoryBlockStore(UNITTEST); }