@@ -0,0 +1,2856 @@
+/*%0A * Copyright 2011 Google Inc.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *    http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage com.google.bitcoin.examples;%0A%0Aimport com.google.bitcoin.core.*;%0A%0Aimport java.io.File;%0Aimport java.math.BigInteger;%0Aimport java.net.InetAddress;%0Aimport java.util.concurrent.CountDownLatch;%0Aimport java.util.concurrent.TimeUnit;%0A%0A/**%0A * RefreshWallet loads a wallet, then processes the block chain to update the transaction pools within it.%0A */%0Apublic class RefreshWallet %7B%0A    public static void main(String%5B%5D args) throws Exception %7B%0A        File file = new File(args%5B0%5D);%0A        Wallet wallet = Wallet.loadFromFile(file);%0A        System.out.println(wallet.toString());%0A%0A        // Set up the components and link them together.%0A        final NetworkParameters params = NetworkParameters.testNet();%0A        BlockStore blockStore = new MemoryBlockStore(params);%0A        NetworkConnection conn = new NetworkConnection(InetAddress.getLocalHost(), params,%0A                                                       blockStore.getChainHead().getHeight(), 60000);%0A        BlockChain chain = new BlockChain(params, wallet, blockStore);%0A        Peer peer = new Peer(params, conn, chain);%0A        peer.start();%0A%0A        wallet.addEventListener(new WalletEventListener() %7B%0A            public void onCoinsReceived(Wallet w, Transaction tx, BigInteger prevBalance, BigInteger newBalance) %7B%0A                System.out.println(%22%5CnReceived tx %22 + tx.getHashAsString());%0A                System.out.println(tx.toString());%0A            %7D%0A        %7D);%0A%0A        // Now download and process the block chain.%0A        CountDownLatch progress = peer.startBlockChainDownload();%0A        long max = progress.getCount();  // Racy but no big deal.%0A        if (max %3E 0) %7B%0A            System.out.println(%22Downloading block chain. %22 + (max %3E 1000 ? %22This may take a while.%22 : %22%22));%0A            long current = max;%0A            while (current %3E 0) %7B%0A                double pct = 100.0 - (100.0 * (current / (double) max));%0A                System.out.println(String.format(%22Chain download %25d%25%25 done%22, (int) pct));%0A                progress.await(1, TimeUnit.SECONDS);%0A                current = progress.getCount();%0A            %7D%0A        %7D%0A        peer.disconnect();%0A        wallet.saveToFile(file);%0A        System.out.println(%22%5CnDone!%5Cn%22);%0A        System.out.println(wallet.toString());%0A    %7D%0A%7D%0A

Add a program that just loads a wallet, runs through the block chain, and then saves/prints out the resulting wallet at the end.