Beispiel #1
0
        public static void Main()
        {
            Console.WriteLine("Bitcoin Hannover Meetup Price Guesser ETH Smart Contract Replacement");
            decimal btcUsdPrice = 0;

            do
            {
                // Check every 15 minutes
                if (btcUsdPrice > 0)
                {
                    Thread.Sleep(15 * 60 * 1000);
                }
                btcUsdPrice = GrabBtcUsdPrice();
                Console.WriteLine("Current BTC price: $" + btcUsdPrice);
            } while (btcUsdPrice >= 12500 && btcUsdPrice < 25000);
            Guess  bestGuess = null;
            double bestGuesserDaysDistance = 10000.0;

            foreach (var guess in guesses)
            {
                double daysDistance = Math.Abs((guess.Date - DateTime.UtcNow.Date).TotalDays);
                if (daysDistance > bestGuesserDaysDistance)
                {
                    continue;
                }
                bestGuess = guess;
                bestGuesserDaysDistance = daysDistance;
            }
            Console.WriteLine("Ending at " + DateTime.UtcNow + ", price=$" + btcUsdPrice +
                              " reached ending condition, will pay out contract now to " + bestGuess.Name + ": " +
                              bestGuess.EthAddress);
            var service = new EthereumService("http://localhost:8545/");

            Console.WriteLine("Final outgoing tx: " + service.SendSmartContractWinner(bestGuess.EthAddress));
            Console.ReadLine();
        }