/*
 * Copyright 2012 Tamas Blummer tamas@bitsofproof.com
 *
 * 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.bitsofproof.supernode.main;

import java.io.IOException;

import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.GnuParser;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.bitsofproof.supernode.core.BitcoinNetwork;
import com.bitsofproof.supernode.model.TransactionValidationException;

public class Application
{
	private static final Logger log = LoggerFactory.getLogger (Application.class);

	private BitcoinNetwork network;

	public void start (String[] args) throws IOException, TransactionValidationException
	{
		final CommandLineParser parser = new GnuParser ();
		final Options gnuOptions = new Options ();
		gnuOptions.addOption ("h", "help", false, "I can't help you yet");

		try
		{
			parser.parse (gnuOptions, args);
		}
		catch ( ParseException e1 )
		{
			log.error ("Invalid options ", e1);
			return;
		}

		if ( network.getStore ().isEmpty () )
		{
			network.getStore ().resetStore (network.getChain ());
		}
		network.getStore ().cache ();
		network.start ();
	}

	public void setNetwork (BitcoinNetwork network)
	{
		this.network = network;
	}
}

@@ -677,24 +677,67 @@
 Exception;%0A%0A
+import org.apache.commons.cli.CommandLine;%0A
 import org.a
@@ -1011,16 +1011,75 @@
 etwork;%0A
+import com.bitsofproof.supernode.core.ValidationException;%0A
 import c
@@ -1544,146 +1544,77 @@
 %22);%0A
-%0A
 %09%09
-try%0A%09%09%7B%0A%09%09%09parser.parse (gnuOptions, args);%0A%09%09%7D%0A%09%09catch ( ParseException e1 )%0A%09%09%7B%0A%09%09%09log.error (%22Invalid options %22, e1);%0A%09%09%09return;%0A%09%09%7D
+gnuOptions.addOption (%22p%22, %22prune%22, true, %22Prune upto given hash%22);
 %0A%0A%09%09
@@ -1748,16 +1748,426 @@
 che ();%0A
+%0A%09%09CommandLine cl = null;%0A%09%09try%0A%09%09%7B%0A%09%09%09cl = parser.parse (gnuOptions, args);%0A%09%09%09if ( cl.hasOption ('p') )%0A%09%09%09%7B%0A%09%09%09%09String upto = cl.getOptionValue ('p');%0A%09%09%09%09try%0A%09%09%09%09%7B%0A%09%09%09%09%09network.getStore ().prune (upto);%0A%09%09%09%09%7D%0A%09%09%09%09catch ( ValidationException e )%0A%09%09%09%09%7B%0A%09%09%09%09%09log.error (%22Pruning failed%22, e);%0A%09%09%09%09%09return;%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D%0A%09%09catch ( ParseException e1 )%0A%09%09%7B%0A%09%09%09log.error (%22Invalid options %22, e1);%0A%09%09%09return;%0A%09%09%7D%0A%0A
 %09%09networ

add prune