Esempio n. 1
0
        private string AskUser(KeysForPhrases question = KeysForPhrases.ExitKey, bool isUserSupposedToEnterNumber = false)
        {
            string userInput = "empty";

            for (InputCheckResult i = InputCheckResult.Invalid; i != InputCheckResult.Valid;)
            {
                if (question != KeysForPhrases.ExitKey)// ExitKey used as flag for execution without question
                {
                    inputOutputModule.ClearMenu();
                    inputOutputModule.WriteOutput(phraseProvider.GetPhrase(gameSettings.LangPackName, question));
                }
                userInput = inputOutputModule.ReadInput();
                i         = ValidateUserInput(userInput, isUserSupposedToEnterNumber);
            }
            return(userInput);
        }
        public UIBadInputChecker(IWebDriver browser, UIFoundTags foundKeyWord)
        {
            UIBadInputCheckEvidence.Feature       = Feature.UIBadInputCheck;
            UIBadInputCheckEvidence.HelperMessage = messages.UIBadInputCheck;

            this.browser = browser;

            UIKeywords.GARBAGE_INPUT.ToList().ForEach(a => InputCheckResult.Add(a, false));

            var uiInputhandler = new InputingToUI(browser, foundKeyWord);

            resultsOutput.AppendLine(string.Format($"\n{"Input name",TitleColumnFormatter} {"FIXED",ValueColumnFormatter}"));
            resultsOutput.AppendLine(messages.ParagraphDivider);

            foreach (var key in UIKeywords.GARBAGE_INPUT)
            {
                var errs = uiInputhandler.InputData(key);
                if (errs.Any())
                {
                    SetCheckUndefined(errs);
                    return;
                }

                OutputCheck(key);
            }
            UIBadInputCheckEvidence.FeatureRating = GetOutputCheckRating();

            var featureImplemented = !ratingsList.Contains(false) && ratingsList.Any();

            if (featureImplemented)
            {
                UIBadInputCheckEvidence.SetPassed(new SimpleEvidenceBuilder(resultsOutput.ToString()));
            }
            else
            {
                UIBadInputCheckEvidence.SetFailed(new SimpleEvidenceBuilder(resultsOutput.ToString()));
            }
        }
Esempio n. 3
0
        public ViewResult TransactionCheck(TransactionCheckModel model)
        {
            model = model ?? new TransactionCheckModel();
            QBitNinjaClient client = new QBitNinjaClient(Network.TestNet);

            if (model.Transaction != null)
            {
                Transaction tx = null;
                try
                {
                    tx = new Transaction(model.Transaction);
                }
                catch (FormatException ex)
                {
                    ModelState.AddModelError("Transaction", "Can't parse transaction (" + ex.Message + ")");
                    return(View(model));
                }
                var totalSize = tx.ToBytes().Length;
                var coreSize  = tx.WithOptions(TransactionOptions.None).ToBytes().Length;
                model.WitnessSize     = totalSize - coreSize;
                model.CoreSize        = coreSize;
                model.TransactionCost = coreSize * 4 + model.WitnessSize;
                model.HasWitness      = tx.HasWitness;
                if (model.HasWitness)
                {
                    model.EstimatedCostNoWit = (coreSize + model.WitnessSize) * 4;
                    model.Saving             = (int)(((decimal)(model.EstimatedCostNoWit - model.TransactionCost) / model.EstimatedCostNoWit) * 100);
                }
                else
                {
                    model.ScriptSigSize    = tx.Inputs.Select(i => i.ScriptSig.Length).Sum();
                    model.EstimatedCostWit = (coreSize - model.ScriptSigSize) * 4 + model.ScriptSigSize;
                    model.Saving           = (int)(((decimal)(model.TransactionCost - model.EstimatedCostWit) / model.TransactionCost) * 100);
                }
                model.Result         = new CheckResult();
                model.Result.Success = true;
                model.Result.Id      = tx.GetHash();
                foreach (var input in tx.Inputs.AsIndexedInputs())
                {
                    if (tx.IsCoinBase)
                    {
                        break;
                    }
                    InputCheckResult inputCheck = new InputCheckResult();
                    inputCheck.PrevOut   = input.PrevOut;
                    inputCheck.Witness   = input.WitScript;
                    inputCheck.ScriptSig = input.ScriptSig;

                    var previous = client.GetTransaction(input.PrevOut.Hash).Result;
                    model.Result.InputResults.Add(inputCheck);
                    if (previous == null || previous.Transaction.Outputs.Count <= input.PrevOut.N)
                    {
                        model.Result.Success   = false;
                        inputCheck.ScriptError = "Previous output not found";
                        ModelState.AddModelError("Transaction", "Previous output not found (" + input.PrevOut + ")");
                        continue;
                    }
                    var output = previous.Transaction.Outputs[input.PrevOut.N];
                    inputCheck.ScriptPubKey = output.ScriptPubKey;
                    inputCheck.Amount       = output.Value;
                    ScriptEvaluationContext evaluator = new ScriptEvaluationContext();
                    evaluator.VerifyScript(input.ScriptSig, output.ScriptPubKey, new TransactionChecker(tx, (int)input.Index, output.Value));
                    if (evaluator.Error != ScriptError.OK)
                    {
                        inputCheck.ScriptError = Enum.GetName(typeof(ScriptError), evaluator.Error);
                        model.Result.Success  &= false;
                    }

                    var scriptId = PayToScriptHashTemplate.Instance.ExtractScriptPubKeyParameters(inputCheck.ScriptPubKey);
                    if (scriptId != null)
                    {
                        var s = PayToScriptHashTemplate.Instance.ExtractScriptSigParameters(input.ScriptSig, scriptId);
                        inputCheck.P2SHRedeemScript = s == null ? null : s.RedeemScript;
                    }
                    inputCheck.SignatureHash = evaluator.SignedHashes.FirstOrDefault();
                }
            }
            return(View(model));
        }