private void resetBlockStore() { blockStore = new MemoryBlockStore(PARAMS); }
public MemoryBlockStore(NetworkParameters params) { // Insert the genesis block. try { Block genesisHeader = params.getGenesisBlock().cloneAsHeader(); StoredBlock storedGenesis = new StoredBlock(genesisHeader, genesisHeader.getWork(), 0); put(storedGenesis); setChainHead(storedGenesis); this.params = params; } catch (BlockStoreException e) { throw new RuntimeException(e); // Cannot happen. } catch (VerificationException e) { throw new RuntimeException(e); // Cannot happen. } }
@Before public void setUp() throws Exception { context = new Context(PARAMS); MemoryBlockStore store = new MemoryBlockStore(PARAMS); // Cheat and place the previous block (block 100000) at the head of the block store without supporting blocks store.put(new StoredBlock(new Block(PARAMS, HEX.decode("0100000050120119172a610421a6c3011dd330d9df07b63616c2cc1f1cd00200000000006657a9252aacd5c0b2940996ecff952228c3067cc38d4885efb5a4ac4247e9f337221b4d4c86041b0f2b5710")), BigInteger.valueOf(1), 100000)); store.setChainHead(store.get(Sha256Hash.wrap("000000000003ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506"))); KeyChainGroup group = new KeyChainGroup(PARAMS); group.importKeys(ECKey.fromPublicOnly(HEX.decode("04b27f7e9475ccf5d9a431cb86d665b8302c140144ec2397fce792f4a4e7765fecf8128534eaa71df04f93c74676ae8279195128a1506ebf7379d23dab8fca0f63")), ECKey.fromPublicOnly(HEX.decode("04732012cb962afa90d31b25d8fb0e32c94e513ab7a17805c14ca4c3423e18b4fb5d0e676841733cb83abaf975845c9f6f2a8097b7d04f4908b18368d6fc2d68ec")), ECKey.fromPublicOnly(HEX.decode("04cfb4113b3387637131ebec76871fd2760fc430dd16de0110f0eb07bb31ffac85e2607c189cb8582ea1ccaeb64ffd655409106589778f3000fdfe3263440b0350")), ECKey.fromPublicOnly(HEX.decode("04b2f30018908a59e829c1534bfa5010d7ef7f79994159bba0f534d863ef9e4e973af6a8de20dc41dbea50bc622263ec8a770b2c9406599d39e4c9afe61f8b1613"))); wallet = new Wallet(PARAMS, group); super.setUp(store); }
private void resetBlockStore() { blockStore = new MemoryBlockStore(PARAMS); }
public MemoryBlockStore(NetworkParameters params) { // Insert the genesis block. try { Block genesisHeader = params.getGenesisBlock().cloneAsHeader(); StoredBlock storedGenesis = new StoredBlock(genesisHeader, genesisHeader.getWork(), 0); put(storedGenesis); setChainHead(storedGenesis); this.params = params; } catch (BlockStoreException e) { throw new RuntimeException(e); // Cannot happen. } catch (VerificationException e) { throw new RuntimeException(e); // Cannot happen. } }
@Override public void setUp() throws Exception { setUp(new MemoryBlockStore(PARAMS)); }
public MemoryBlockStore(NetworkParameters params) { // Insert the genesis block. try { Block genesisHeader = params.getGenesisBlock().cloneAsHeader(); StoredBlock storedGenesis = new StoredBlock(genesisHeader, genesisHeader.getWork(), 0); put(storedGenesis); setChainHead(storedGenesis); this.params = params; } catch (BlockStoreException e) { throw new RuntimeException(e); // Cannot happen. } catch (VerificationException e) { throw new RuntimeException(e); // Cannot happen. } }
} else if (args[1].equals("Mem")) { Preconditions.checkArgument(args.length == 2); store = new MemoryBlockStore(params); } else if (args[1].equals("SPV")) { Preconditions.checkArgument(args.length == 3);
public MemoryBlockStore(NetworkParameters params) { // Insert the genesis block. try { Block genesisHeader = params.getGenesisBlock().cloneAsHeader(); StoredBlock storedGenesis = new StoredBlock(genesisHeader, genesisHeader.getWork(), 0); put(storedGenesis); setChainHead(storedGenesis); this.params = params; } catch (BlockStoreException e) { throw new RuntimeException(e); // Cannot happen. } catch (VerificationException e) { throw new RuntimeException(e); // Cannot happen. } }
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(InetAddress.getLocalHost(), params.getPort())); 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(); } }
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(InetAddress.getLocalHost(), params.getPort()); 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(); } }
public void setUp() throws Exception { setUp(new MemoryBlockStore(UnitTestParams.get())); }
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()); } }
@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); }
final BlockStore store = new MemoryBlockStore(PARAMS); final BlockChain chain = new BlockChain(PARAMS, store); final PeerGroup peerGroup = new PeerGroup(PARAMS, chain);
final MemoryBlockStore blockStore = new MemoryBlockStore(params); BlockChain chain = new BlockChain(params, wallet, blockStore);
final BlockStore store = new MemoryBlockStore(params); final BlockChain chain = new BlockChain(params, store); final PeerGroup peerGroup = new PeerGroup(params, chain);
public void init () { synchronized (initialized) { if (!initialized) { try { blockStore = new SPVBlockStore(Constants.getNetwork(), new File("blockheaders")); } catch (Exception e) { blockStore = new MemoryBlockStore(Constants.getNetwork()); } try { blockChain = new BlockChain(Constants.getNetwork(), blockStore); peerGroup = new PeerGroup(Constants.getNetwork(), blockChain); peerGroup.addPeerDiscovery(new DnsDiscovery(Constants.getNetwork())); peerGroup.setDownloadTxDependencies(false); peerGroup.setBloomFilteringEnabled(false); peerGroup.setFastCatchupTimeSecs(System.currentTimeMillis()); peerGroup.start(); peerGroup.addEventListener(new EventListener(), Threading.SAME_THREAD); registerShutdownHook(); final DownloadProgressTracker listener = new DownloadProgressTracker(); peerGroup.startBlockChainDownload(listener); } catch (Exception e) { throw new RuntimeException(e); } initialized = true; } } }
private void createMarriedWallet(int threshold, int numKeys, boolean addSigners) throws BlockStoreException { wallet = new Wallet(PARAMS); blockStore = new MemoryBlockStore(PARAMS); chain = new BlockChain(PARAMS, wallet, blockStore); List<DeterministicKey> followingKeys = Lists.newArrayList(); for (int i = 0; i < numKeys - 1; i++) { final DeterministicKeyChain keyChain = new DeterministicKeyChain(new SecureRandom()); DeterministicKey partnerKey = DeterministicKey.deserializeB58(null, keyChain.getWatchingKey().serializePubB58(PARAMS), PARAMS); followingKeys.add(partnerKey); if (addSigners && i < threshold - 1) wallet.addTransactionSigner(new KeyChainTransactionSigner(keyChain)); } MarriedKeyChain chain = MarriedKeyChain.builder() .random(new SecureRandom()) .followingKeys(followingKeys) .threshold(threshold).build(); wallet.addAndActivateHDChain(chain); }
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); }