/// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public async Task <Result> Scrape(IWebDriver webDriver)
        {
            webDriver.SwitchTo().Frame(webDriver.FindElement(By.Id(Constants.HeaderFrameId)));
            webDriver.FindElement(By.CssSelector(Constants.TradeTabSelector)).Click();
            Logger.Info($"trade tab click success");
            webDriver.FindElement(By.CssSelector(TradeHistorySelector)).Click();
            Logger.Info($"trade history click success");

            webDriver.SwitchTo().ParentFrame();
            webDriver.SwitchTo().Frame(webDriver.FindElement(By.Id(Constants.MainFrameId)));
            Logger.Info($"switching to main frame success");

            var webDriverWait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));

            Thread.Sleep(TimeSpan.FromSeconds(3));
            webDriverWait.Until(d => d.FindElement(By.CssSelector(MonthlyRadioSelector)));
            //if (!isMonthlyHistoryValid) throw new Exception("monthly transaction history cannot be detected");

            webDriver.FindElement(By.CssSelector(MonthlyRadioSelector)).Click();
            Logger.Info($"selecting monthly trade history");
            Thread.Sleep(TimeSpan.FromSeconds(3));
            webDriver.FindElement(By.Name(TradeHistorySubmitName)).Click();
            Logger.Info($"monthly trade history click success");

            Thread.Sleep(TimeSpan.FromSeconds(10));
            webDriverWait.Until(d => d.FindElement(By.CssSelector(TradeHistoryTableSelector)));
            // need to test for no trades
            var tables = webDriver.FindElements(By.CssSelector(TradeHistoryTableSelector));

            foreach (var table in tables)
            {
                var tbody = table.FindElement(By.TagName(TableBodyTag));
                var rows  = tbody.FindElements(By.TagName(TableRowTag));

                var transactions      = (List <Transaction>)_transactionBuilder.Build(rows);
                var transactionResult = await _transactionProcessor.Process(transactions);
            }

            return(new TaskResult {
                IsSuccessful = true
            });
        }
Пример #2
0
        static void RunCommand(string command, KeyPair keys)
        {
            var args       = command.Split(' ');
            var ownAddress = _addressEncoder.EncodeAddress(keys.PublicKey, 0);

            switch (args[0])
            {
            case "help":
                PrintHelp();
                break;

            case "mine-genesis":
                Console.WriteLine("Mining...");
                _miner.Start(keys, true);
                break;

            case "mine":
                Console.WriteLine("Mining...");
                _miner.Start(keys, false);
                break;

            case "stop-mining":
                Console.WriteLine("Stopping...");
                _miner.Stop();
                break;

            case "peers":
                var peersIn  = _network.GetPeersIn();
                var peersOut = _network.GetPeersOut();
                Console.WriteLine("Incoming peers");
                PrintPeerList(peersIn);
                Console.WriteLine("Outgoing peers");
                PrintPeerList(peersOut);
                break;

            case "balance":
                if (args.Length == 1)
                {
                    Console.WriteLine($"Balance = {_txnRepo.GetAccountBalance(ownAddress)}");
                }
                else
                {
                    Console.WriteLine($"Balance = {_txnRepo.GetAccountBalance(args[1])}");
                }
                break;

            case "best-block":
                var header = _blockRepo.GetBestBlockHeader().Result;
                Console.WriteLine($"Height: {header.Height}, Id: {BitConverter.ToString(header.BlockId)}");
                break;

            case "gen-key":
                var genkeys = _sigService.GetKeyPairFromPhrase(args[1]);
                var address = _addressEncoder.EncodeAddress(genkeys.PublicKey, 0);
                Console.WriteLine($"{address}");
                break;

            case "avg-time":
                var avgTime = _blockRepo.GetAverageBlockTimeInSecs(DateTime.UtcNow.AddHours(-1), DateTime.UtcNow).Result;
                Console.WriteLine($"Avg time: {avgTime}s");
                break;

            case "send":
                if (args.Length != 3)
                {
                    Console.WriteLine("invalid command");
                    return;
                }

                var instruction = new TransferInstruction()
                {
                    PublicKey   = keys.PublicKey,
                    Amount      = Convert.ToInt32(args[2]),
                    Destination = _addressEncoder.ExtractPublicKeyHash(args[1])
                };

                Console.WriteLine($"Signing instruction");
                _sigService.SignInstruction(instruction, keys.PrivateKey);
                var txn = _txnBuilder.Build(new List <Instruction>()
                {
                    instruction
                }).Result;

                Console.WriteLine($"Sending transaction {BitConverter.ToString(txn.TransactionId)}");
                _host.SendTransaction(txn);
                break;

            default:
                Console.WriteLine("invalid command");
                break;
            }
        }
Пример #3
0
        public async Task <Transaction> Build(KeyPair builderKeys, ICollection <Transaction> transactions)
        {
            var instructions = BuildInstructions(builderKeys, transactions);

            return(await TransactionBuilder.Build(instructions));
        }