/* * Copyright 2011 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.devcoin.examples; import com.google.devcoin.core.*; import com.google.devcoin.params.MainNetParams; import com.google.devcoin.store.BlockStore; import com.google.devcoin.store.MemoryBlockStore; import com.google.devcoin.utils.BriefLogFormatter; import java.net.InetAddress; import java.util.concurrent.Future; /** * Downloads the block given a block hash from the localhost node and prints it out. */ public class FetchBlock { public static void main(String[] args) throws Exception { BriefLogFormatter.init(); System.out.println("Connecting to node"); final NetworkParameters params = MainNetParams.get(); BlockStore blockStore = new MemoryBlockStore(params); BlockChain chain = new BlockChain(params, blockStore); PeerGroup peerGroup = new PeerGroup(params, chain); peerGroup.startAndWait(); PeerAddress addr = new PeerAddress(InetAddress.getLocalHost(), params.getPort()); peerGroup.addAddress(addr); peerGroup.waitForPeers(1).get(); Peer peer = peerGroup.getConnectedPeers().get(0); // Sha256Hash blockHash = new Sha256Hash("000000000003d9812c612985455e73501999127c324e128ef72e6ad5b931a63c");//24999 Sha256Hash blockHash = new Sha256Hash("f4663ea84b99f9d35c6d9e982733eebf2e33305cc1bf3691f649745dc1fb3e58");//25000 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.stop(); } }