Beispiel #1
0
        public InputValidationResult ValidateInput(int index)
        {
            if (index < 0 || index >= SpentOutputs.Length)
            {
                throw new ArgumentOutOfRangeException(nameof(index));
            }
            ScriptEvaluationContext ctx = new ScriptEvaluationContext()
            {
                ScriptVerify = ScriptVerify
            };

            if (Transaction is IHasForkId)
            {
                ctx.ScriptVerify |= NBitcoin.ScriptVerify.ForkId;
            }

            var scriptSig = Transaction.Inputs[index].ScriptSig;
            var txout     = this.SpentOutputs[index];

            var ok = ctx.VerifyScript(scriptSig, txout.ScriptPubKey, new TransactionChecker(Transaction, index, txout, PrecomputedTransactionData));

            if (!ok)
            {
                return(new InputValidationResult(index, ctx.Error, ctx.ExecutionData));
            }
            return(new InputValidationResult(index, ctx.ExecutionData));
        }
Beispiel #2
0
        public static bool VerifyScript(Script scriptSig, Script scriptPubKey, Transaction tx, int i, ScriptVerify scriptVerify = ScriptVerify.StrictEnc | ScriptVerify.P2SH, SigHash sigHash = SigHash.Undefined)
        {
            ScriptEvaluationContext eval = new ScriptEvaluationContext();

            eval.SigHash      = sigHash;
            eval.ScriptVerify = scriptVerify;
            return(eval.VerifyScript(scriptSig, scriptPubKey, tx, i));
        }
		public static bool VerifyScript(Script scriptSig, Script scriptPubKey, Transaction tx, int i, Money value, ScriptVerify scriptVerify, SigHash sigHash, out ScriptError error)
		{
			var eval = new ScriptEvaluationContext
			{
				SigHash = sigHash,
				ScriptVerify = scriptVerify
			};
			var result = eval.VerifyScript(scriptSig, scriptPubKey, tx, i, value);
			error = eval.Error;
			return result;
		}
Beispiel #4
0
        public static bool VerifyScript(Script scriptSig, Transaction tx, int i, TxOut spentOutput, ScriptVerify scriptVerify, SigHash sigHash, out ScriptError error)
        {
            if (spentOutput == null)
            {
                throw new ArgumentNullException(nameof(spentOutput));
            }
            var eval = new ScriptEvaluationContext
            {
                SigHash      = sigHash,
                ScriptVerify = scriptVerify
            };
            var result = eval.VerifyScript(scriptSig, tx, i, spentOutput);

            error = eval.Error;
            return(result);
        }
Beispiel #5
0
 public bool SignedByMe(Transaction tx)
 {
     for (int i = 0; i < tx.Inputs.Count; i++)
     {
         var vin = tx.Inputs[i];
         var key = GetKey(vin.ScriptSig.GetSourcePubKey());
         if (key == null)
         {
             return(false);
         }
         var pubkeyScript = new PayToPubkeyHashTemplate().GenerateScriptPubKey(key.PubKey);
         var eval         = new ScriptEvaluationContext();
         eval.SigHash = SigHash.All;
         if (!eval.VerifyScript(vin.ScriptSig, pubkeyScript, tx, i))
         {
             return(false);
         }
     }
     return(true);
 }
Beispiel #6
0
        private static bool VerifySignature(Transaction txFrom, Transaction txTo, int txToInN, ScriptVerify flagScriptVerify)
        {
            var input = txTo.Inputs[txToInN];

            if (input.PrevOut.N >= txFrom.Outputs.Count)
            {
                return(false);
            }

            if (input.PrevOut.Hash != txFrom.GetHash())
            {
                return(false);
            }

            var output = txFrom.Outputs[input.PrevOut.N];

            var txData  = new PrecomputedTransactionData(txFrom);
            var checker = new TransactionChecker(txTo, txToInN, output.Value, txData);
            var ctx     = new ScriptEvaluationContext {
                ScriptVerify = flagScriptVerify
            };

            return(ctx.VerifyScript(input.ScriptSig, output.ScriptPubKey, checker));
        }