internal void HandleStartCommand(bool startMining)
        {
            _started = DateTime.Now;
            _cts     = new CancellationTokenSource();
            var keyGen = new KeyGenerator();

            Task.Run(async() =>
            {
                Random rnd    = new Random();
                int skuAmount = 1000;//rnd.Next(100000, 250000);
                Console.WriteLine("Preparing " + skuAmount + " SKU's..");
                List <AbstractTransaction> skuTransactions      = new List <AbstractTransaction>();
                List <AbstractTransaction> transferTransactions = new List <AbstractTransaction>();
                Dictionary <string, string> keys = new Dictionary <string, string>();

                for (int i = 0; i < skuAmount; i++)
                {
                    if (_cts.IsCancellationRequested)
                    {
                        return;
                    }

                    Random rndEan      = new Random();
                    string name        = Convert.ToBase64String(Guid.NewGuid().ToByteArray()).Substring(0, 8);
                    string eanCode     = rnd.Next(100000000, 999999999).ToString(); // Should be 13 numbers long, but ok.
                    string description = " Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim.";
                    SkuData skuData    = new SkuData(name, eanCode, description);
                    keyGen.GenerateKeys(out var publicKey, out var privateKey);
                    var tx = _txCreator.CreateSkuCreationTransaction(publicKey, privateKey, (uint)rndEan.Next(10, 20000), skuData);
                    try
                    {
                        keys.Add(publicKey, privateKey);
                    }
                    catch (Exception) { }
                    skuTransactions.Add(tx);
                }

                Console.WriteLine("Prepared " + skuTransactions.Count + " new SKU's. Submitting them gradually now..");

                if (startMining)
                {
                    _miner.StartMining();
                }

                foreach (var transaction in skuTransactions)
                {
                    if (_cts.IsCancellationRequested)
                    {
                        return;
                    }
                    _miner.AddTransactionToPool(transaction, true);
                    await Task.Delay(20);
                }
            }
                     );
        }
Ejemplo n.º 2
0
        internal void HandleCommand(string netId)
        {
            ulong creationFee = CreateSkuFee; // From BlockchainConstants.cs

            Console.WriteLine("Current SKU creation fee is " + creationFee + " TK.");
            WriteLineWithInputCursor("Enter the sender's public key:");
            var fromPub = Console.ReadLine();

            var fromPriv = Program.GetPrivKey(fromPub);

            while (String.IsNullOrWhiteSpace(fromPriv))
            {
                Console.WriteLine("Private key not found.");
                WriteLineWithInputCursor("Enter the sender's public key:");
                fromPub = Console.ReadLine();
            }

            var balance = _transactionRepo.GetTokenBalanceForPubKey(fromPub, netId);

            Console.WriteLine("The sender's balance: " + balance);

            // Todo support custom fees in transactionCreator

            /*
             * var askFeeFirstTime = true;
             * var forceLowerFee = false;
             * while (creationFee < CreateSkuFee && !forceLowerFee || askFeeFirstTime)
             * {
             *  askFeeFirstTime = false;
             *  WriteLineWithInputCursor("Use a different fee ["+ CreateSkuFee + "]:");
             *  var feeInput = Console.ReadLine().ToLower();
             *  while (!ulong.TryParse(feeInput, out creationFee))
             *  {
             *      creationFee = CreateSkuFee;
             *      if (feeInput != "")
             *      {
             *          WriteLineWithInputCursor("Invalid value. Use a positive numeric value without decimals.");
             *          feeInput = Console.ReadLine().ToLower();
             *      }
             *      else
             *      {
             *          break;
             *      }
             *  }
             *
             *  if (creationFee < CreateSkuFee && !forceLowerFee)
             *  {
             *      Console.WriteLine("This low fee might result into a rejection. ");
             *      WriteLineWithInputCursor("Type 'force' to use the given fee. Press ENTER to specify another amount.");
             *      feeInput = Console.ReadLine().ToLower();
             *      if (feeInput == "force")
             *      {
             *          forceLowerFee = true;
             *      }
             *  }
             * }
             */

            var sku = HandleCreateSkuCommand();

            bool firstTimeSupplyAmountInput = true;
            uint supplyAmount = 0;

            while (supplyAmount < 0 || firstTimeSupplyAmountInput)
            {
                firstTimeSupplyAmountInput = false;
                WriteLineWithInputCursor("Specify the initial supply:");

                var amountInput = Console.ReadLine().ToLower();
                while (!UInt32.TryParse(amountInput, out supplyAmount))
                {
                    WriteLineWithInputCursor("Invalid value. Use a positive numeric value without decimals.");
                    amountInput = Console.ReadLine().ToLower();
                }
            }

            AbstractTransaction transactionToSend = _transactionCreator.CreateSkuCreationTransaction(fromPub, fromPriv, supplyAmount, sku);

            EventPublisher.GetInstance().PublishUnvalidatedTransactionReceived(this, new TransactionReceivedEventArgs(transactionToSend));
            Console.Write("> ");
        }